Repository navigation
[Java] [okhttp-gson] Add anyOf Discriminator Support - #24632
Conversation
anOf Discriminator SupportanyOf Discriminator Support
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
|
@wing328 Let me know what to do about that failing test, I thought that would be a fine place to add a new test but CI doesn't seem to like the fact that file was changed. |
|
I'll fix it. Don't worry. Thanks for the contribution as always. |
|
@ckoegel I think you broke master. JsonTest.java was manual updated. @wing328 what is the goal of this |
[Java] [okhttp-gson] Add `anyOf` Discriminator Support (OpenAPITools#24632) [Java][okhttp-gson] Fix `LocalDateTime` Serialization (OpenAPITools#24643)
Adds support for discriminators for
anyOfmodels in the Java okhttp-gson library. This functionality is copied over from theoneOfmodel to match it, and is also gated behind theuseOneOfDiscriminatorLookupflag. I kept it behind the flag since it seemed reasonable to assume users would want to toggle discriminator lookup for both oneOf+anyOf at once, tho the flag is now slightly inappropriately named. Lmk if we need to make a change regarding that, that flag is used across a few generators.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.
@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
Adds discriminator-based deserialization for
anyOfmodels in the Javaokhttp-gsongenerator, matchingoneOf. It now performs fast discriminator lookup when present and safely skips it for non-object payloads, with clearer warnings for missing or non-primitive discriminator values.New Features
anyOfadapters with early switch and fallback to schema-order matching.MammalAnyof) and tests for mapped values, unmapped fallback, and empty payload failure.Migration
useOneOfDiscriminatorLookupto apply to bothoneOfandanyOf.Written for commit ebcd0a5. Summary will update on new commits.