Skip to content

Discriminated Union Not Typed Correctly #2154

Open
@iulspop

Description

@iulspop

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions