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
  • #10591
Closed
Open
Issue created Oct 13, 2021 by Administrator@rootContributor

[BUG] Kotlin generator produce a invalid kotlin file when shema have an enum with default value.

Created by: etremblay

Description

Kotlin generator produce a invalid kotlin file when shema have an enum with default value.

Unresolved reference: TypeEnum
openapi-generator version

5.2.1, master

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: 'Enum Bug'
  version: latest
paths:
  '/':
    get:
      operationId: demoBug
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MoveMovement'
components:
  schemas:
    MoveMovement:
      required:
        - type
      properties:
        type:
          type: string
          default: MOVE
          enum:
            - MOVE
Generation Details
docker run --rm  -v ${PWD}:/local --user "${USER_ID}:${GROUP_ID}" openapitools/openapi-generator-cli:latest generate -i /local/model.yaml -g kotlin -o /local/kotlin
Steps to reproduce

Generate a model with an enum property with default value

The model constructor will have invalid kotlin code

  data class MovementMoveMovement (

    @Json(name = "type")
    val type: MovementMoveMovement.Type = TypeEnum.MOVE

) : MovementMovement {

    /**
     * 
     *
     * Values: MOVE
     */
    enum class Type(val value: kotlin.String) {
        @Json(name = "MOVE") MOVE("MOVE");
    }
}

should be

   val type: MovementMoveMovement.Type = Type.MOVE
Related issues/PRs

Similar to https://github.com/OpenAPITools/openapi-generator/issues/10244

The regression was introduced by https://github.com/OpenAPITools/openapi-generator/pull/9853 in 5.2.1

Suggest a fix

https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java

    @Override
    public String toEnumName(CodegenProperty property) {
        return property.nameInCamelCase;
    }

I will try to submit a proper pull request with unit tests.

Assignee
Assign to
Time tracking