[java][Native] [#12911] Improve handling of oneOf/anyOf with mixed object and lists etc
- Improve handling of oneOf/anyOf with mixed object and lists etc (open since 2022)
- Also correct any tests outside of native changes (unrelated but boy scout rule, don't leave broken tests in master)
- Also updated native pom to use current versions for items.
- Had to also correct javadoc issues where < and > symbols were not html escaped once oneOf/anyOf tests were added which also contained lists.
- Also jackson3 is usually always going to go with newest Jakarta spec (not javax) from 17+ so i flipped the tests for it.
I had to skip adding the public constructors for List in oneOf/anyOf due to inability to only add it once and causing java compile errors (you can't have more than on interface of List...)
java native can now handle
fruitOrFruits:
properties:
color:
type: string
x-has-list-alternative: true
oneOf:
- $ref: "#/components/schemas/apple"
- type: array
items:
$ref: "#/components/schemas/apple"
- $ref: "#/components/schemas/banana"
- type: array
items:
$ref: "#/components/schemas/banana"
additionalProperties: false
gmFruitOrFruits:
properties:
color:
type: string
x-has-list-alternative: true
anyOf:
- $ref: "#/components/schemas/apple"
- type: array
items:
$ref: "#/components/schemas/apple"
- $ref: "#/components/schemas/banana"
- type: array
items:
$ref: "#/components/schemas/banana"
additionalProperties: false
PR checklist
-
Read the contribution guidelines.
-
Run the following to build the project and update samples:
./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit -
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
Improves the Java native client's handling of oneOf/anyOf schemas that mix object and list alternatives. Deserialization now inspects the JSON shape before each candidate, so list alternatives are only attempted on arrays and object alternatives only on objects.
- Added
fruitOrFruits(oneOf) andgmFruitOrFruits(anyOf) test schemas covering mixed object/list alternatives. - Public constructors for list alternatives are not generated because Java cannot implement multiple
Listinterface variants in one class. - Updated Jackson and Jakarta dependency versions in the native templates, regenerated samples, and switched the Jackson 3 sample to Jakarta EE annotations.
- Generated
oneOf/anyOfdocs now iteratecomposedSchemasfor correct ordering and escape</>in javadoc. - Removed a duplicate
jakarta.validationdependency from theretrofit2POM.