Skip to content

Bug: references to nested properties in schemas generate invalid types #1742

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

Closed
2 tasks done
avaly opened this issue Jul 4, 2024 · 0 comments · Fixed by #1743
Closed
2 tasks done

Bug: references to nested properties in schemas generate invalid types #1742

avaly opened this issue Jul 4, 2024 · 0 comments · Fixed by #1743
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@avaly
Copy link
Contributor

avaly commented Jul 4, 2024

Description

The generated types in a parameters entry which references a nested property from a schemas entry is generating an invalid type.

Name Version
openapi-typescript 7.0.1
Node.js 18.16.1
OS + version Ubuntu 22.04

Reproduction

Generate types for the following OpenAPI schema:

openapi: "3.0"
info:
  title: test
  version: "1.0"
servers:
  - url: https://example.com
security: []
paths:
  /endpoint:
    get:
      description: Test
      summary: Test
      parameters:
        - $ref: "#/components/parameters/direct"
        - $ref: "#/components/parameters/nested"
      responses:
        200:
          description: '200'
          content:
            application/json:
              schema:
                type: string
components:
  parameters:
    direct:
      in: query
      name: direct
      schema:
        $ref: "#/components/schemas/aaa"
    nested:
      in: query
      name: nested
      schema:
        $ref: "#/components/schemas/bbb/properties/ccc"
  schemas:
    aaa:
      type: string
    bbb:
      type: object
      properties:
        ccc:
          type: number

Expected result

export interface components {
    schemas: {
        aaa: string;
        bbb: {
            ccc?: number;
        };
    };
    responses: never;
    parameters: {
        direct: components["schemas"]["aaa"];
        nested: components["schemas"]["bbb"]["ccc"];
    };
    requestBodies: never;
    headers: never;
    pathItems: never;
}

Actual result

export interface components {
    schemas: {
        aaa: string;
        bbb: {
            ccc?: number;
        };
    };
    responses: never;
    parameters: {
        direct: components["schemas"]["aaa"];
        nested: components["schemas"]["bbb"]["properties"]["ccc"];
    };
    requestBodies: never;
    headers: never;
    pathItems: never;
}

Notice the extra ["properties"] here, which makes the type for the nested property invalid.

Checklist

@avaly avaly added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Jul 4, 2024
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

Successfully merging a pull request may close this issue.

1 participant