-
Notifications
You must be signed in to change notification settings - Fork 6k
[Java] Useless generation of fields when using allOf #1348
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
Comments
It even leads to an exception : |
@cbornet my understanding of Do you have a sample spec so that I can repeat the issue you mentioned above? |
@wing328 Well, it seems to me that implementing swagger composition with class extension would be fine if there was only one object possible in the composition since the classes are just mere containers for the Json mapping. But since there can be several objects to compose, it looks preferable to just copy the attributes for clarity and remove the class inheritance in the generated code. |
A spec to reproduce here: https://raw.githubusercontent.com/swagger-api/swagger-spec/07cce43535e90815737e7258bb4d51c0c76999d6/examples/v2.0/json/petstore-expanded.json public class Pet extends NewPet {
@SerializedName("name")
private String name = null;
@SerializedName("tag")
private String tag = null;
@SerializedName("id")
private Long id = null; public class NewPet {
@SerializedName("name")
private String name = null;
@SerializedName("tag")
private String tag = null; |
The issue is also debated in #1120 . We need to have class extension or copy but not both as it fails with gson. |
I have tested that a definition with multiple allOf gets the copies of all the elements so composition is working fine if we remove the class extension. As per #1120, there seems to be an issue when the parent holds an enum. I think the solution there would be to also copy the enum to the child class (or import the one from the parent class if it is visible). |
@wing328 I'm facing the problem. What is the final decision about it ? |
I was going to open a separate issue (and I still can if you find that more appropriate), but I just wanted mention other issues with model generation. It seems that model generation where inheritance/composition is involved is severely broken. Basically: Also, this generates no extra properties at all (it is the same as Page class, with no extra properties):
So my question is, is this an issue that people are actively working on, or should I have a look? |
When using composition with
allOf
, the child class contains un-needed attributes which are already in the parent class.The text was updated successfully, but these errors were encountered: