Skip to content
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

Schema generation leads to generating an invalid type #1879

Open
1 of 2 tasks
Miosp opened this issue Aug 25, 2024 · 0 comments
Open
1 of 2 tasks

Schema generation leads to generating an invalid type #1879

Miosp opened this issue Aug 25, 2024 · 0 comments
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@Miosp
Copy link

Miosp commented Aug 25, 2024

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 Miosp added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Aug 25, 2024
@Miosp Miosp changed the title Schema generation leads to generating invalid type Schema generation leads to generating an invalid type Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

1 participant