OpenAPITools / OpenAPITools/openapi-generator

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

Open
#21,337 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing Python client generation from the minimal OpenAPI declaration with openapi-generator 7.13.0 and useOneOfDiscriminatorLookup enabled. Inspect the generated deserialization behavior for duplicate subtype properties and subtypes without unique properties; done means discriminator-based deserialization works reliably or generation emits a clear warning or error, with regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.