Skip to content

[BUG][KOTLIN] Number-based enums with defaults result in invalid Kotlin enums #23293

@acsbendi

Description

@acsbendi

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

Number-based enums with defaults result in invalid Kotlin enums. With no options, enums are generated like this:

 enum class OwnedByYouGetArchivedDeals(val value: java.math.BigDecimal) {
        @JsonProperty(value = ""0"") _0("0"),
        @JsonProperty(value = ""1"") _1("1")
    }

After adding number=kotlin.Int as a type mapping, the resulting enum is fine, but the instantiations of non-null default values are still broken:

enum class IsActive(val value: kotlin.Int) {
        @JsonProperty(value = "0") _0(0),
        @JsonProperty(value = "1") _1(1);
    }

val isActive: BaseWebhook.IsActive? = kotlin.Int("IsActive._1"),
openapi-generator version

I use the latest version of the Maven plugin (openapi-generator-maven-plugin, version 7.20.0).

OpenAPI declaration file content or url

Number-based boolean enums, with a default value:

                - in: query
                  name: skip_users
                  schema:
                      title: numberBooleanDefault0
                      type: number
                      default: 0
                      enum:
                          - 0
                          - 1
                  description: 'When enabled, the teams will not include IDs of member users'
Generation Details

mvn generate-sources

Steps to reproduce

Generate Kotlin sources based on the OpenAPI specification shown above.

Related issues/PRs

I couldn't find any.

Suggest a fix

The type constructor shouldn't be used for enums.

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