openapi-typescript
openapi-typescript copied to clipboard
Schema generation leads to generating an invalid type
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
- [x] My OpenAPI schema passes the Redocly validator (
npx @redocly/cli@latest lint) - [ ] I’m willing to open a PR (see CONTRIBUTING.md)