[BUG][JAVA][okhttp-gson] Skip validateJsonElement for $ref'd enum properties#23669
Open
winrid wants to merge 3 commits intoOpenAPITools:masterfrom
Open
[BUG][JAVA][okhttp-gson] Skip validateJsonElement for $ref'd enum properties#23669winrid wants to merge 3 commits intoOpenAPITools:masterfrom
winrid wants to merge 3 commits intoOpenAPITools:masterfrom
Conversation
…erties A property that is both isModel and isEnum (a $ref to a top-level enum schema) was emitting MyEnum.validateJsonElement(...) inside the parent class's validateJsonElement, which doesn't exist on enum classes and breaks compilation. This is the same surface as OpenAPITools#18547 narrowed to the enum case. Add an {{^isEnum}} guard inside the {{#isModel}} block so the call is only emitted for non-enum models; the dedicated {{#isEnum}} branch already below handles enum validation correctly. Test: NullableFieldsMapResponse (anyOf wrapper of a success/error pair with nullable required fields) added to the okhttp-gson fake petstore; two JSONTest cases verify deserialization round-trips when nullable required fields are null. Refs OpenAPITools#18547
CI's bin/generate-samples.sh regen skips writing test files when they already exist, and only newly-written files go into the FILES index. The test stubs were emitted on first regen and listed in FILES; CI's re-regen sees them existing -> skips -> filters them from FILES, producing a 'Samples up-to-date' diff. Remove the four NullableFields* test stub entries to match what regen actually produces.
The new testAnyOfWithNullableRequiredFields cases changed the file SHA; update the hash so 'Misc tests / Detect changes in test files' passes.
winrid
added a commit
to winrid/openapi-generator
that referenced
this pull request
May 1, 2026
Added PetReactionStatus, PetReactionResponse, PetEmptyMetadata, PetReactionsResponse to the dart fake-petstore yaml; that yaml is also consumed by dart-dio configs. Regenerate to keep CI 'Samples up-to-date' green. Also strip the auto-generated test stub entries from the FILES index because CI's regen filters them out (see OpenAPITools#23669 for the same pattern).
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.
Refs #18547 (this is the enum slice of the broader "validateJsonElement cannot find symbol" surface).
A property that is both
isModelandisEnum(a$refto a top-level enum schema) emittedMyEnum.validateJsonElement(...)inside the parent class'svalidateJsonElement. Enum classes don't declare that method, so the generated POJO failed to compile.Fix
Wrap the
{{#isModel}}validateJsonElementcall with{{^isEnum}}inJava/libraries/okhttp-gson/pojo.mustache. The dedicated{{#isEnum}}branch already below handles enum validation correctly via the codegen-generated enum's own validator.Test
NullableFieldsMapResponseadded to the okhttp-gson fake petstore: ananyOf [NullableFieldsMapSuccess, NullableFieldsMapError]whose value type contains nullable required fields.JSONTestcases verify deserialization round-trips when nullable required fields arenull.JSONTestcases pass (2 pre-existing skips unchanged).PR checklist
master(5.x.x) (patches will be cascaded frommasterto other branches by the maintainers)cc @bbdouglas @wing328 @JFCote