OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.98k stars 6.6k forks source link

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

Open ivanvasheka-intellias opened 1 year ago

ivanvasheka-intellias commented 1 year ago
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.

noulis commented 1 year ago

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

ctamisier commented 10 months ago

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)

Aschraf commented 6 months ago

Still happening with 7.5.0

takkiraz commented 3 weeks ago

Still happening with 7.9.0