fix(java): make nested enums serializable with serializableModel
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:
varsitemsadditionalPropertiescontainsrequiredVarsMapallOfoneOfanyOfnot- 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:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
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
DefaultCodegenthat 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
Serializableentries. - Adds a regression spec and a focused traversal test, and regenerates the
okhttp-gson-streamingsample so its inner enum implementsSerializable.