-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
[spring] oneOf implementation for spring boot #10993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[spring] oneOf implementation for spring boot #10993
Conversation
- Adding support for oneOf with and without discriminators. - Created oneof_interface.mustache template.
- Updating SpringCodegen with an implementation to add imports for one of interfaces.
…e of. - Attempting to repair inline oneOf before calling the super.
- Post processing all oneOf models to add x-deduction and x-deduction-model-names vendor extensions.
- Composed schema defaults to having isMap set to true if it contains additional properties, this is not the case some times.
- Fixing the squashed imports.
- Removing extra space in between annotation and interface.
- If components are null, there is nothing to preprocess other than title etc.
- Adding some test cases for oneOf code generation.
- Running /bin/generate-samples.sh - Running /bin/utils/export_docs_generators.sh Signed-off-by: Martin <7595909+martin-bucinskas@users.noreply.github.com>
@martin-bucinskas Thank you for this implementation of oneOf support . I am also really interested in having this feature in the Spring/Java generator. I tested out your changes on a specification that I am working on and the generated code looked good. I am not a maintainer but for whatever it is worth. If there is anything I can help with to finally have oneOf support, please let me know. |
I'd like to echo the sentiment that this is something that is badly needed. Hopefully it can be merged and released soon! |
Yep, just hit the same issue |
@martin-bucinskas Is there something I can support you with? This feature would be highly welcome :D |
@daviian I'll have a look at at fixing the conflicts on this branch some time this weekend, this probably needs to have test cases updated that someone could take a look at. I'd love to get this feature in the openapi-generator too! |
Having the same issue, thanks for working on this guys! |
single values are treated as an array with one entry, see OpenAPITools/openapi-generator#10993
Doesn't the specification state that using
|
I don't think that a discriminator should be mandatory in such cases. https://spec.openapis.org/oas/v3.0.2#fixed-fields-20
MyResponseType:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
- $ref: '#/components/schemas/Lizard'
The use case for one of discriminator is not mandatory, but may be used to help resolve costly operations in a complex schema. However if the schema is not complex enough to require a discriminator, it should just be able to use a modern approach of deduction and generate valid code. |
- Updated one-of-spring code to match the latest changes within master branch.
This feature is badly needed in openapi-generator. OpenAPI spec though mentions @martin-bucinskas Thank you for your work. I was actually planning to write this feature till I stumbled on this PR. Will you be able to please resolve conflicts in this PR soon? Let me know if any help needed. @welshm @cachescrubber Do you agree with adding this feature to OpenAPI-generator? |
I do agree with the feature - some of this may be resolved already by #11650 - so likely this needs a rebase to resolve conflicts and re-test. Would also be good to include generated samples here to be able to see the output of the changes |
@martin-bucinskas , @alexsuperdev @welshm @smilep @feliperuiz @daviian @ManuelTS @SamD @weierstrass @jimsong Could you have a look this version of DEDUCTION of oneOf? |
Updated
SpringCodegen
to allow the usage ofoneOf
when generating models with discriminators and without.Fixes:
Generation of
oneOf
interfaces without discriminatorhttps://swagger.io/specification#discriminator-object states that
oneOf
can be used without a discriminator object.We can utilise a feature brought in by jackson since version 2.12 to use deduction-based polymorphism.
By setting the
x-deduction
andx-deduction-model-names
vendor extensions, we can set up the values that will be populated in theoneOf
templates for a deduction based approach, wherex-deduction
is a flag used to switch between deduction and discriminator approach, andx-deduction-model-names
is an array of the type names.PR based on #10463 implementation.
PR checklist
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*
.For Windows users, please run the script in Git BASH.
master
(5.3.0),6.0.x
@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) @nmuesch (2021/01)