I'm using TSOA to auto-generate a swagger.json
file which will be rendered with swagger-ui-express
The problem is that, although the endpoint really returns a status code 200 and a response object, TSOA is interpreting that the execute()
method does not return anything (void
) and ends up indicating that in addition to returning a 200, it can also return a 204-NoContent
Is there a way to specify TSOA or Swagger to ignore this response possibility?
The Controller:
@Controller()
@Route('/user')
@Tags('User')
export class UserGetController extends BaseController<UserGetResponse> {
@Get()
@Response<UserGetResponse>(200)
public async execute(): Promise<void> {
this.sendResponse(UserGetController.toResponse({user: undefined}));
}
}
protected sendResponse(params: Record<string, unknown>, statusCode?: number): void {
this.response.status(statusCode || 200).json(params);
}
The generated code in swagger.json
file:
"paths": {
"/user": {
"get": {
"operationId": "Execute",
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserGetResponse"
}
}
}
},
"204": {
"description": "No content"
}
},
"tags": [
"User"
],
"security": [],
"parameters": []
}
}
},