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] enums declared in the model have incorrect names #18714

Open
4 of 6 tasks
ivanvasheka-intellias opened this issue May 20, 2024 · 0 comments
Open
4 of 6 tasks

Comments

@ivanvasheka-intellias
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Enums that are declared inside models are generated with incorrect names.

openapi-generator version

7.5.0 - issue appeared
7.6.0 - issue reproduced

OpenAPI declaration file content or url
{
  "openapi": "3.0.1",
  "info": {
    "title": "Test.Api",
    "version": "1.0.0"
  },
  "components": {
    "schemas": {
      "User.Model": {
        "required": [
          "userType",
          "name"
        ],
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "age": {
            "type": "integer"
          },
          "userType": {
            "enum": [
              "MALE",
              "FEMALE",
              "ANIMAL"
            ],
            "type": "string"
          }
        }
      }
    }
  }
}

results into:

data class UserModel (

    @Json(name = "name")
    val name: kotlin.String,

    @Json(name = "userType")
    val userType: UserModel.UserType,

    @Json(name = "age")
    val age: kotlin.Int? = null

) {
    enum class userType(val value: kotlin.String) {
        @Json(name = "MALE") MALE("MALE"),
        @Json(name = "FEMALE") FEMALE("FEMALE"),
        @Json(name = "ANIMAL") ANIMAL("ANIMAL");
    }
}

here enum name conflicts with the property name giving an error:
image

Generation Details
        task.additionalProperties = [
                useCoroutines: "true",
                library      : "jvm-retrofit2",
                sourceFolder : "src/main/java",
        ]
        task.globalProperties = [
                apiDocs        : "false",
                apiTests       : "false",
                modelDocs      : "false",
                modelTests     : "false",
                apis           : "",
                models         : "",
                supportingFiles: "CollectionFormats.kt"
        ]
        task.configOptions = [
                dateLibrary       : "java8-localdatetime",
                enumPropertyNaming: "UPPERCASE",
                moshiCodeGen      : "true"
        ]
        task.typeMappings = [
                "URI"                     : "kotlin.String",
                "ByteArray"               : "kotlin.String",
        ]
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

1 participant