Skip to content

Add 'produces' at response level #660

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

Closed
dolmen opened this issue Apr 19, 2016 · 8 comments
Closed

Add 'produces' at response level #660

dolmen opened this issue Apr 19, 2016 · 8 comments

Comments

@dolmen
Copy link

dolmen commented Apr 19, 2016

In Swagger 2.0 produces is defined at the operation level and applies to all responses. This forbid to uses different MIME types for different responses and to use for example a specific MIME type for errors, as proposed in RFC 7807 ("Problem Details for HTTP APIs", published in March 2016).

@ePaul
Copy link
Contributor

ePaul commented Apr 19, 2016

While this is true, the proposed solution would go too short – we also need to allow responses with the same response code, but differing in produces MIME type (and result schema). (This relates to #146.)

@DavidBiesack
Copy link
Contributor

👍 to what @ePaul wrote - our 200 responses return different representations based on Accept headers; others want different representations based on other (query) parameters, etc.

@webron
Copy link
Member

webron commented Apr 19, 2016

How is this different than #146?

@ePaul
Copy link
Contributor

ePaul commented Apr 20, 2016

@webron As I understand the original request, this just wants to add a produces field to each response, e.g. for explaining that a 4xx response returns application/problem+json while 200 is returning application/my-object+json. (This currently can only be expressed in a description.)

#146 (and my comment) needs e.g. to allow having several 200 responses which differ by its produces property.

@dolmen
Copy link
Author

dolmen commented Oct 5, 2016

Here is my use case to clarify my request. I'm implementing streaming operation using Server-Sent-Events (see #396).

  • The response with status 200 will produce text/event-stream.
  • Others responses are errors and are sent as application/json.

The spec should include enough information to be used to build a client that will send Accept: text/event-stream, application/json but expect only Content-Type: text/event-stream for status 200 and only Content-Type: application/json for other status.

Here is how that would be specified in the Operation object:

produces:
- text/event-stream
- application/json
responses:
  '200':
    description: Stream is starting
    produces: ["text/event-stream"]
  default:
    # has produces: ["application/json"]
    $ref: '#/responses/DefaultError'

The Accept header sent by the client would be built by selecting at least one MIME type from the produces of each possible response.

The existing spec is only meant to allow the client to choose the MIME type for all responses of an operation just to select the serialisation format between application/xml or application/json. This does not fit my use case.

@fehguy
Copy link
Contributor

fehguy commented Oct 5, 2016

@dolmen please look at the solution that was accepted by the TDC:

#761

@dolmen
Copy link
Author

dolmen commented Oct 5, 2016

In fact, there is already a way to declare produces at responses level by adding a header constraint for Content-Type:

responses:
  '200':
    description: Stream is starting
    headers:
      'Content-Type':
        type: string
        enum: ["text/event-stream"]

(but unfortunately swagger-ui doesn't (yet) shows the enum)

@webron
Copy link
Member

webron commented Mar 3, 2017

With the new Response Object's content you can specify specific. consumes and produces have been removed entirely.

@webron webron closed this as completed Mar 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants