-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Spring] OneOf Polymorphism support for spring boot #5596
Conversation
copy methods from OpenAPITools#5120 (oneOf support for jackson clients) to implement same in spring generate oneOf Class that has all properties from inherited classes fix property name of inherited model for oneOf fix imports for oneOf create oneOf stuff only if useOneOfInterfaces is setted
fixed format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey 👋 IIUC a lot of code added is a copy-paste from the old version of the oneOf
implementation that I wrote for JavaClientCodegen
. Since then, most of the functionality was moved to DefaultCodegen
, so you really only need to make sure the overloading methods properly call their parent's implementation (specifically postProcessOpenAPI
and postProcessAllModels
). Then it should be matter of setting useOneOfInterfaces = true
and perhaps overriding the addImportsToOneOfInterface
method (see how this is done in JavaClientCodegen
).
I hope this makes sense.
@@ -579,6 +588,251 @@ public void preprocessOpenAPI(OpenAPI openAPI) { | |||
} | |||
} | |||
} | |||
|
|||
if (useOneOfInterfaces && openAPI.getComponents() != null){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this method calls super.preprocessOpenAPI
, I don't think you should need to include this block at all. Is there a specific reason why you added it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it because SpringCodegenTest.testAdditionalPropertiesPutForConfigValues and
SpringCodegenTest.testInitialConfigValues fails with NPE otherway.
} | ||
} | ||
|
||
public void addOneOfNameExtension(Schema s, String name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICS, this is the same as DefaultCodegen.addOneOfNameExtension
and so I think it can be safely omitted.
} | ||
} | ||
|
||
public void addOneOfInterfaceModel(ComposedSchema cs, String name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above - this is already implemented in DefaultCodegen.addOneOfInterfaceModel
, so let's omit it here (unless there's a specific reason to override it).
return null; | ||
} | ||
|
||
private class OneOfImplementorAdditionalData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, I don't think this is really necessary here.
Hey @bkabrda! Thank you for your codereview of my pullrequest. And i have one question to your implementation. |
Sure, I think that's perfectly fine.
TBH I don't have a good answer. I can definitely take a closer look when time permits, but I have tons of work right now and can't promise anything. |
Fix 5381
Implemented OneOf Polymorphism for java spring library.
PR checklist
./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc).master
,4.3.x
,5.0.x
. Default:master
.@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) @bkabrda (2020/01)