Skip to content

[BUG][Python] Multi-level inheritance not working correctly #1662

@tomghyselinck

Description

@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 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
  1. 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
    
  2. Start (mocked) server

    python3 -m connexion run --mock=all multi-level-inheritance.yaml
    
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions