Skip to content

use openapiTS and astToString generate file type error in V7 #1483

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
liangskyli opened this issue Dec 13, 2023 · 1 comment · Fixed by #1489
Closed
2 tasks

use openapiTS and astToString generate file type error in V7 #1483

liangskyli opened this issue Dec 13, 2023 · 1 comment · Fixed by #1489
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@liangskyli
Copy link
Contributor

liangskyli commented Dec 13, 2023

Description

generate file type error

code generate

const result = await openapiTS(this.schema, openAPITSOptions);
const schemaString = `${astToString(result)}`;

openapi.json

{
  "openapi": "3.1.0",
  "info": {
    "title": "test",
    "license": {
      "name": "test"
    },
    "version": "0.4.1"
  },
  "tags": [
    {
      "name": "Test1",
      "description": ""
    }
  ],
  "paths": {
    "/root/v1/getQueryParams2": {
      "get": {
        "tags": ["Test1"],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "number",
                      "description": "接口返回code码字段"
                    },
                    "data": {
                      "$ref": "#/components/schemas/commonResponse.2e0063f8"
                    },
                    "msg": {
                      "type": "string",
                      "description": "接口返回信息字段"
                    }
                  },
                  "required": ["code", "data"]
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "inlineQueryParam5",
            "in": "query",
            "required": true,
            "schema": {
              "items": [
                {
                  "type": "string"
                },
                {
                  "type": "boolean"
                }
              ],
              "type": "array",
              "maxItems": 2,
              "minItems": 2
            }
          },
          {
            "name": "inlineQueryParam6",
            "in": "query",
            "required": true,
            "schema": {
              "type": "array",
              "items": {
                "items": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "boolean"
                  }
                ],
                "type": "array",
                "maxItems": 2,
                "minItems": 2
              }
            }
          },
          {
            "name": "inlineQueryParam7",
            "in": "query",
            "required": true,
            "schema": {
              "type": "array",
              "items": {
                "items": [
                  {
                    "items": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "boolean"
                      }
                    ],
                    "type": "array",
                    "maxItems": 2,
                    "minItems": 2
                  },
                  {
                    "type": "number"
                  }
                ],
                "type": "array",
                "maxItems": 2,
                "minItems": 2
              }
            }
          }
        ]
      }
    }
  },
  "components": {
    "schemas": {
      "commonResponse.2e0063f8": {
        "type": "object",
        "properties": {
          "a": {
            "type": "string"
          }
        },
        "required": ["a"]
      }
    }
  }
}
Name Version
openapi-typescript 7.0.0-next.5
Node.js x.x.x
OS + version macOS 13, Windows 11, etc.

Reproduction

generate error:


export interface paths {
  '/root/v1/getQueryParams2': {
    parameters: {
      query?: never;
      header?: never;
      path?: never;
      cookie?: never;
    };
    get: {
      parameters: {
        query: {
          inlineQueryParam5: [string, boolean];
          inlineQueryParam6: [string, boolean];
          inlineQueryParam7: [[string, boolean], number];
        };
        header?: never;
        path?: never;
        cookie?: never;
      };
      requestBody?: never;
      responses: {
        /** @description Success */
        200: {
          headers: {
            [name: string]: unknown;
          };
          content: {
            'application/json': {
              /** @description 接口返回code码字段 */
              code: number;
              data: components['schemas']['commonResponse.2e0063f8'];
              /** @description 接口返回信息字段 */
              msg?: string;
            };
          };
        };
      };
    };
    put?: never;
    post?: never;
    delete?: never;
    options?: never;
    head?: never;
    patch?: never;
    trace?: never;
  };
}
export type webhooks = Record<string, never>;
export interface components {
  schemas: {
    'commonResponse.2e0063f8': {
      a: string;
    };
  };
  responses: never;
  parameters: never;
  requestBodies: never;
  headers: never;
  pathItems: never;
}
export type $defs = Record<string, never>;
export type operations = Record<string, never>;

inlineQueryParam6 , inlineQueryParam7 type generater error!
should generater:
inlineQueryParam6: [string, boolean][];
inlineQueryParam7: [[string, boolean], number][];
when use V6 generator is ok!

Expected result

/**
 * This file was auto-generated by @liangskyli/openapi-gen-ts.
 * Do not make direct changes to the file.
 */

export interface paths {
  '/root/v1/getQueryParams2': {
    parameters: {
      query?: never;
      header?: never;
      path?: never;
      cookie?: never;
    };
    get: {
      parameters: {
        query: {
          inlineQueryParam5: [string, boolean];
          inlineQueryParam6: [string, boolean][];
          inlineQueryParam7: [[string, boolean], number][];
        };
        header?: never;
        path?: never;
        cookie?: never;
      };
      requestBody?: never;
      responses: {
        /** @description Success */
        200: {
          headers: {
            [name: string]: unknown;
          };
          content: {
            'application/json': {
              /** @description 接口返回code码字段 */
              code: number;
              data: components['schemas']['commonResponse.2e0063f8'];
              /** @description 接口返回信息字段 */
              msg?: string;
            };
          };
        };
      };
    };
    put?: never;
    post?: never;
    delete?: never;
    options?: never;
    head?: never;
    patch?: never;
    trace?: never;
  };
}
export type webhooks = Record<string, never>;
export interface components {
  schemas: {
    'commonResponse.2e0063f8': {
      a: string;
    };
  };
  responses: never;
  parameters: never;
  requestBodies: never;
  headers: never;
  pathItems: never;
}
export type $defs = Record<string, never>;
export type operations = Record<string, never>;

(in case it’s not obvious)

Checklist

@liangskyli liangskyli added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Dec 13, 2023
@drwpow
Copy link
Contributor

drwpow commented Dec 14, 2023

Great bug report, thank you! Will fix.

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
2 participants