Skip to content

[BUG][JAVA][okhttp-gson] Skip validateJsonElement for $ref'd enum properties#23669

Open
winrid wants to merge 3 commits intoOpenAPITools:masterfrom
winrid:pr/java-okhttp-gson-enum-validate
Open

[BUG][JAVA][okhttp-gson] Skip validateJsonElement for $ref'd enum properties#23669
winrid wants to merge 3 commits intoOpenAPITools:masterfrom
winrid:pr/java-okhttp-gson-enum-validate

Conversation

@winrid
Copy link
Copy Markdown
Contributor

@winrid winrid commented Apr 30, 2026

Refs #18547 (this is the enum slice of the broader "validateJsonElement cannot find symbol" surface).

A property that is both isModel and isEnum (a $ref to a top-level enum schema) emitted MyEnum.validateJsonElement(...) inside the parent class's validateJsonElement. Enum classes don't declare that method, so the generated POJO failed to compile.

Fix

Wrap the {{#isModel}} validateJsonElement call with {{^isEnum}} in Java/libraries/okhttp-gson/pojo.mustache. The dedicated {{#isEnum}} branch already below handles enum validation correctly via the codegen-generated enum's own validator.

Test

  • NullableFieldsMapResponse added to the okhttp-gson fake petstore: an anyOf [NullableFieldsMapSuccess, NullableFieldsMapError] whose value type contains nullable required fields.
  • Two new JSONTest cases verify deserialization round-trips when nullable required fields are null.
  • All 28 JSONTest cases pass (2 pre-existing skips unchanged).

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
    
  • File the PR against the correct branch: master (5.x.x) (patches will be cascaded from master to other branches by the maintainers)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc @bbdouglas @wing328 @JFCote

…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
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 21 files

winrid added 2 commits April 30, 2026 15:34
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).
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.

1 participant