chenshuai2144 / openapi2typescript

一个被大范围使用的小工具
312 stars 136 forks source link

Get请求中如果query方式参数生成问题 #40

Closed darin-lao closed 1 year ago

darin-lao commented 2 years ago

你好,发现有一个问题, Get请求中如果query方式参数,如果operationId 生成的生typings.d.ts生在问题 下面是open api

{
  "openapi": "3.0.1",
  "info": {
    "title": "tcbj-store-open-api",
    "description": "",
    "version": "1.0.0"
  },
  "tags": [
    {
      "name": "commodityCenter"
    },
    {
      "name": "inventoryCenter"
    },
    {
      "name": "inventoryCenter/warehouseManage"
    },
    {
      "name": "inventoryCenter/warehouseManage/physical"
    },
    {
      "name": "inventoryCenter/warehouseManage/logic"
    }
  ],
  "paths": {
    "/inventoryCenter/warehouseManage/physical": {
      "get": {
        "summary": "物理仓列表",
        "x-apifox-folder": "inventoryCenter/warehouseManage/physical",
        "x-apifox-status": "designing",
        "deprecated": false,
        "description": "",
        "tags": ["inventoryCenter/warehouseManage/physical"],
        "parameters": [
          {
            "name": "pageSize",
            "in": "query",
            "description": "xx",
            "required": true,
            "style": "form",
            "explode": true,
            "example": "10",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "pageNum",
            "in": "query",
            "description": "xxx",
            "style": "form",
            "explode": true,
            "required": true,
            "example": "1",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "endRow": {
                          "type": "integer"
                        },
                        "hasNextPage": {
                          "type": "boolean"
                        },
                        "hasPreviousPage": {
                          "type": "boolean"
                        },
                        "isFirstPage": {
                          "type": "boolean"
                        },
                        "isLastPage": {
                          "type": "boolean"
                        },
                        "list": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/PhysicalItem"
                          }
                        },
                        "navigateFirstPage": {
                          "type": "integer"
                        },
                        "navigateLastPage": {
                          "type": "integer"
                        },
                        "navigatePages": {
                          "type": "integer"
                        },
                        "navigatepageNums": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "nextPage": {
                          "type": "integer"
                        },
                        "pageNum": {
                          "type": "integer"
                        },
                        "pageSize": {
                          "type": "integer"
                        },
                        "pages": {
                          "type": "integer"
                        },
                        "prePage": {
                          "type": "integer"
                        },
                        "size": {
                          "type": "integer"
                        },
                        "startRow": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        }
                      },
                      "required": [
                        "endRow",
                        "hasNextPage",
                        "hasPreviousPage",
                        "isFirstPage",
                        "isLastPage",
                        "list",
                        "navigateFirstPage",
                        "navigateLastPage",
                        "navigatePages",
                        "navigatepageNums",
                        "nextPage",
                        "pageNum",
                        "pageSize",
                        "pages",
                        "prePage",
                        "size",
                        "startRow",
                        "total"
                      ]
                    },
                    "exceptCauseApp": {
                      "type": "null"
                    },
                    "exceptCauseIp": {
                      "type": "null"
                    },
                    "exceptClass": {
                      "type": "null"
                    },
                    "extFields": {
                      "type": "object",
                      "properties": {}
                    },
                    "resultCode": {
                      "type": "string"
                    },
                    "resultMsg": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data",
                    "exceptCauseApp",
                    "exceptCauseIp",
                    "exceptClass",
                    "extFields",
                    "resultCode",
                    "resultMsg"
                  ]
                },
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "新建物理仓库",
        "x-apifox-folder": "inventoryCenter/warehouseManage/physical",
        "x-apifox-status": "designing",
        "deprecated": false,
        "description": "",
        "tags": ["inventoryCenter/warehouseManage/physical"],
        "parameters": [],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PhysicalItem"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "null"
                    },
                    "exceptCauseApp": {
                      "type": "string"
                    },
                    "exceptCauseIp": {
                      "type": "string"
                    },
                    "exceptClass": {
                      "type": "string"
                    },
                    "extFields": {
                      "type": "string"
                    },
                    "resultCode": {
                      "type": "integer"
                    },
                    "resultMsg": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data",
                    "exceptCauseApp",
                    "exceptCauseIp",
                    "exceptClass",
                    "extFields",
                    "resultCode",
                    "resultMsg"
                  ]
                },
                "examples": {}
              }
            }
          }
        }
      },
      "put": {
        "summary": "更新物理仓库",
        "x-apifox-folder": "inventoryCenter/warehouseManage/physical",
        "x-apifox-status": "designing",
        "deprecated": false,
        "description": "",
        "tags": ["inventoryCenter/warehouseManage/physical"],
        "parameters": [],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PhysicalItem"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {}
                    },
                    "exceptCauseApp": {
                      "type": "string"
                    },
                    "exceptCauseIp": {
                      "type": "string"
                    },
                    "exceptClass": {
                      "type": "string"
                    },
                    "extFields": {
                      "type": "object",
                      "properties": {}
                    },
                    "resultCode": {
                      "type": "integer"
                    },
                    "resultMsg": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data",
                    "exceptCauseApp",
                    "exceptCauseIp",
                    "exceptClass",
                    "extFields",
                    "resultCode",
                    "resultMsg"
                  ]
                },
                "examples": {}
              }
            }
          }
        }
      }
    },
    "/inventoryCenter/warehouseManage/logic": {
      "get": {
        "summary": "逻辑仓列表",
        "x-apifox-folder": "inventoryCenter/warehouseManage/logic",
        "x-apifox-status": "designing",
        "deprecated": false,
        "description": "",
        "tags": ["inventoryCenter/warehouseManage/logic"],
        "parameters": [
          {
            "name": "pageSize",
            "in": "query",
            "description": "",
            "required": true,
            "example": "20",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "currentPage",
            "in": "query",
            "description": "",
            "required": true,
            "example": "1",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "endRow": {
                          "type": "integer"
                        },
                        "hasNextPage": {
                          "type": "boolean"
                        },
                        "hasPreviousPage": {
                          "type": "boolean"
                        },
                        "isFirstPage": {
                          "type": "boolean"
                        },
                        "isLastPage": {
                          "type": "boolean"
                        },
                        "list": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "properties": {
                              "brandFactory": {
                                "type": "string"
                              },
                              "channelType": {
                                "type": "string"
                              },
                              "channelTypeStr": {
                                "type": "string"
                              },
                              "realWarehouseCode": {
                                "type": "integer"
                              },
                              "createTime": {
                                "type": "string"
                              },
                              "modifyTime": {
                                "type": "string"
                              },
                              "id": {
                                "type": "string"
                              },
                              "modifyUserId": {
                                "type": "string"
                              },
                              "createUserId": {
                                "type": "string"
                              },
                              "modifyUserName": {
                                "type": "string"
                              },
                              "realWarehouseName": {
                                "type": "string"
                              },
                              "realWarehouseStatus": {
                                "type": "integer"
                              },
                              "realWarehouseStatusName": {
                                "type": "string"
                              },
                              "realWarehouseTypeName": {
                                "type": "string"
                              },
                              "stockTagName": {
                                "type": "string"
                              },
                              "realWarehouseType": {
                                "type": "string"
                              },
                              "storageLocation": {
                                "type": "string"
                              },
                              "tag": {
                                "type": "string"
                              },
                              "tagName": {
                                "type": "string"
                              }
                            }
                          }
                        },
                        "navigateFirstPage": {
                          "type": "integer"
                        },
                        "navigateLastPage": {
                          "type": "integer"
                        },
                        "navigatePages": {
                          "type": "integer"
                        },
                        "navigatepageNums": {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        },
                        "nextPage": {
                          "type": "integer"
                        },
                        "pageNum": {
                          "type": "integer"
                        },
                        "pageSize": {
                          "type": "integer"
                        },
                        "pages": {
                          "type": "integer"
                        },
                        "prePage": {
                          "type": "integer"
                        },
                        "size": {
                          "type": "integer"
                        },
                        "startRow": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        }
                      },
                      "required": [
                        "endRow",
                        "hasNextPage",
                        "hasPreviousPage",
                        "isFirstPage",
                        "isLastPage",
                        "list",
                        "navigateFirstPage",
                        "navigateLastPage",
                        "navigatePages",
                        "navigatepageNums",
                        "nextPage",
                        "pageNum",
                        "pageSize",
                        "pages",
                        "prePage",
                        "size",
                        "startRow",
                        "total"
                      ]
                    },
                    "exceptCauseApp": {
                      "type": "null"
                    },
                    "exceptCauseIp": {
                      "type": "null"
                    },
                    "exceptClass": {
                      "type": "null"
                    },
                    "extFields": {
                      "type": "null"
                    },
                    "resultCode": {
                      "type": "string"
                    },
                    "resultMsg": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data",
                    "exceptCauseApp",
                    "exceptCauseIp",
                    "exceptClass",
                    "extFields",
                    "resultCode",
                    "resultMsg"
                  ]
                },
                "examples": {
                  "1": {
                    "summary": "示例",
                    "value": "{\r\n    \"data\": {\r\n        \"endRow\": 96,\r\n        \"hasNextPage\": false,\r\n        \"hasPreviousPage\": true,\r\n        \"isFirstPage\": false,\r\n        \"isLastPage\": false,\r\n        \"list\": [\r\n            {\r\n                \"brandFactory\": \"6056\",\r\n                \"channelType\": \"20\",\r\n                \"channelTypeStr\": \"联营\",\r\n                \"realWarehouseCode\": 60561000,\r\n                \"createTime\": \"2013-07-14 17:07:11\",\r\n                \"modifyTime\": \"2010-01-11 09:46:03\",\r\n                \"id\": \"65\",\r\n                \"modifyUserId\": \"43\",\r\n                \"createUserId\": \"30\",\r\n                \"modifyUserName\": \"管理员\",\r\n                \"realWarehouseName\": \"贵阳杉杉奥特莱斯K\",\r\n                \"realWarehouseStatus\": 1,\r\n                \"realWarehouseStatusName\": \"启用\",\r\n                \"realWarehouseTypeName\": \"联营门店A版-商场回款\",\r\n                \"stockTagName\": \"联营门店仓\",\r\n                \"realWarehouseType\": \"12\",\r\n                \"storageLocation\": \"1000\",\r\n                \"tag\": \"店\",\r\n                \"tagName\": \"D\",\r\n            }\r\n        ],\r\n        \"navigateFirstPage\": 24,\r\n        \"navigateLastPage\": 93,\r\n        \"navigatePages\": 79,\r\n        \"navigatepageNums\": [\r\n            \"53\",\r\n            \"61\",\r\n            \"93\",\r\n            \"68\",\r\n            \"36\"\r\n        ],\r\n        \"nextPage\": 92,\r\n        \"pageNum\": 35,\r\n        \"pageSize\": 96,\r\n        \"pages\": 46,\r\n        \"prePage\": 6,\r\n        \"size\": 65,\r\n        \"startRow\": 55,\r\n        \"total\": 14\r\n    },\r\n    \"exceptCauseApp\": null,\r\n    \"exceptCauseIp\": null,\r\n    \"exceptClass\": null,\r\n    \"extFields\": null,\r\n    \"resultCode\": \"82\",\r\n    \"resultMsg\": \"magna sit\"\r\n}"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/inventoryCenter/warehouseManage/physical/{id}": {
      "get": {
        "summary": "查询物理仓库详情",
        "x-apifox-folder": "inventoryCenter/warehouseManage/physical",
        "x-apifox-status": "designing",
        "deprecated": false,
        "description": "",
        "operationId": "getPhysicalById",
        "tags": ["inventoryCenter/warehouseManage/physical"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {}
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "成功",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PhysicalItem"
                    },
                    "exceptCauseApp": {
                      "type": "string"
                    },
                    "exceptCauseIp": {
                      "type": "string"
                    },
                    "exceptClass": {
                      "type": "string"
                    },
                    "extFields": {
                      "type": "object",
                      "properties": {}
                    },
                    "resultCode": {
                      "type": "string"
                    },
                    "resultMsg": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "data",
                    "exceptCauseApp",
                    "exceptCauseIp",
                    "exceptClass",
                    "extFields",
                    "resultCode",
                    "resultMsg"
                  ]
                },
                "examples": {}
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "PhysicalItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "physicalWarehouseCode": {
            "type": "string"
          },
          "physicalWarehouseName": {
            "type": "string"
          },
          "physicalWarehouseType": {
            "type": "string"
          },
          "physicalWarehouseStatus": {
            "type": "string",
            "enum": ["NW", "NE", "SW", "SE"]
          },
          "createUserId": {
            "type": "string"
          },
          "createUserName": {
            "type": "string"
          },
          "createTime": {
            "type": "string"
          },
          "modifyUserId": {
            "type": "string"
          },
          "modifyUserName": {
            "type": "string"
          },
          "modifyTime": {
            "type": "string"
          }
        },
        "required": [
          "physicalWarehouseCode",
          "physicalWarehouseName",
          "physicalWarehouseType",
          "physicalWarehouseStatus"
        ],
        "x-apifox-folder": "inventoryCenter/warehouseManage"
      },
      "CommonListPage": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "endRow": {
                "type": "integer"
              },
              "hasNextPage": {
                "type": "boolean"
              },
              "hasPreviousPage": {
                "type": "boolean"
              },
              "isFirstPage": {
                "type": "boolean"
              },
              "isLastPage": {
                "type": "boolean"
              },
              "list": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {}
                }
              },
              "navigateFirstPage": {
                "type": "integer"
              },
              "navigateLastPage": {
                "type": "integer"
              },
              "navigatePages": {
                "type": "integer"
              },
              "navigatepageNums": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "nextPage": {
                "type": "integer"
              },
              "pageNum": {
                "type": "integer"
              },
              "pageSize": {
                "type": "integer"
              },
              "pages": {
                "type": "integer"
              },
              "prePage": {
                "type": "integer"
              },
              "size": {
                "type": "integer"
              },
              "startRow": {
                "type": "integer"
              },
              "total": {
                "type": "integer"
              }
            },
            "required": [
              "endRow",
              "hasNextPage",
              "hasPreviousPage",
              "isFirstPage",
              "isLastPage",
              "list",
              "navigateFirstPage",
              "navigateLastPage",
              "navigatePages",
              "navigatepageNums",
              "nextPage",
              "pageNum",
              "pageSize",
              "pages",
              "prePage",
              "size",
              "startRow",
              "total"
            ]
          },
          "exceptCauseApp": {
            "type": "string"
          },
          "exceptCauseIp": {
            "type": "string"
          },
          "exceptClass": {
            "type": "string"
          },
          "extFields": {
            "type": "object",
            "properties": {}
          },
          "resultCode": {
            "type": "string"
          },
          "resultMsg": {
            "type": "string"
          }
        },
        "required": [
          "data",
          "exceptCauseApp",
          "exceptCauseIp",
          "exceptClass",
          "extFields",
          "resultCode",
          "resultMsg"
        ],
        "x-apifox-folder": "Common"
      },
      "CommonResponse": {
        "type": "object",
        "properties": {
          "data": {
            "type": "string"
          },
          "exceptCauseApp": {
            "type": "string"
          },
          "exceptCauseIp": {
            "type": "string"
          },
          "exceptClass": {
            "type": "string"
          },
          "extFields": {
            "type": "object",
            "properties": {}
          },
          "resultCode": {
            "type": "string"
          },
          "resultMsg": {
            "type": "string"
          }
        },
        "required": [
          "data",
          "exceptCauseApp",
          "exceptCauseIp",
          "exceptClass",
          "extFields",
          "resultCode",
          "resultMsg"
        ],
        "x-apifox-folder": "Common"
      }
    }
  }
}

生成的typings.d.ts 其中,undefinedParams

declare namespace API {
  type PhysicalItem = {
    id?: string;
    physicalWarehouseCode: string;
    physicalWarehouseName: string;
    physicalWarehouseType: string;
    physicalWarehouseStatus: 'NW' | 'NE' | 'SW' | 'SE';
    createUserId?: string;
    createUserName?: string;
    createTime?: string;
    modifyUserId?: string;
    modifyUserName?: string;
    modifyTime?: string;
  };

  type CommonListPage = {
    data: {
      endRow?: number;
      hasNextPage?: boolean;
      hasPreviousPage?: boolean;
      isFirstPage?: boolean;
      isLastPage?: boolean;
      list?: Record<string, any>[];
      navigateFirstPage?: number;
      navigateLastPage?: number;
      navigatePages?: number;
      navigatepageNums?: string[];
      nextPage?: number;
      pageNum?: number;
      pageSize?: number;
      pages?: number;
      prePage?: number;
      size?: number;
      startRow?: number;
      total?: number;
    };
    exceptCauseApp: string;
    exceptCauseIp: string;
    exceptClass: string;
    extFields: Record<string, any>;
    resultCode: string;
    resultMsg: string;
  };

  type CommonResponse = {
    data: string;
    exceptCauseApp: string;
    exceptCauseIp: string;
    exceptClass: string;
    extFields: Record<string, any>;
    resultCode: string;
    resultMsg: string;
  };

  type undefinedParams = {
    /** xx */
    pageSize: string;
    /** xxx */
    pageNum: string;
  };

  type undefinedParams = {
    pageSize: string;
    currentPage: string;
  };

  type getPhysicalByIdParams = {
    id: string;
  };
}

生成了两个undefinedParams ,Api引用param无引用正常生成,需要处理无operationId属性情况下生成声明参数跟生成接口层命名一样

image

XuJin186 commented 2 years ago

一模一样的问题

chenshuai2144 commented 2 years ago

欢迎pr

BruceYe2020 commented 2 years ago

提交了一个PR

XuJin186 commented 2 years ago

提交了一个PR

@chenshuai2144 既然有pr了 麻烦发布一个版本吧

scrapstation commented 2 years ago

@BruceYe2020 @chenshuai2144 这个pr #51 会导致customTypeName不生效