fix(java): validate string enum values excluded by not
Fixes #25065
What does this PR do?
Fixes Java okhttp-gson validation for string properties that use not with an enum.
For a schema such as:
kind:
type: string
not:
enum:
- known
the generated validateJsonElement method previously checked only that kind was a string and did not enforce the value excluded by not.
This caused oneOf schemas that rely on not: enum to become ambiguous. For example, {"kind":"known"} could incorrectly match both the schema that explicitly allows "known" and the schema that excludes it.
Implementation
- Reads string enum values from the property's
composedSchemas.notmetadata during Java client model-property post-processing. - Exposes those excluded values to the
okhttp-gsonPOJO template. - Generates validation that rejects matching excluded string values.
- Keeps the change intentionally scoped to Java
okhttp-gsonand string enums undernot.
Tests
Added an OpenAPI 3.1 regression fixture with:
Known.kind:enum: [known]Other.kind:not: { enum: [known] }Union:oneOf: [Known, Other]
Added a Java client generation test that verifies the generated Other validation:
- checks the actual
kindproperty; - rejects
"known"; - does not incorrectly validate a synthetic
not_schemaproperty.
Targeted test:
JavaClientCodegenTest#testOneOfNotEnumValidation
passes successfully.
Summary by cubic
Fixes Java okhttp-gson validation so string properties using not with an enum reject excluded values, resolving ambiguity in oneOf schemas that rely on not: enum (issue #25065).
Previously validateJsonElement only checked that the property was a string, so {"kind":"known"} could match both a schema allowing "known" and one excluding it. The generator now reads the excluded values from composedSchemas.not, exposes them via a vendor extension, and generates validation that throws an IllegalArgumentException for disallowed values.
The change is scoped to Java okhttp-gson string enums under not, and adds a regression fixture plus a generation test covering the oneOf scenario, including enum references.