-
Notifications
You must be signed in to change notification settings - Fork 475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mechanism to avoid controller state and duplicating success annotations #723
Comments
I think the idea is good, but I'd rather approach it in a different way. Not using the default type annotation for the default response woud be a major change and in fact one that would hurt a lot of existing users. Instead, I'd suggest we promote the Would you generally be interested in implementing this? |
Would promoting |
Would probably be a breaking change, yes. |
Sorting
I'm submitting a ...
I confirm that I
Expected Behavior
I can write handlers without storing request state on the controller, i.e. without the
.getStatus
/.setStatus
methods, and without duplicating information in annotations.Current Behavior
If I use
@SuccessResponse
to describe the result of a handler, I still need to create a status state on the controller andsetStatus
/getStatus
/getHeaders
methods to have responses actually return the correct status code. To avoid having to add stateful (and possibly concurrency-unsafe) methods to a controller, I've instead opted to use the@Res
decorator for all responses, including the final return.e.g.
However, doing this still produces a default success response in the spec:
To eliminate the extra response, I need to duplicate the success case in the annotations:
Possible Solution
If the default response code in the generated template was derived from the success response annotation, I wouldn't need the
@Res
callback, and regular return would work fine. I don't know what happens if there's multipleSuccessResponse
annotations though - maybe this could cause tsoa to error out?Another alternative would be to avoid the default response being generated, although that raises the question of what the generated code should do when no response callback was called. Maybe generate an internal error?
Context (Environment)
Version of the library: 3.1.0
Version of NodeJS: 10.19
The text was updated successfully, but these errors were encountered: