openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Schema generation leads to generating an invalid type

Open Miosp opened this issue 1 year ago • 0 comments

Description

I have a following openAPI 3.0.3 schema:

"Entity": {
  "oneOf": [
    {
      "allOf": [
        {
          "$ref": "#/components/schemas/FileEntity"
        },
        {
          "type": "object",
          "required": [
            "tag"
          ],
          "properties": {
            "tag": {
              "type": "string",
              "enum": [
                "File"
              ]
            }
          }
        }
      ]
    },
    {
      "allOf": [
        {
          "$ref": "#/components/schemas/FolderEntity"
        },
        {
          "type": "object",
          "required": [
            "tag"
          ],
          "properties": {
            "tag": {
              "type": "string",
              "enum": [
                "Folder"
              ]
            }
          }
        }
      ]
    }
  ],
  "discriminator": {
    "propertyName": "tag"
  }
}

Which is generated by some other piece of code. After passing this through openapi-ts it gives:

Entity: ({
    tag: "Entity";
} & (components["schemas"]["FileEntity"] & {
    /** @enum {string} */
    tag: "File";
})) | ({
    tag: "Entity";
} & (components["schemas"]["FolderEntity"] & {
    /** @enum {string} */
    tag: "Folder";
}));

which gets evaluated to never

Name Version
openapi-typescript 7.3.0
Bun 1.1.17
OS + version Windows 11

Reproduction

I run the openapi-typescript command on my schema.json file

Expected result

(in case it’s not obvious)

Checklist

Miosp avatar Aug 25 '24 18:08 Miosp