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

Discriminated Union Not Typed Correctly #2154

Open
2 tasks done
iulspop opened this issue Feb 13, 2025 · 0 comments
Open
2 tasks done

Discriminated Union Not Typed Correctly #2154

iulspop opened this issue Feb 13, 2025 · 0 comments
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@iulspop
Copy link

iulspop commented Feb 13, 2025

openapi-typescript version

7.6.1

Node.js version

22.12.0

OS + version

macOS 15.2

Description

Reproduce Bug

Given

    CreateRepositoryRequest:
      description: Lorem ipsum dolor sit amet.
      type: object
      discriminator:
        propertyName: type
        mapping:
          azure: '#/components/schemas/CreateAzureRepositoryRequest'
          git: '#/components/schemas/CreateGitRepositoryRequest'

When

run npm run generate

Actual

        CreateRepositoryRequest: Record<string, never>;

Expected

A discriminated union of the two types, something like:

        "CreateRepositoryRequest": {
            type: "azure" | "git";
        } & ({
            type: "azure";
        } & components["schemas"]["CreateAzureRepositoryRequest"]) | ({
            type: "git";
        } & components["schemas"]["CreateGitRepositoryRequest"]);

Reproduction

clone: https://github.com/iulspop/bug-report-openapi-typescript-feb-13-2025
then npm i && npm run generate

Expected result

A discriminated union of the two types, something like:

        "CreateRepositoryRequest": {
            type: "azure" | "git";
        } & ({
            type: "azure";
        } & components["schemas"]["CreateAzureRepositoryRequest"]) | ({
            type: "git";
        } & components["schemas"]["CreateGitRepositoryRequest"]);

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

@iulspop iulspop added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Feb 13, 2025
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