Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1662
Closed
Open
Issue created Dec 11, 2018 by Administrator@rootContributor

[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 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 (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
  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
  • #1842
  • #1841

Similar issues has been seen with CSHARP and Java:

  • #1068
  • #1113
  • #1663 (closed)
  • #453 (closed)
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.

Assignee
Assign to
Time tracking