Description
The generated Python client does not properly return the final classes when multi-level inheritance is used.
For example:
- When
GET /pet returns any of AngryDog, NiceDog, and FunnyCat object, the Python client will return a Pet object (without all final_type-specific attributes missing).
- When
GET /dog returns any of AngryDog or NiceDog object, the Python client will return a Pet object (without all final_type-specific attributes missing).
Please note that you can also see that the member fields of the Pet and Dog parent object are missing in the AngryDog (cfr. #453).
openapi-generator version
I used OpenAPI generator CLI version 4.0.0-SNAPSHOT:
https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/openapi-generator-cli-4.0.0-20181210.103357-85.jar
OpenAPI declaration file content or url
See multi-level-inheritance.yaml in the attached zip-file:
multi-level-inheritance.zip
Command line used for generation
java -jar openapi-generator-cli-4.x.jar generate -i ./multi-level-inheritance.yaml -g python -o ./multi-level-inheritance/client/python
Steps to reproduce
-
Generate client code
See also multi-level-inheritance.sh.
wget \
'https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/openapi-generator-cli-4.0.0-20181210.103357-85.jar' \
-O 'openapi-generator-cli-4.x.jar'
rm -rf ./multi-level-inheritance/
java -jar openapi-generator-cli-4.x.jar generate -i ./multi-level-inheritance.yaml -g python -o ./multi-level-inheritance/client/python
-
Start (mocked) server
python3 -m connexion run --mock=all multi-level-inheritance.yaml
-
Run the client test
(cd multi-level-inheritance/client/python/ && python3)
import openapi_client
api = openapi_client.DefaultApi()
pet = api.pet_get()
print(type(pet))
print(pet)
dog = api.dog_get()
print(type(dog))
print(dog)
Output:
<class 'openapi_client.models.pet.Pet'>
{'pet_type': 'NiceDog'}
<class 'openapi_client.models.dog.Dog'>
{'doggie_thing': 'Playing with piece of wood'}
Related issues/PRs
Similar issues has been seen with CSHARP and Java:
Suggest a fix
When we add an addition discriminator in the Dog schema then GET /dog does properly return either an AngryDog or NiceDog object.
Description
The generated Python client does not properly return the final classes when multi-level inheritance is used.
For example:
GET /petreturns any ofAngryDog,NiceDog, andFunnyCatobject, the Python client will return aPetobject (without all final_type-specific attributes missing).GET /dogreturns any ofAngryDogorNiceDogobject, the Python client will return aPetobject (without all final_type-specific attributes missing).Please note that you can also see that the member fields of the
PetandDogparent object are missing in theAngryDog(cfr. #453).openapi-generator version
I used OpenAPI generator CLI version
4.0.0-SNAPSHOT:https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/openapi-generator-cli-4.0.0-20181210.103357-85.jar
OpenAPI declaration file content or url
See
multi-level-inheritance.yamlin the attached zip-file:multi-level-inheritance.zip
Command line used for generation
Steps to reproduce
Generate client code
See also
multi-level-inheritance.sh.Start (mocked) server
Run the client test
Output:
Related issues/PRs
Similar issues has been seen with CSHARP and Java:
Suggest a fix
When we add an addition
discriminatorin theDogschema thenGET /dogdoes properly return either anAngryDogorNiceDogobject.