Skip to content

[BUG] [Python] Discriminator Not Generated or Used When Subtypes Have Duplicate Property Names or No Unique Properties #21337

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

Open
MaxHuber03 opened this issue May 27, 2025 · 0 comments

Comments

@MaxHuber03
Copy link

MaxHuber03 commented May 27, 2025

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.

@MaxHuber03 MaxHuber03 changed the title [BUG] [Python] Discriminator Not Used for Subtypes in oneOf Array Response [BUG] [Python] Discriminator Not Generated or Used When Subtypes Have Duplicate Property Names or No Unique Properties May 28, 2025
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

1 participant