Avoid autogenerated response status in Controllers
See original GitHub issueSorting
-
I’m submitting a …
- bug report
- feature request
- support request
-
I confirm that I
- used the search to make sure that a similar issue hasn’t already been submit
Expected Behavior
Hi! First of all, congrats for this great project
I have a little problem with the infered response status (and response object):
All my Controllers entry-point are void
methods that can return a variety of responses (200 with content, 204 without content, 400 with error message…)
When a use annotations with some endpoint that return a response, tsoa
infers automatically that, being a void
method, the status code is 204 with no-content, even if I use the annotation @Response<MyResponse>(200, ‘some description’)
This is an example of my controller
@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);
}
Current Behavior
With this code, currently tsoa
generate two kind of responses instead of one (this is the swagger.json generated):
"paths": {
"/user": {
"get": {
"operationId": "Execute",
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserGetResponse"
}
}
}
},
"204": {
"description": "No content"
}
},
"tags": [
"User"
],
"security": [],
"parameters": []
}
}
},
Possible Solution
I would like to find a way to ignore or override the inferred response (the status code 204 in my case) but I couldn’t find anything in the Docs or the examples ¿It’s possible?
Context (Environment)
Version of the library: 4.1.2 Version of NodeJS: 16 Version of Express: 4.17.0
- Confirm you were using yarn not npm
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top GitHub Comments
Hello there pabloleonalcaide 👋
Thank you for opening your very first issue in this project.
We will try to get back to you as soon as we can.👀
I’m running into the same issue, I’m trying to use tsoa to generate openapi documentation for an API, but I’m not using the runtime tsoa functionality. I’ve got methods that conform to
(input: In) => Success | SomeError | NotFound
, and I’ve decorated it withThis almost does what I need it to, except it generates an extra 200 Ok response in the documentation which I don’t want.