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

Incorrect Type Generation for Discriminator Mappings: Common Schema Discriminator Values Not Fully Propagated #1905

Open
Omarov3000 opened this issue Apr 2, 2025 · 3 comments
Labels
bug 🔥 Something isn't working

Comments

@Omarov3000
Copy link

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"

@Omarov3000 Omarov3000 added the bug 🔥 Something isn't working label Apr 2, 2025
@Omarov3000
Copy link
Author

Note: the same issue happens for both: input and output

@Omarov3000
Copy link
Author

Probably duplicate of #1805 but with a bit easier reproduction

@mrlubos
Copy link
Member

mrlubos commented Apr 2, 2025

Yep! Thanks for flagging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants