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
Child in hierarchy of more than one level doesn't inherit from its parent #3474
Now you define the parent in swagger-codegen inside DefaultCodegen.fromModel method.
You set as the parent the first "interface" that has a discriminator. But in the case of a hierarchy with more than one level the discriminator would be in the root of the hierarchy and this condition would be false.
I change the code to first search for a parent with discriminator and if it does not exist, then I set as the parent the first of the ComposedModels inside the "interfaces".
I will add a pull request with my solution.
I am also getting this for typescript-node and typescript-angular. I'm guessing these changes to swagger-parser will affect every language since the responsibility of finding the parent has changed.
Works fine when all the models are defined in a single file.
Still doesn't work with models split to several files. Consider the following scenario: there are multiple web services that share common resources. So there is a common models spec file, and a spec file for each service.
When the common specs file defined like this
and in service file there is an inheritance from Observation (see the attachment) the code that is produced (with Java language) doesn't contain any extends. Neither for Observation (which resides in the same file with its parent) or MyCoolResource (which extends Observation and sits in a different file).
Here is even weirder thing:
If you do define an additional discriminator for Observation like this:
the code that is produced for MyCoolResource does contain extends! Which is completely fine by me, I wouldn't mind adding another discriminator.
But the code that is produced for Observation still lacks extends of BaseResource
I'm little confused here. Can someone clarify my doubts?
My understanding is a subclass extends from baseclass if baseclass has declared a discriminator. Otherwise subclass just composes fields from baseclass with no parent child relationship.
example can be used in polymorphic way, because it declares a discriminator.
subexample "extends" from example ( because example can be used in a polymorphic way)
Shouldnt' subsubexample extend example because example was the one who defined the discriminator?
if subsubexample extends subexample, doesn't it mean subexample can be used in a polymorphic way (which was not intended)?
Isn't subsubexample "composing" from subexample, because subexample has not declared a discriminator ?
It is my understanding that when allOf: references another definition that does not contain a discriminator, that the Java class will "extend" the other definition, but there will not be Jackson annotations on the classes that will allow correct serialization and deserialization.
The discriminator in a definition enable the generation of the Jackson annotations on the Java classes.
Activity
support for hierarchies with more than one level, fixes swagger-api#3474
fix some inheritance/composition issues and add allOf unit tests
pixelshaded commentedon Aug 24, 2016
I am also getting this for typescript-node and typescript-angular. I'm guessing these changes to swagger-parser will affect every language since the responsibility of finding the parent has changed.
wing328 commentedon Oct 3, 2016
PR (#3637) merged into master. Please pull the latest master to give it a try.
just-jeb commentedon Oct 19, 2016
Works fine when all the models are defined in a single file.
Still doesn't work with models split to several files. Consider the following scenario: there are multiple web services that share common resources. So there is a common models spec file, and a spec file for each service.
When the common specs file defined like this
{ "definitions": { "ResourceDescriptor": { "description": "This object is a Resource Id", "type": "object", "properties": { "id": { "type": "string" }, "resourceType": { "type": "string" } }, "required": [ "id", "resourceType" ] }, "BaseResource": { "discriminator": "baseResType", "type": "object", "description": "This is base class for all resources", "properties": { "resourceDescriptor": { "$ref": "#/definitions/ResourceDescriptor" }, "language": { "type": "string" }, "baseResType": { "type": "string" } }, "required": [ "resourceDescriptor", "baseResType" ] }, "Outcome": { "type": "object", "properties": { "responseString": { "type": "string" }, "responseCode": { "type": "integer" }, "resourceDescriptor": { "$ref": "#/definitions/ResourceDescriptor" } } }, "Observation": { "allOf": [ { "$ref": "#/definitions/BaseResource" }, { "type": "object", "properties": { "subject": { "$ref": "#/definitions/ResourceDescriptor" }, "effective": { "type": "string", "format": "date-time" } }, "required": [ "subject", "effective" ] } ] } } }and in service file there is an inheritance from
Observation(see the attachment) the code that is produced (with Java language) doesn't contain anyextends. Neither forObservation(which resides in the same file with its parent) orMyCoolResource(which extendsObservationand sits in a different file).Here is even weirder thing:
If you do define an additional discriminator for
Observationlike this:the code that is produced for
MyCoolResourcedoes containextends! Which is completely fine by me, I wouldn't mind adding another discriminator.But the code that is produced for
Observationstill lacksextendsofBaseResourceModelsForGithub.json.txt
ServiceForGithub.json.txt
sreeshas commentedon Dec 4, 2016
I'm little confused here. Can someone clarify my doubts?
My understanding is a subclass extends from baseclass if baseclass has declared a discriminator. Otherwise subclass just composes fields from baseclass with no parent child relationship.
example can be used in polymorphic way, because it declares a discriminator.
subexample "extends" from example ( because example can be used in a polymorphic way)
Shouldnt' subsubexample extend example because example was the one who defined the discriminator?
if subsubexample extends subexample, doesn't it mean subexample can be used in a polymorphic way (which was not intended)?
Isn't subsubexample "composing" from subexample, because subexample has not declared a discriminator ?
jeff9finger commentedon Dec 8, 2016
It is my understanding that when
allOf:references another definition that does not contain a discriminator, that the Java class will "extend" the other definition, but there will not be Jackson annotations on the classes that will allow correct serialization and deserialization.The
discriminatorin a definition enable the generation of the Jackson annotations on the Java classes.Using the original example:
In order to create Java classes that serialize/deserialize subsubexample as a subexample type, a unique discriminator must be declared on subexample.