Closed
Description
Description
When using a discriminator where multiple mapping keys (e.g., "approval_policy" and "entity") point to the same common schema, the generated TypeScript types incorrectly narrow the allowed discriminator values to only one representative (in this case, "approval_policy").
Reproducible example or configuration
npx @hey-api/openapi-ts \
-i https://pub-32c654c6a381482f95842971390c1d2f.r2.dev/gh-issues/discriminator-bug.yaml \
-o src \
-c @hey-api/client-fetch
generated:
export type RootSchemaInput = ({
object_type?: 'approval_policy';
} & CommonSchemaInput) | ({
object_type?: 'payable';
} & PayableSchemaInput);
export type CommonSchemaInput = {
object_type?: 'approval_policy' | 'entity';
};
export type PayableSchemaInput = {
object_type?: 'payable';
};
expected
export type RootSchemaInput = ({
object_type: 'approval_policy' | 'entity';
} & CommonSchemaInput) | ({
object_type: 'payable';
} & PayableSchemaInput);
export type CommonSchemaInput = {
object_type: 'approval_policy' | 'entity';
};
export type PayableSchemaInput = {
object_type: 'payable';
};
OpenAPI specification (optional)
openapi: "3.0.3"
info:
title: Minimal Discriminator Example
version: "1.0"
paths: {}
components:
schemas:
RootSchemaInput:
oneOf:
- $ref: "#/components/schemas/CommonSchemaInput"
- $ref: "#/components/schemas/PayableSchemaInput"
discriminator:
propertyName: object_type
mapping:
approval_policy: "#/components/schemas/CommonSchemaInput"
entity: "#/components/schemas/CommonSchemaInput"
payable: "#/components/schemas/PayableSchemaInput"
CommonSchemaInput:
type: object
properties:
object_type:
type: string
enum:
- approval_policy
- entity
PayableSchemaInput:
type: object
properties:
object_type:
type: string
enum:
- payable
System information (optional)
"@hey-api/openapi-ts": "^0.65.0"