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

Regression: OAS2 response examples are not displayed if response has no schema #6631

Closed
hkosova opened this issue Nov 17, 2020 · 4 comments · Fixed by #6641
Closed

Regression: OAS2 response examples are not displayed if response has no schema #6631

hkosova opened this issue Nov 17, 2020 · 4 comments · Fixed by #6641

Comments

@hkosova
Copy link
Contributor

hkosova commented Nov 17, 2020

Issue #5458 reappeared in v. 3.36.2.

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: Chrome, Firefox (latest)
  • Method of installation: https://editor.swagger.io
  • Swagger-UI version: 3.36.2
  • Swagger/OpenAPI version: 2.0

Content & configuration

Example Swagger/OpenAPI definition:

swagger: "2.0"
info:
  title: OAS2 response examples
  version: 1.0.0
produces:
  - application/json
paths:
  /foo1:
    get:
      summary: Response without a schema
      responses:
        200:
          description: Successful response
          examples:
            application/json:
              foo: custom value
  /foo2:
    get:
      summary: Response with schema
      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

v. 3.36.2 has a regression 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 GET ​/foo1 and GET /foo2 should display the same response example:

{
  "foo": "custom value"
}

Actual behavior

GET ​/foo1 does NOT display a response example. But if you add schema: {} to its /foo1's response then the example appears.

Workaround

Add a schema for responses that have examples. Even an empty schema schema: {} will work.

@tim-lai
Copy link
Contributor

tim-lai commented Nov 18, 2020

@hkosova I am unable to reproduce the issue as described with the provided definition. When loaded into editor.swagger.io, both endpoints display

{
  "foo": "custom value"
}

However, I do observe an issue of updating. If the example in/foo1 (without schema) is updated in the editor, swagger-ui does not re-render and display the updated value. However, the example in /foo2 does display the updated value.

@hkosova
Copy link
Contributor Author

hkosova commented Nov 18, 2020

@tim-lai you're right, it must have happened during editor updates. Is this a UI issue or editor issue then?


Steps to reproduce:

  1. Paste this spec into editor:
swagger: "2.0"
info:
  title: OAS2 response examples
  version: 1.0.0
produces:
  - application/json
paths:
  /foo1:
    get:
      summary: Response without a schema
      responses:
        200:
          description: Successful response

  /foo2:
    get:
      summary: Response with schema
      responses:
        200:
          description: Successful response
          schema: {}
          examples:
            application/json:
              foo: custom value
  1. In the UI panel, expand both operations.
  2. Copy examples (but not schema) from the second operation's response to the first operation's response.

Expected result: First operation should display newly added response example.

Actual result: Newly added example is not displayed.

@tim-lai
Copy link
Contributor

tim-lai commented Nov 18, 2020

Pretty sure this is a swagger-ui issue.

@tim-lai
Copy link
Contributor

tim-lai commented Nov 19, 2020

Yup, it's swagger-ui. I can see that the res value doesn't always reflect incoming arguments to memoizedSampleFromSchema.

const res = memoizedSampleFromSchema(schema, config, exampleOverride)

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

Successfully merging a pull request may close this issue.

2 participants