Skip to content

[@spec2ts/openapi] [bug] schema with "oneOf" keyword ignores "properties" keyword #4

@marcogrcr

Description

@marcogrcr

I encountered a bug when attempting to generate types for the following JSON schema:

openapi: 3.0.3
info:
  title: example
  version: 1.0.0
paths:
  /example:
    get:
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  name:
                    type: string
                  value:
                    type: integer
                oneOf:
                  - properties:
                      value:
                        minimum: 0
                        maximum: 5
                  - properties:
                      value:
                        minimum: 10
                        maximum: 15

Expected result:

The library detects that there's an overlap between the properties names of $.oneOf and $.properties and generates a type that satisfies all specifications:

export interface GetExampleResponse {
    name?: string;
    value?: number;
}

Actual result:

The library ignores $.properties when $.oneOf is present. It also does not detect there's an overlap between the elements of the $.oneOf array and generates a type union that's redundant.

export type GetExampleResponse = {
    value?: any;
} | {
    value?: any;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions