-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add Polymorphism Support #1152
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
Add Polymorphism Support #1152
Conversation
@Fyro-Ing This pr works but I'd like to re-work some aspects of it. Comments inlined |
@@ -47,7 +48,8 @@ public Model( | |||
String baseModel, | |||
String discriminator, | |||
List<String> subTypes, | |||
String example) { | |||
String example, | |||
Model parent) { |
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'd like tho use ModelRef
here directly assuming some other plugin is responsible to dig out the Model
from the @ApiModel#parent()
. Typically by modifying the ModelDependencyProvider
or creating a new implementation (plugin?) i.e. Parent => is a dependency of => Subclass
Secondly, we're anyways turning around and resolving it to a RefModel in the mapper.
it would be possible to add this feature in the milestone 2.4.0? |
I could try be if we finish out this pr based on feedback it might be possible |
Thanks for this. I see this feature is now pushed to milestone 2.5.0, is there an ETA for 2.5.0 ? Thanks. |
@dilipkrish @Fyro-Ing I think there's may be an issue with the above - So for the following:
will only work for me if
Or perhaps add a dummy API... Here's the stack trace the above fails if not using the workaround:
|
Any updates on this ? |
See fixes I applied to swagger-core: thought maybe it'll help this project too - it seems to fix the same symptom as described in my previous comment as well. |
Hi. Any word on this PR? |
@benfowler needs some work... actually may need to be re-implemented |
@dilipkrish I know you are not actively working on this project butthis PR is really important and will solve a bunch of issues on are side too. Would you please review it? |
@cemo I am actively working on this project. Just not this PR :) This solution will not work when supporting OpenAPI 3.0 thats why its not pulled in. |
@dilipkrish Why will it not work? Where do you see any problems? Can you please elaborate on that a bit. Whats with backwards compatibility for OAS 2? |
@ralfhecktor composition based inheritance was introduced in 3.0 (allOf, anyOf etc.) with better schema support. Discriminator based inheritance isn't ideal when there is better support. I'd rather think the problem through "whole brain" than hack the solution together. |
@dilipkrish do you have any idea when 3.0 support will be landed? |
Im hoping in June. If I get some help with PR's etc. may be earlier |
How can we help? |
@raderio there are plenty of issues where I could use help |
It is still supported in OpenAPI 3 https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/ Discriminator section, if it is better than why they support it? Also discriminator is supported by Jackson https://gist.github.com/christophercurrie/8939489 https://github.com/Rebilly/ReDoc/blob/master/docs/images/discriminator-demo.gif |
Im not denying there is support, just suggesting there are better ways of doing it @raderio |
If there are better ways of doing it, why OpenAPI 3 supports it, why they just don't dropped it? Maybe because in some cases discriminator fits better? |
@raderio Will definitely revisit this PR when it comes time to look at open api 3 support |
@Fyro-Ing thanks for your PR, while I didnt incorporate all of your changes I cherry picked the important changes you contributed to the |
@dilipkrish coooool |
@raderio targetting this weekend. Yes feedback will be awesome! You can use the SNAPSHOT build |
@dilipkrish I've tested, it works, big thanks. |
@raderio If you don't mind, would you please share your use case? |
Guys, is there any idea if this would be applied to |
@diogosouza What are you seeing/not-seeing? |
Hi @dilipkrish, |
@MrDefinite not if its not supported in the spec |
Hi @dilipkrish, { Any suggestion? |
No. Don't use inheritance in an API. It exposes the type system and implementation language internals. |
I've added "Polymorphism support" (discriminator on parent, and allOf on child(s)) with springfox
On java models :
Parent -> @apimodel(discriminator="id")
Child -> @apimodel(parent = Parent.class)
see Fyro-Ing@43923f5