Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
etremblay opened this issue Oct 13, 2021 · 0 comments

Comments

@etremblay
Copy link
Contributor

etremblay commented Oct 13, 2021

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 #10244

The regression was introduced by #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.

etremblay pushed a commit to kronostechnologies/openapi-generator that referenced this issue Oct 13, 2021
wing328 pushed a commit that referenced this issue Oct 16, 2021
* Issue #10591 kotlin enum defaultValue

* Updated sample

* Register sample

Co-authored-by: Eric Durand-Tremblay <etremblay@kronostechnologies.com>
@wing328 wing328 closed this as completed Oct 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants