Skip to content

[BUG][Kotlin] Incorrect enum parameter type #5247

@dalewking

Description

@dalewking
Description

Kotlin generation is producing a wrong parameter type for an enum that is declared in an array. It is getting the type from another array declared in the same object

openapi-generator version

4.2.3

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: Blah
  version: v2
paths:
  /api/v2/query:
    post:
      operationId: foo
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Query"
components:
  schemas:
    Query:
      type: object
      properties:
        groupBy:
          type: array
          items:
            type: string
            enum:
              - value1
              - value2
              - value3
              - value4
        views:
          type: array
          items:
            type: int
Command line used for generation

openapi-generator generate -i test.yml -g kotlin --skip-validate-spec -o output

Steps to reproduce
  • Store the yml contents into a file named test.yml.
  • Run openapi-generator generate -i test.yml -g kotlin --skip-validate-spec -o output
  • examine the contents of output/src/main/kotlin/org/openapitools/client/models/Query.kt

You will see this code:

    enum class GroupBy(val value: Int){
        @Json(name = "value1") value1("value1"),
        @Json(name = "value2") value2("value2"),
        @Json(name = "value3") value3("value3"),
        @Json(name = "value4") value4("value4");
    }

The Int parameter type here is not correct and will not compile. It should be kotlin.String. That type is coming from the views array type. If you change the type used for the views array it changes the GroupBy parameter type. If you remove the views property it does generate the correct code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions