Skip to content

[BUG][Kotlin] Integer enums outputs as a string #21204

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

Open
5 of 6 tasks
CHervaudBetclic opened this issue May 2, 2025 · 0 comments
Open
5 of 6 tasks

[BUG][Kotlin] Integer enums outputs as a string #21204

CHervaudBetclic opened this issue May 2, 2025 · 0 comments

Comments

@CHervaudBetclic
Copy link

CHervaudBetclic commented May 2, 2025

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

When using the generator for kotlin with the kotlinx serialization method, integer enums will be correctly serialized from integer to kotlin integer, but will be incorrectly deserialized from kotlin integer to string
This:

@Serializable
enum class SomeCode(val value: kotlin.Int) {
    @SerialName(value = "0")
    _0(0)
}

Should be this:

@Serializable
enum class SomeCode(val value: kotlin.Int) {
    @SerialName(value = 0)
    _0(0),
}
openapi-generator version

Latest (7.12.0)

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Demo
  version: v1

components:
  schemas:
    Code:
      type: integer
      enum:
        - 0

paths:
  /do:
    get:
      summary: Do something
      responses:
        200:
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                properties:
                  code:
                    $ref: '#/components/schemas/Code'
Generation Details

Generate with Docker command:

docker run --rm -v $(pwd):/local openapitools/openapi-generator-cli generate -i /local/Test.yml -g kotlin -o /local/out/kotlin
Steps to reproduce

Generate with Docker command:

docker run --rm -v $(pwd):/local openapitools/openapi-generator-cli generate -i /local/Test.yml -g kotlin -o /local/out/kotlin
Related issues/PRs
Suggest a fix

The bug seems to be caused by the following line:

    @SerialName(value = {{#lambda.doublequote}}{{{value}}}{{/lambda.doublequote}})

Where double quotes are hard-coded
They should be conditionally added, whether it's a dataType string or integer.
I'm not sure if we can do conditional checks like that is the mustaches syntax, let me know if we can, it would be a pleasure to create a PR

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