Skip to content

Name of schema generated as type value when using oneOf #2318

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

Open
1 of 2 tasks
raduinsuretech opened this issue May 12, 2025 · 0 comments
Open
1 of 2 tasks

Name of schema generated as type value when using oneOf #2318

raduinsuretech opened this issue May 12, 2025 · 0 comments
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@raduinsuretech
Copy link

openapi-typescript version

7.6.1

Node.js version

20

OS + version

macOs 14.6

Description

When generating a schema from my openapi specification I get this schema:

    OfferBasePersonInternalRequest: {
        /** Format: int64 */
        id?: number;
        cif?: string;
        personType?: string;
        phone?: string;
        email?: string;
        address?: components["schemas"]["OfferAddressInternalRequest"];
    };
    OfferCompanyPersonInternalRequest: {
        personType: "OfferCompanyPersonInternalRequest";
    } & (Omit<components["schemas"]["OfferBasePersonInternalRequest"], "personType"> & {
        caenCode?: string;
        companyName?: string;
        companyType?: string;
    });
    OfferIndividualPersonInternalRequest: {
        personType: "OfferIndividualPersonInternalRequest";
    } & (Omit<components["schemas"]["OfferBasePersonInternalRequest"], "personType"> & {
        firstName?: string;
        lastName?: string;
        foreignPerson?: boolean;
        identityDocumentNo?: string;
        identityDocumentSeries?: string;
    });

the value of personType is incorrect. It should be a string, but here is constrained to be the name of the schema.

This is a my definition:

BasePersonInternalResponse:
  type: object
  properties:
    id:
      type: integer
      format: int64
    cif:
      type: string
    personType:
      type: string
    phone:
      type: string
    email:
      type: string
    address:
      $ref: '#/components/schemas/PersonAddressResponse'
  discriminator:
    propertyName: personType
CompanyPersonInternalResponse:
  type: object
  allOf:
    - $ref: '#/components/schemas/BasePersonInternalResponse'
    - type: object
      properties:
        caenCode:
          type: string
        companyName:
          type: string
        companyType:
          type: string
IndividualPersonInternalResponse:
  type: object
  allOf:
    - $ref: '#/components/schemas/BasePersonInternalResponse'
    - type: object
      properties:
        firstName:
          type: string
        lastName:
          type: string
        identityDocumentNo:
          type: string
        identityDocumentSeries:
          type: string

Reproduction

Use the schemas that I've put in description combined like this:

   user:
      oneOf:
        - $ref: '#/components/schemas/OfferCompanyPersonInternalRequest'
        - $ref: '#/components/schemas/OfferIndividualPersonInternalRequest'

Expected result

personType should be of type string.

Required

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

Extra

@raduinsuretech raduinsuretech added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels May 12, 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