openapi2typescript
openapi2typescript copied to clipboard
当 swagger 文档中返回类型同时有定义 default 和 200 时,生成的方法返回类型是 default 中定义的
https://github.com/chenshuai2144/openapi2typescript/blob/74b11d5a6c8a46a6c10856920404ebe0b709076b/src/serviceGenerator.ts#L569-L578
问个问题哈,200 的优先级不是应该比 default 高吗,还是我理解错了
例如当我有个接口是这样定义的
"paths": {
"/v1/address/find_by_user_id": {
"get": {
"operationId": "Address_FindAddressByUserId",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/addressFindAddressByUserIdReply"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"tags": [
"Address"
]
}
}
},
最终生成的接口是这样
export async function AddressFindAddressByUserId(options?: { [key: string]: any }) {
return request<Api.rpcStatus>('/v1/address/find_by_user_id', {
method: 'GET',
...(options || {}),
});
}
200 的优先级应该比 default 高 @chenshuai2144
You can use the default response to describe these errors collectively, not individually. "Default" means this response is used for all HTTP codes that are not covered individually for this operation.
想问一下这个问题有打算处理的吗?
想问一下这个问题有打算处理的吗?
看起来是不会改了,可以自己sed一下.
package.json
{
"scripts": {
"openapi": "yarn fixed && umi openapi",
"fixed": "sed -i \"s/\\(responses.default || responses\\['200'\\]\\)/\\(responses\\['200'\\] || responses.default\\)/g\" node_modules/@umijs/openapi/dist/serviceGenerator.js"
}
}
我是另外写了 node 来改一下, 用 sed 看起来简洁点. (y)