You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Java] Useless generation of fields when using allOf #1348
It even leads to an exception : class io.swagger.client.model.Bar declares multiple JSON fields named foo when using Gson (in okhttp-gson and retrofit libraries)
@cbornet my understanding of allOf (without discriminator) is that child should "copy" all the parent properties to itself (child) since child does not inherit (extend) parent.
@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.
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).
I agree with @wing328 that class extension should be reserved for when we have discriminator support.
So what should be done ? I have removed the class extension on my fork and I can pull a PR.
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:
It should support the same inheritance hierarchy as specified in the Swagger model.
Also, this generates no extra properties at all (it is the same as Page class, with no extra properties):
Activity
cbornet commentedon Oct 7, 2015
It even leads to an exception :
class io.swagger.client.model.Bar declares multiple JSON fields named foowhen using Gson (in okhttp-gson and retrofit libraries)wing328 commentedon Oct 7, 2015
@cbornet my understanding of
allOf(withoutdiscriminator) is that child should "copy" all the parent properties to itself (child) since child does not inherit (extend) parent.Ref: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#composition-and-inheritance-polymorphism
Do you have a sample spec so that I can repeat the issue you mentioned above?
cbornet commentedon Oct 7, 2015
@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.
cbornet commentedon Oct 7, 2015
A spec to reproduce here: https://raw.githubusercontent.com/swagger-api/swagger-spec/07cce43535e90815737e7258bb4d51c0c76999d6/examples/v2.0/json/petstore-expanded.json
cbornet commentedon Oct 10, 2015
The issue is also debated in #1120 . We need to have class extension or copy but not both as it fails with gson.
remove java subclassing when using allOf for composition
cbornet commentedon Nov 9, 2015
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).
I agree with @wing328 that class extension should be reserved for when we have
discriminatorsupport.So what should be done ? I have removed the class extension on my fork and I can pull a PR.
hiveship commentedon Feb 8, 2016
@wing328 I'm facing the problem. What is the final decision about it ?
ethlo commentedon May 4, 2016
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:
It should support the same inheritance hierarchy as specified in the Swagger model.
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?
wing328 commentedon Jul 19, 2016
@cbornet PR (#3393) has been merged into master. Please pull the latest to give it a try.