Skip to content

Feature/add kotlin enum unknown default case support#23936

Open
dijkstrar wants to merge 11 commits into
OpenAPITools:masterfrom
dijkstrar:feature/add-kotlin-enumUnknownDefaultCase-support
Open

Feature/add kotlin enum unknown default case support#23936
dijkstrar wants to merge 11 commits into
OpenAPITools:masterfrom
dijkstrar:feature/add-kotlin-enumUnknownDefaultCase-support

Conversation

@dijkstrar
Copy link
Copy Markdown

@dijkstrar dijkstrar commented Jun 3, 2026

I made a change to also include the default enum value for kotlin-spring (as i use it privately, and want to have it included)

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Adds enumUnknownDefaultCase support to the kotlin-spring generator to safely handle unknown enum values at runtime. Enums now include UNKNOWN_DEFAULT_OPEN_API; deserialization falls back to it instead of throwing.

  • New Features
    • New CLI/config option enumUnknownDefaultCase (default: false) for kotlin-spring only.
    • Generated enums (top-level and inline) add UNKNOWN_DEFAULT_OPEN_API; forValue falls back to it for string and numeric enums.
    • Docs updated to match the Spring docs wording; tests added for on/off behavior with sample specs enum_unknown_default_case.yaml and dataclass_unknown_default_case.yaml.

Written for commit 5f444ca. Summary will update on new commits.

Review in cubic

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 5 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@dijkstrar
Copy link
Copy Markdown
Author

dijkstrar commented Jun 3, 2026

Hi all (@karismann @Zomzog @andrewemery @4brunu @stefankoppier @e5l @dennisameling )

i made a small PR for the kotlin-spring server to include a default case for enums, toggled by enumUnknownDefaultCase flag.

Could you be so kind to review my PR? :)

Thanks in advance :D

@Picazsoo
Copy link
Copy Markdown
Contributor

Picazsoo commented Jun 3, 2026

Nice! Bringing kotlin-spring codegen closer to feature parity with java-spring codegen!

Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/enumClass.mustache Outdated
@Picazsoo
Copy link
Copy Markdown
Contributor

Picazsoo commented Jun 4, 2026

dataClass.mustache also contains possible enum definition - I guess this should be supported there as well?

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread modules/openapi-generator/src/main/resources/kotlin-spring/dataClass.mustache Outdated
@dijkstrar
Copy link
Copy Markdown
Author

dataClass.mustache also contains possible enum definition - I guess this should be supported there as well?

awesome! Good catch :D I have implemented a solution for it! Feel free to review if you want :)

@Picazsoo
Copy link
Copy Markdown
Contributor

Picazsoo commented Jun 5, 2026

I would recommend also adding a compilation sample as it is generally more thorough than just depending on the unit tests. I would suggest against (unless it is really the only way to go) creating entirely new sample (as that increases the CI/CD pipelines runtime) - you should be able to find some existing kotlin-spring config that tests some unrelated functionality and can therefore basically test your functionality side-by-side without having to compile entirely separate spring boot application.

But maybe no - that is just a suggestion.

Overall I am suggesting this since many times in the past I had kotlin tests in this project passing with flying colors and then compilation caught some missing import or dependency, etc.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants