Skip to content

Fix missing @Serializable on enums for kotlin/jvm-retrofit2 - #21907

Merged
wing328 merged 3 commits into
OpenAPITools:masterfrom
yzaoui:patch-1
Sep 6, 2025
Merged

wing328 merged 3 commits into
OpenAPITools:masterfrom
yzaoui:patch-1

Conversation

@yzaoui

@yzaoui yzaoui commented Sep 5, 2025 •

Copy link
Copy Markdown
Contributor

This adds the missing @Serializable annotation when using the kotlin generator with serializationLibrary=kotlinx_serialization and library=jvm-retrofit2.
Currently, the generated enum classes add @SerialName to each child of the enum, but these annotations do not work because @Serializable is missing from the enum class. This can be seen in the docs here. As a result, currently a setup like this to control ascending/descending sort order

enum class SortOrder(val value: String) {
    @SerialName(value = "-name") _NAME("-name"),
    @SerialName(value = "name") NAME("name"),
}

is serialized as "_NAME" and "NAME", rather than the expected "-name" and "name". Adding the missing annotation fixes this.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@yzaoui yzaoui changed the title Fix missing @Serializable on enums for Fix missing @Serializable on enums for kotlin/jvm-retrofit2 Sep 5, 2025
@yzaoui

yzaoui commented Sep 5, 2025

Copy link
Copy Markdown
Contributor Author

Could @4brunu take a look?

@wing328

wing328 commented Sep 6, 2025

Copy link
Copy Markdown
Member

https://github.com/OpenAPITools/openapi-generator/actions/runs/17506211302/job/49735197450?pr=21907

please follow step 3 to update the samples

@wing328

wing328 commented Sep 6, 2025

Copy link
Copy Markdown
Member

thanks for the fix, which has been merged

have a nice weekend

@wing328
wing328 merged commit 2a556ff into OpenAPITools:master Sep 6, 2025
63 checks passed
@yzaoui

yzaoui commented Sep 6, 2025

Copy link
Copy Markdown
Contributor Author

Thank you William!

@yzaoui
yzaoui deleted the patch-1 branch September 6, 2025 02:19
goopher pushed a commit to goopher/openapi-generator that referenced this pull request Sep 9, 2025
…ITools#21907)

* Add @serializable annotation to enum for kotlinx-serialization

* Adjust template, generate samples

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants