Skip to content

Discriminator enum property breaks enum value #2775

Description

@alex-eri

openapi-typescript version

7.13.0

Node.js version

v24.13.0

OS + version

Debian GNU/Linux 13 (trixie)

Description

If the schema declares a oneOf property with discriminator the generated Types will have their name as discriminator value and their value at same time. So generated type is always never.

Reproduction

Schema: https://yookassa.ru/developers/api/yookassa-openapi-specification.yaml

Generated type is never

        ConfirmationDataExternal: Omit<components["schemas"]["ConfirmationData"], "type"> & Record<string, never> & {
            /**
             * @description discriminator enum property added by openapi-typescript
             * @enum {string}
             */
            type: "ConfirmationDataExternal";
        } & {
            /**
             * @description discriminator enum property added by openapi-typescript
             * @enum {string}
             */
            type: "external";
        };

Expected result

        ConfirmationDataExternal: Omit<components["schemas"]["ConfirmationData"], "type"> & Record<string, never> & {
            /**
             * @description discriminator enum property added by openapi-typescript
             * @enum {string}
             */
            type: "external";
        };

Schema has issues, but not here.

    ConfirmationData:
      description: "Information required to initiate the selected payment confirmation scenario by the user. More about confirmation scenarios: https://yookassa.ru/developers/payment-acceptance/getting-started/payment-process#user-confirmation"
      type: "object"
      properties:
        type:
          $ref: "#/components/schemas/ConfirmationDataType"
        locale:
          $ref: "#/components/schemas/Locale"
      discriminator:
        propertyName: "type"
        mapping:
          redirect: "#/components/schemas/ConfirmationDataRedirect"
          external: "#/components/schemas/ConfirmationDataExternal"
          qr: "#/components/schemas/ConfirmationDataQr"
          embedded: "#/components/schemas/ConfirmationDataEmbedded"
          mobile_application: "#/components/schemas/ConfirmationDataMobileApplication"
      required:
      - "type"

....

    ConfirmationDataType:
      description: "Type of payment confirmation scenario by the user. Possible values: redirect - redirecting the user to a ready-made YooMoney page or a partner's page; external - waiting for the user to confirm the payment independently; qr - generating a QR and displaying it on the payment page so that the user can confirm the payment; embedded - displaying the YooMoney payment widget; mobile_application - redirecting the user to the partner's payment app."
      type: "string"
      enum:
      - "redirect"
      - "external"
      - "qr"
      - "embedded"
      - "mobile_application"

....

    ConfirmationDataExternal:
      type: "object"
      allOf:
      - $ref: "#/components/schemas/ConfirmationData"
      - type: "object"

Required

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

Extra

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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