Open
Description
openapi-typescript version
7.6.1
Node.js version
22.12.0
OS + version
macOs 15.3
Description
If the schema declares a oneOf
property with discriminator the generated Types will have their name as discriminator value.
Reproduction
Example Schema:
openapi: 3.0.3
components:
schemas:
Post:
properties:
comments:
type: array
items:
oneOf:
- $ref: '#/components/schemas/TextComment'
- $ref: '#/components/schemas/QuoteComment'
discriminator:
propertyName: commentType
TextComment:
type: object
required:
- commentType
properties:
commentType:
type: string
enum:
- text
QuoteComment:
type: object
required:
- commentType
properties:
commentType:
type: string
enum:
- quote
Output:
schemas: {
Post: {
comments?: (components["schemas"]["TextComment"] | components["schemas"]["QuoteComment"])[];
};
TextComment: {
/**
* @description discriminator enum property added by openapi-typescript
* @enum {string}
*/
commentType: "TextComment";
};
QuoteComment: {
/**
* @description discriminator enum property added by openapi-typescript
* @enum {string}
*/
commentType: "QuoteComment";
};
Where actual values of commentType
should be text|quote
.
This issue does not occur if
discriminator:
propertyName: commentType
is absent, or if the types are not nested/referenced at all.
Expected result
schemas: {
Post: {
comments?: (components["schemas"]["TextComment"] | components["schemas"]["QuoteComment"])[];
};
TextComment: {
/**
* @description discriminator enum property added by openapi-typescript
* @enum {string}
*/
commentType: "text";
};
QuoteComment: {
/**
* @description discriminator enum property added by openapi-typescript
* @enum {string}
*/
commentType: "quote";
};
Required
- My OpenAPI schema is valid and passes the Redocly validator (
npx @redocly/cli@latest lint
)
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)