Skip to content

[BUG] Duplicate Model problem when using oneOf #15860

@hannanstd

Description

@hannanstd

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions