Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5247
Closed
Open
Issue created Feb 08, 2020 by Administrator@rootContributor

[BUG][Kotlin] Incorrect enum parameter type

Created by: 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.

Assignee
Assign to
Time tracking