Skip to content
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

Support response examples for alternative media types #4500

Closed
simonoakesepimorphics opened this issue May 1, 2018 · 2 comments
Closed

Support response examples for alternative media types #4500

simonoakesepimorphics opened this issue May 1, 2018 · 2 comments

Comments

@simonoakesepimorphics
Copy link

I'm not totally sure if this is a bug or a feature request, but I think the behaviour is in conflict with the OpenAPI Specification so I have labelled it as a bug. I hope you'll correct me if I'm wrong.

I would like to be able to document an API endpoint which responds with text/csv format by providing an example response. Currently it is possible to specify an example of a media type on an API response object (OpenAPI spec), however this is not rendered in the Swagger UI. The description of the property in the specification implies that this example should have precedence over any others, so I would expect it to be visible whether there is an example specified for the response schema or not.

The specification says:

Example of the media type. The example object SHOULD be in the correct format as specified by the media type. The example field is mutually exclusive of the examples field. Furthermore, if referencing a schema which contains an example, the example value SHALL override the example provided by the schema.

As a workaround I have tried associating the example with the response schema, which does appear on the UI. However this isn't an adequate solution for my particular case. When the example property is given in this way, new lines are rendered as \n, and the text is enclosed in quotes. This is inappropriate for specifying examples in CSV format.

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 3.0.1
Which Swagger-UI version? 3.13.6
How did you install Swagger-UI? Using maven: org.webjars.swagger-ui.3.13.6
Which browser & version? Chrome 65.0.3325.181
Which operating system? Mac OS High Sierra 10.13.4
openapi: 3.0.1
info:
  title: Demo App
  description: |
    Swagger UI response example
  version: '0.1'
paths:
  /example:
    description: Example
    get:
      description: Example GET
      responses:
        '200':
          description: Success
          content:
            text/csv:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        label:
                          type: string
                        type:
                          type: string
                example: |-
                  type, label
                  type A, name A
              example: |-
                type, label
                type B, name B

Replicated on Swagger Editor (https://editor.swagger.io/)

Expected Behavior

  • Media type example should override schema example
  • New lines should be represented in the example value
  • Example value should not be enclosed in quotes

Current Behavior

  • Media type example is not visible
  • New lines are respresented as \n
  • Example value is enclosed in quotes
@webron
Copy link
Contributor

webron commented May 2, 2018

Thanks - we qualify this as a feature and not a bug, because it was never implemented. See #3437.

@webron webron closed this as completed May 2, 2018
@lock
Copy link

lock bot commented Jul 2, 2019

Locking due to inactivity.

This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.

If you think you're experiencing something similar to what you've found here: please open a new issue, follow the template, and reference this issue in your report.

Thanks!

@lock lock bot locked and limited conversation to collaborators Jul 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants