-
Notifications
You must be signed in to change notification settings - Fork 6k
java support inheritance #1120
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
java support inheritance #1120
Conversation
as per swagger-api#1015 (and swagger-api#946) this is now optional and disabled by default. this results in extra unnecessary code, masking fields in some cases, and breaks code generated for jax-rs in certain cases (enums with inheritance).
Just a reminder, before merging this we need to clarify the inheritance with regards to the spec. Can't merge it for now. |
To expand on @webron -- this does not fix the underlying problem which I think is that what should be treated as extension is implemented as inheritance in the current Java implementation. However this expands the (already very large) set of cases where the theoretically-wrong implementation works totally fine. Partial work towards a proper implementation (see #1094 for discussion) has caused a regression in the cases where java codegen worked, including the model we use (of course) and the following cut-down model:
|
Note that if you have multiple allOf with enums, the class extension trick will only work for one of the allOf (since we can only extend one class) so I think this is not an optimal solution. |
What's the status of this PR? |
No idea. This was a useful band-aid but not a cure-all. Maybe someone has improved the underlying problems in which case this could be closed? |
Right now we have a situtation where:
So, the child models specify that they extend another model, but then copy in their properties anyway. This is Bad Java. I'd like to see a single decision here - the models in Java either extend, or they don't. Right now, they're straddling that boundary. |
@webron Please can you chip in? Right now, for a bunch of previously "working" cases, Java codegen doesn't work properly. It's also somewhat schizophrenic, where generated model classes declare extension, but nonetheless redefines the properties. See comment above. If we can't enable supportsInheritance on a theoretical blocker, then I'd suggest exposing this parameter through the CLI and allowing users to override it. |
We have a clearer idea now, but I'm not really sure what's implemented right. I'd rather have @wing328 chip in and look at it. |
Please refer to #2096 for the latest discussion on |
@wing328 What is the status of this? |
Please refer to #2096 for the latest update on supporting inheritance in Java. |
This solution doesn't work when a definition imports multiple models through allOf : only the first model is taken for inheritance (obviously) and the attributes of the other models are not copied. |
This is a philosophical question - does "allOf" indicate inheritance? I was using the supportsInheritance flag also to suppress copying of all the fields from the parent class to the subclass. The subclasses should not have an extra copy of all the fields of the parent class. |
The spec is quite clear about that : allOf indicates inheritance only if the referenced model holds a discriminator field. Otherwise it is composition. |
Can be closed. |
When this is planned to integrate? Can I help on anything related? |
@FireZenk It's been integrated long ago. This issue can be closed. |
as per #1015 (and #946) this is now optional and disabled by default.
this results in extra unnecessary code, masking fields in some cases, and
breaks code generated for jax-rs in certain cases (enums with inheritance).
(this is a resubmission of #1094 targetting
master
branch -- see comments there)