OpenAPITools / OpenAPITools/openapi-generator
[BUG] Python client code generation with allOf and discriminator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I am trying to generate python client code from yaml that uses allOf with a discriminator property,
generated code in 4.3.1 is not describing inheritance between generated models, schemas that are composed from parent model (using allOf) do not have the attributes of the parent as it is represented in JAVA with class extension.
Tried generating using v5 that came out recently and the request validation is failing around get_discriminated_attributes in model_utils
openapi-generator version
4.3.1 / 5.0.0
OpenAPI declaration file content or url
ParentObject:
type: object
required:
- objectType
- baseProperty
properties:
objectType:
type: string
baseProperty:
type: string
discriminator:
propertyName: objectType
ChildObject1:
allOf:
- $ref: '#/components/schemas/ParentObject
- type: object
properties:
extraProp1:
type: string
ChildObject2:
allOf:
- $ref: '#/components/schemas/ParentObject
- type: object
properties:
extraProp2:
type: string
in 4.3.1, generated models are:
ParentObject with objectType property
ChildObject1 with extraProp1 and no mention of ParentObject properties/any relation to it (unlike Java where there is a clear inheritance)
same with ChildObject2
in 5.0, generated code looks more attentive to the allOf attributes, but when running requests with created object of type ChildObject1 for example, request validation fails on initial steps, and GET requests fail on nullable and non-required properties if returned as null from server
Steps to reproduce
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided YAML schema and compare the generated ParentObject, ChildObject1, and ChildObject2 models in generator versions 4.3.1 and 5.0.0. Read the Python client's model_utils entry point, especially get_discriminated_attributes, and reproduce request validation and nullable-property failures. Done means allOf inheritance and discriminator handling behave consistently without those validation failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, python
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100