-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Child in hierarchy of more than one level doesn't inherit from its parent #3474
Comments
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. |
PR (#3637) merged into master. Please pull the latest master to give it a try. |
Works fine when all the models are defined in a single file. {
"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": {
"allOf": [
{
"$ref": "#/definitions/BaseResource"
},
{
"discriminator": "observationType",
"type": "object",
"properties": {
"subject": {
"$ref": "#/definitions/ResourceDescriptor"
},
"effective": {
"type": "string",
"format": "date-time"
},
"observationType": {
"type": "string"
}
},
"required": [
"subject",
"effective",
"observationType"
]
}
]
} the code that is produced for |
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. Shouldnt' subsubexample extend example because example was the one who defined the discriminator? |
It is my understanding that when The 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.
|
Description
When you create a hierarchy with more than one level the generated java code of the child doesn't inherit (extends) from its parent
Swagger-codegen version
2.2.0
Swagger declaration file example
Hierarchy generated classes
Error detected
SubsubexampleModel should extends from SubexampleModel
Suggested fix
First of all the parent property in a ComposedModel isn't set anymore in the parser. That's because of this issue and commit:
swagger-api/swagger-parser#245
swagger-api/swagger-parser@be6f068
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.
Thanks!
Regards,
Adrian
The text was updated successfully, but these errors were encountered: