Skip to content

fix(java): make nested enums serializable with serializableModel - #24814

Open
KannaKim wants to merge 4 commits into
OpenAPITools:masterfrom
KannaKim:fix-23082
Open

fix(java): make nested enums serializable with serializableModel#24814
KannaKim wants to merge 4 commits into
OpenAPITools:masterfrom
KannaKim:fix-23082

Conversation

@KannaKim

@KannaKim KannaKim commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Fixes #23082.

Description

When serializableModel is enabled, Java models implement Serializable, but enums declared inside model properties do not.

This change recursively visits nested CodegenProperty instances and adds Serializable to the x-implements vendor extension of enum properties. It covers properties nested through arrays, maps, contains, required-property maps, and composed schemas.

The traversal uses object identity to avoid processing shared properties more than once and to terminate safely for cyclic property graphs. Existing interfaces are preserved, and duplicate Serializable entries are avoided.

Testing

Added:

  • A regression spec for a direct inner enum and an enum nested inside multiple array levels.
  • A focused traversal test covering:
    • vars
    • items
    • additionalProperties
    • contains
    • requiredVarsMap
    • allOf
    • oneOf
    • anyOf
    • not
    • self-referential property graphs

The focused tests pass:

./mvnw -pl modules/openapi-generator -am \
  -Dtest=JavaClientCodegenTest#testSerializableModelAddsSerializableToInnerEnums_issue23082+testSerializableModelTraversesEveryNestedPropertyLocation_issue23082 \
  -Dsurefire.failIfNoSpecifiedTests=false \
  test \
  -Dspotless.check.skip=true \
  -Dcheckstyle.skip=true

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.

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08) @KannaKim (2026/07)


Summary by cubic

Fixes #23082 so inline enums nested inside model properties are made Serializable when serializableModel is enabled, matching the model itself.

  • Adds a reusable recursive traversal in DefaultCodegen that visits every nested property location (vars, items, additionalProperties, contains, requiredVarsMap, and composed schemas) at both the model and property level.
  • Uses object identity to avoid duplicate work and terminate safely on cyclic property graphs.
  • Preserves existing interfaces and avoids duplicate Serializable entries.
  • Adds a regression spec and a focused traversal test, and regenerates the okhttp-gson-streaming sample so its inner enum implements Serializable.

Written for commit 4534776. Summary will update on new commits.

Review in cubic

Recursively traverse model properties and add Serializable to inline enums.
Add regression coverage for nested schema locations and recursive graphs.

Fixes OpenAPITools#23082
@KannaKim
KannaKim marked this pull request as ready for review August 31, 2026 03:28

@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 4 files

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

Re-trigger cubic

…en/languages/AbstractJavaCodegen.java

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

@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 1 file (changes from recent commits).

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

Re-trigger cubic

…en/languages/AbstractJavaCodegen.java

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
chore: add docstring to addInterfaceToVendorExtensions method in AbstractJavaCodegen.java
@wing328

wing328 commented Sep 2, 2026

Copy link
Copy Markdown
Member

cc @OpenAPITools/generator-core-team as the changes over default codegen

@KannaKim

KannaKim commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

cc @OpenAPITools/generator-core-team as the changes over default codegen

right on! Hi core team, I made some addition to DefaultCodegen, I'd appreciate your review.
@wing328
@jimschubert
@cbornet
@jmini
@etherealjoy

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.

[BUG][Java][serializableModel] Generated inner-enum lack implements Serializable

3 participants