Repository navigation
fix(java): do not map 'format: enum' schemas to 'Enum' - #25008
Open
Natarajan717 wants to merge 2 commits into
Open
Natarajan717 wants to merge 2 commits into
Natarajan717 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Sekator778
approved these changes
Sep 27, 2026
Sekator778
left a comment
Contributor
There was a problem hiding this comment.
Built it and ran the new test, it fails on master. Also generated native, okhttp-gson and Spring code from a format: enum schema: on master it references a missing Enum class and doesn't compile, with this it's a proper enum. The oneOf enum samples from #24812 come out unchanged. LGTM, thanks!
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…en (fixes #24950)
fixes #24950
PR checklist
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.
In PR #24812,
typeMapping.put("enum", "Enum")was added toAbstractJavaCodegento resolve common discriminator types foroneOfinterface methods across enum subtypes. However, becauseDefaultCodegen.getSchemaTypecheckstypeMappingfor format matches, schemas specifyingformat: enumwere mapped to type"Enum", causing invalid Java code generation (private Enum value;and invalidEnum.valueOf(...)calls).This PR:
protected String getCommonEnumType()inDefaultCodegen(overridden inAbstractJavaCodegento return"Enum").typeMapping.get("enum")lookups in discriminator resolution withgetCommonEnumType().typeMapping.put("enum", "Enum")fromAbstractJavaCodegen, preventing the format collision.JavaClientCodegenTestverifying that schemas withformat: enumgenerate validStringbacking fields and constructors without invalidEnum.valueOf(...)or imports.cc: @wing328
Summary by cubic
Fixes Java code generation for schemas with
format: enumso they no longer produce invalidEnumtypes.getCommonEnumType()hook inDefaultCodegen; the base implementation keeps thetypeMapping["enum"]lookup and falls back to the mapped object type when absent.AbstractJavaCodegento return"Enum", and removestypeMapping.put("enum", "Enum")soformat: enumstrings are no longer resolved to Java'sEnum.format: enumschemas generate String-backed enums withoutEnum.valueOf(...), invalidEnumsfields, orEnumimports.Written for commit b362993. Summary will update on new commits.