Skip to content

Regression: OAS2 response examples are not displayed #5458

@hkosova

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

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