Skip to content

Regression: OAS2 response examples are not displayed #5458

Description

@hkosova

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: any
  • Method of installation: https://editor.swagger.io
  • Swagger-UI version: 3.23.0
  • Swagger/OpenAPI version: OpenAPI 2.0

Content & configuration

Example Swagger/OpenAPI definition:

swagger: "2.0"
info:
  title: test
  version: 1.0.0
paths:
  /foo1:
    get:
      summary: Response without a schema
      produces:
        - application/json
      responses:
        200:
          description: Successful response
          examples:
            application/json:
              foo: custom value
  /foo2:
    get:
      summary: Response with schema
      produces:
        - application/json
      responses:
        200:
          description: Successful response
          schema:
            $ref: '#/definitions/Foo'
          examples:
            application/json:
              foo: custom value

definitions:
  Foo:
    type: object
    properties:
      foo:
        type: string
        example: bar

Describe the bug you're encountering

/pull/5427 seems to have introduced an issue where OAS2 response examples are not displayed if the response does not have a schema defined. Previous versions of Swagger UI rendered the response examples in this case.

Expected behavior

Both /foo1 and /foo2 display the following response example, as it was in Swagger UI v. 3.22.3:

{
  "foo": "custom value"
}

Response example in Swagger UI

Actual behavior

/foo1 does not display any example.
/foo2 displays schema-based example instead of the custom example from examples.

Wrong response examples

Activity

  1. changed the title [-]Regression: OAS2 response examples are not displayed if the response does not have schema[/-] [+]Regression: OAS2 response examples are not displayed[/+] on Jul 12, 2019
  2. shockey commented on Jul 13, 2019

    @shockey
    Contributor

    (P1 in order to push this above #5453 and #5455)

  3. shockey commented on Jul 13, 2019

    @shockey
    Contributor

    thanks as always @hkosova!

  4. shockey commented on Jul 13, 2019

    @shockey
    Contributor

    wait a second

    My implementation missed the mark, it's generating custom value instead of the entire object.

    Reopening.

  5. shockey commented on Jul 13, 2019

    @shockey
    Contributor

    :shipit:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions