OpenAPITools / OpenAPITools/openapi-generator

[BUG] Duplicate Model problem when using oneOf

Open
#15,860 0 comments 1 reaction 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

Hi.
I am using a typescript-axios generator. I have a problem with the Model for composed schemas.

Imagine openapi.yml has the below content:

Item:
  type: object
  properties:
    id:
      type: string
    attributes:
      oneOf:
        - $ref: "#/components/schemas/ItemAttributes"
        - $ref: "#/components/schemas/Brand"

Generator config:

"generator-cli": {
    "version": "6.6.0",
    "useDocker": false,
    "generators": {
      "typescript-axios": {
        "generatorName": "typescript-axios",
        "additionalProperties": {
          "modelPackage": "model",
          "modelNameSuffix": "Model",
          "apiPackage": "api",
          "apiNameSuffix": "Api",
          "supportsES6": true,
          "withSeparateModelsAndApi": true
        },
      }
    }
}

as It shows we may have 2 models ItemAttributesModel based on #/components/schemas/ItemAttributes and BrandModel based on #/components/schemas/Brand.

On the other hand, since Item.attributes has oneOf props then the openapi-generator generates a new model for it through the combination of Item + attributes (ItemAttributesModel). So due to the ItemAttributesModelis existed before then, the generation fails.

I have tested with version 5.4.0 and there is no problem in 5.4.0. because in version 6.0.0 and above, it generates a new model for oneOf but in version 5.4.0 it doesn't generate a new model for this situation and uses UNION TYPE like: ItemAttributesModel | BrandModel.

The main question is, how can disable this feature added in version 6.0.0 in order to use UNION TYPE instead of generating new model?

openapi-generator version
6.6.0

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

Reproduce the issue with the supplied OpenAPI schema and typescript-axios configuration using version 6.6.0, then compare generated output with version 5.4.0. Trace the oneOf model-generation behavior and determine whether a configuration option can restore the union type; done means generation no longer fails on the duplicate model and produces the intended union.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.