typescript-rest-swagger icon indicating copy to clipboard operation
typescript-rest-swagger copied to clipboard

Consumes value should not read @Accept

Open ngraef opened this issue 7 years ago • 4 comments

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.)

ngraef avatar Feb 09 '18 01:02 ngraef

Any thoughts on this, @thiagobustamante ?

ngraef avatar Feb 13 '18 04:02 ngraef

Hi @ngraef ,

Sorry for the late response. I totally agree with the proposal.

thiagobustamante avatar Feb 14 '18 12:02 thiagobustamante

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:

  1. In typescript-rest:
  • added @Consumes to 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)
  1. In typescript-rest-swagger:
  • mark @Produces as deprecated
  • generate swagger consumes from @Consumes
  • generate swagger produces from @Accept
  • to keep compatibily: in case of no @Accept, we generate produces from @Produces if defined

But I'm totally fine with the original proposal which takes less effort to implement

Insalien avatar Jun 21 '19 08:06 Insalien

Hey guys, any news for the PR? Do not hesitate if I need to rework it.

Insalien avatar Aug 07 '19 08:08 Insalien