[BUG][Python] Multi-level inheritance not working correctly
Created by: tomghyselinck
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 ofAngryDog
,NiceDog
, andFunnyCat
object, the Python client will return aPet
object (without all final_type-specific attributes missing). - When
GET /dog
returns any ofAngryDog
orNiceDog
object, the Python client will return aPet
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 (closed)).
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
- #1842
- #1841
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.