acacode / acacode/swagger-typescript-api

[route generation] multiple response type cases

Đang mở
#318 4 bình luận 3 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
4.1k
Fork
436
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

I've got a request the has 2 different return types: one on status 200 and another one on status 201

```
paths:
/hello:
get:
tags:
- "Hello Api"
operationId: sayHello

responses:
200:
schema:
$ref: "#/definitions/Hello"
201:
schema:
$ref: "#/definitions/User"
400:
$ref: "#/responses/400-BadRequest"
401:
$ref: "#/responses/401-Unauthorized"
404:
$ref: "#/responses/404-NotFound"
500:
$ref: "#/responses/500-InternalServerError"
default:
$ref: "#/responses/500-InternalServerError"
```

It generated me this namespace
```

export namespace Hello {
/**
* @tags Hello Api
* @name SayHello
* @request GET:/hello
* @response `200` `Hello`
* @response `201` `User`
* @response `400` `Error`
* @response `401` `Error`
* @response `404` `Error`
* @response `500` `Error`
* @response `default` `Error`
*/
export namespace SayHello {
export type RequestParams = {};
export type RequestQuery = {};
export type RequestBody = never;
export type RequestHeaders = {};
export type ResponseBody = Hello;
}
}
```

I think the correct response body is ```ResponseBody = Hello | User;``` as we cans return the 2 types

Also in case want to return an error, how is it supposed to work ? the error cases are only refered in @response decorator

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.