Skip to content

refactor(kotlin): remove unknown default enum case for inline operation enums in multiplatform library - #24521

Open
Mattias-Sehlstedt wants to merge 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:kotlin-multiplatform-inline-enum-in-operation-default-unknown
Open

refactor(kotlin): remove unknown default enum case for inline operation enums in multiplatform library#24521
Mattias-Sehlstedt wants to merge 1 commit into
OpenAPITools:masterfrom
Mattias-Sehlstedt:kotlin-multiplatform-inline-enum-in-operation-default-unknown

Conversation

@Mattias-Sehlstedt

@Mattias-Sehlstedt Mattias-Sehlstedt commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

This PR changes how enumUnknownDefaultCase is handled with the operations inline enum support that was introduced to the kotlin multiplatform library with #16327.

The background is that we do not want to have to conduct mustache magic with regards to hiding the unnecessary enumUnknownDefaultCase case (hidden since these enums are only used to send values).

It is also tied to being able to place the ; after the last enum value, this so that the .toString() can be overridden in the enum, which would solve this issue.

Thus we move the handling of the ignoring/removal of the enumUnknownDefaultCase from the mustache file to the client codegen.

Kotlin committee:
@karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10)

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

Remove the unknown_default_open_api enum case from inline operation enums in the Kotlin multiplatform client and move default-case handling from the template into codegen. This simplifies generated APIs and allows a trailing semicolon on enum declarations so enum methods (e.g., toString()) can be added.

  • Refactors

    • Add injectEnumUnknownDefaultCase and removeEnumUnknownDefaultCase in DefaultCodegen; remove default enum case for non-body operation params.
    • Apply removal during operation post-processing in KotlinClientCodegen for the multiplatform library.
    • Simplify kotlin-client/libraries/multiplatform/api.mustache by removing enumUnknownDefaultCase branching and always adding ; after the last enum value.
    • Keep the unknown default case for model enums and referenced operation enums to retain fallback behavior when receiving values.
  • Tests

    • Add multiplatform-inline-query-enum.yaml and a test ensuring inline header/query/path enums omit the default case while model/referenced enums keep it.
    • Regenerate Kotlin multiplatform samples to reflect the trailing ; in generated enums.

Written for commit 868633d. Summary will update on new commits.

Review in cubic

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 7 files

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

Re-trigger cubic

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.

1 participant