Description
Description
When generating client code from an OpenAPI 3.0 specification using openapi-generator (version 7.13.0), the generator fails to generate or use the discriminator for polymorphic deserialization if:
- Two or more subtypes define properties with the same name (e.g., both have a property called value or data).
- Some subtypes have no unique properties at all.
openapi-generator version
7.13.0
OpenAPI declaration file content
This is a minimal example
components:
schemas:
BaseType:
type: object
discriminator:
propertyName: "@type"
properties:
id:
type: integer
"@type":
type: string
SubTypeA:
allOf:
- $ref: '#/components/schemas/BaseType'
- type: object
properties:
value:
type: string
SubTypeB:
allOf:
- $ref: '#/components/schemas/BaseType'
- type: object
properties:
value:
type: string
Generation Details
In the config file I added:
"useOneOfDiscriminatorLookup": true,
Result
The generator does not generate code that uses the discriminator for deserialization.
In Python, deserialization fails with a "multiple matches found" exception.
Suggest a fix
The generator should either emit a clear error/warning during generation or support discriminator-based deserialization as long as the discriminator property is present in the payload, regardless of duplicate property names.
At minimum, this limitation should be clearly documented.
Workaround
Ensure that all subtypes have at least one unique property name, or use the discriminator property with a unique value for each subtype.