typescript-rest-swagger
typescript-rest-swagger copied to clipboard
Consumes value should not read @Accept
Issue
The consumes property on a generated method should not be populated by reading the @Accept decorator. Accept header is the media type allowed by the client in responses, and the @Accept decorator is used by the service to determine the media type of responses.
Proposal
I propose consumes be changed to read the value of a new @Consumes decorator to match the current @Produces. Additionally, we could be smart about this and read the type property of @BodyOptions options if specified. If that value is a string, use it as the value of consumes. In case both decorators are specified, @Consumes should take precedence as an explicitly declared value. Similarly, we should read the value of @Accept to determine the produces property if @Produces is not specified.
(I'd be happy to code this up. Just seeking input here.)
Any thoughts on this, @thiagobustamante ?
Hi @ngraef ,
Sorry for the late response. I totally agree with the proposal.
Hi guys, any update on this issue? I just ran into it recently. I might summit a patch if you haven't worked on that yet.
And IMO, it's better to make the fix in 2 repos:
- In typescript-rest:
- added
@Consumesto define MIME type that can be handled by the server. - compare the values in Content-Type headers and return 415 if not matched (like 406 which is already done for
@Accept)
- In typescript-rest-swagger:
- mark
@Producesas deprecated - generate swagger consumes from
@Consumes - generate swagger produces from
@Accept - to keep compatibily: in case of no
@Accept, we generate produces from@Producesif defined
But I'm totally fine with the original proposal which takes less effort to implement
Hey guys, any news for the PR? Do not hesitate if I need to rework it.