Skip to content

[BUG][Kotlin] Enum with Int values generated to hold StringΒ #15204

Closed

Description

@ivanvasheka-intellias
openapi-generator version

6.3.0

Source json
"typeIDs": {
          "description": "Ids",
          "type": "array",
          "items": {
            "format": "int32",
            "type": "integer",
            "enum": [
              0,
              7,
              8,
              9,
              10,
              11,
              12,
              13,
              14,
              15,
              16,
              19,
              -98
            ]
          }
        }
Generation code
enum class TypeIDs(val value: kotlin.String) {
        @Json(name = "0") _0(0),
        @Json(name = "7") _7(7),
        @Json(name = "8") _8(8),
        @Json(name = "9") _9(9),
        @Json(name = "10") _10(10),
        @Json(name = "11") _11(11),
        @Json(name = "12") _12(12),
        @Json(name = "13") _13(13),
        @Json(name = "14") _14(14),
        @Json(name = "15") _15(15),
        @Json(name = "16") _16(16),
        @Json(name = "19") _19(19),
        @Json(name = "-98") MINUS98(-98);
    }

Generated code has type String in the declaration (enum class TypeIDs(val value: kotlin.String)), however every entry is populated with an Int value (ex. _0(0), and not _0("0")), which results into a compilation error.

Activity

  1. noulis commented on Jul 6, 2023

    @noulis

    Any workaround for this? Or any expectation if this will be fixed?

  2. ctamisier commented on Jan 18, 2024

    @ctamisier
    Contributor

    This also can be reproduced with this openapi file: https://api-docs.jrni.com/v5/swagger/admin.json

    (also with openapi-generator 7.2.0 version)

  3. Aschraf commented on May 16, 2024

    @Aschraf

    Still happening with 7.5.0

  4. takkiraz commented on Nov 3, 2024

    @takkiraz
    Contributor

    Still happening with 7.9.0

  5. childnode commented on Mar 13, 2025

    @childnode

    yes, still alive on 7.12.0
    Example:

          target_access_levels:
            type: array
            description: Target user roles
            items:
              type: integer
              format: int32
              enum:
              - 10
              - 15
              - 20
              - 30
              - 40
              - 50
    

    in https://gitlab.com/gitlab-org/gitlab/-/raw/master/doc/api/openapi/openapi_v2.yaml

    by using

    openApiGenerate {
        generatorName.set("kotlin")
        library.set("jvm-ktor")
    
        skipValidateSpec.set(true)
    
        configOptions.putAll(
            mapOf(
                "dateLibrary" to "kotlinx-datetime",
                "serializationLibrary" to "kotlinx_serialization",
                "useCoroutines" to "true",
            )
        )
    }
    
  6. exviva commented on Nov 10, 2025

    @exviva
    Contributor

    I opened a PR with the fix: #22324

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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