Skip to content
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

[Python] Inheritance doesn't work #623

Closed
emreakca opened this issue Jul 23, 2018 · 3 comments
Closed

[Python] Inheritance doesn't work #623

emreakca opened this issue Jul 23, 2018 · 3 comments

Comments

@emreakca
Copy link

Description

The generated Python SubClass doesn't inherited from the BaseClass, when allOf is used.

SubClass:
  allOf:
    - $ref: '#/components/schemas/BaseClass'

The generated class shows

class SubClass(object):

instead of

class SubClass(BaseClass):

This issue was already posted (#453), but it's not solved nor answered.

openapi-generator version

3.1.1

Command line used for generation
java -jar ~/openapi-generator-cli-3.1.1.jar generate -g python -i openapi.json -o generated/python-client
Suggestion

Either do the inheritance correctly (as shown at the beginning), with the right constructors (__init__)
or add the Properties of the BaseClass to the SubClass, as in swagger 2.

@macjohnny
Copy link
Member

@emreakca @poli-granot this could be fixed by applying the changes in swagger-api/swagger-codegen@843c638 to https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/python/model.mustache#L13 and other relevant files. would you like to file a PR for this?

@spacether
Copy link
Contributor

spacether commented Jan 23, 2019

I am working on a PR which will fix this issue. The problem is that the mustache files iterate through #vars per here: https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/python/model.mustache#L36. #vars does not include the variables inherited from the allOf class. However, the requiredVars and optionalVars DO include those needed properties. My fix will iterate over the requiredVars and optionalVars.

@spacether
Copy link
Contributor

spacether commented May 30, 2020

composed schema inheritance is working in the python-experimental generator
Composed schema inheritance is implemented by storing instances of "ancestor" allOf models rather than using inherited classes.
This was done because multiple allOf models can contain the same property with differing enum and validation constraints on it.
Python class based inheritance generally assumes that a property has its definition/validation in one source of truth class location.

nilskuhn pushed a commit to nilskuhn/openapi-generator that referenced this issue Apr 6, 2023
chore(deps): update dependency @types/node to v14.18.13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants