Skip to content

Incorrect TypeScript Type Generation for OpenAPI allOf and oneOf Combinations #251

@mpyw

Description

@mpyw

Description

openapi2aspida seems to incorrectly transform OpenAPI schemas using allOf and oneOf. The issue is with combining common properties (defined with allOf) and selective properties (defined with oneOf) in TypeScript type.

OpenAPI Spec

MyObject:
  type: object
  allOf:
    - type: object
      properties:
        commonProperty:
          type: string
      required:
        - commonProperty
    - type: object
      oneOf:
        - type: object
          properties:
            optionA:
              type: string
          required:
            - optionA
        - type: object
          properties:
            optionB:
              type: number
          required:
            - optionB

Expected Output

export type MyObject = {
  commonProperty: string;
} & (
  | {
      optionA: string;
    }
  | {
      optionB: number;
    }
);

Actual Output

export type MyObject = {
  commonProperty: string;
} & {
  optionA: string;
} | {
  optionB: number;
};

Environment

  • Package version: v0.23.2
  • OS: macOS
  • Node.js version: 20.6.1
  • npm version: 9.8.1

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions