swagger-editor icon indicating copy to clipboard operation
swagger-editor copied to clipboard

Response example is sometimes replaced with "(no example available)" after re-rendering

Open hkosova opened this issue 3 years ago • 3 comments

Q&A (please complete the following information)

  • OS: Windows 10
  • Browser: Chrome latest
  • Method of installation: https://editor.swagger.io
  • Swagger-Editor version: 3.15.10
  • OpenAPI version: 2.0. I didn't test 3.0 but it might be affected too.

Content & configuration

swagger: '2.0'
info:
  title: test
  version: 1.0.0
produces:
  - application/json
paths:
  /foo:
    get:
      responses:
        '404':
          $ref: '#/responses/NotFound'
    post:
      responses:
        '404':
          $ref: '#/responses/NotFound'
responses:
  NotFound:
    description: Not Found
    schema:
      $ref: '#/definitions/error404'
definitions:
  error404:
    description: Error 404
    allOf:
      - $ref: '#/definitions/error'
  error:
    type: object
    properties:
      code:
        type: integer
      message:
        type: string

Describe the bug you're encountering

When operations are expanded in the UI panel, editing the spec can result in some response example disappearing and being replaced "(no example available)". See the GIF below.

I only checked OAS response schema examples but it's possible that the same issue affects OAS2 body param examples and OAS3 requestBody & parameter examples.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io and paste the YAML provided above.
  2. Expand both operations in the UI panel. Note that both operations show response examples.
  3. Scroll the UI so that both response examples are visible.
  4. In the editor, make some changes to the YAML. E.g. append some words to the title.

Actual behavior

In the second operation (POST), response example disappears and is replaced with "(no example available)".

Expected behavior

Both response examples continue to be displayed.

Screenshots

response example disappears

Additional context or thoughts

1) It's not just examples, the Model/Schema also loses info

image

2) The issue seems to happen if several expanded operations use the same schema. If we expand just the POST operation but not GET and then update the YAML, the issue does NOT occur.

3) The issue seems to be related to the use of allOf in the response schema:

  error404:
    description: Error 404
    allOf:
      - $ref: '#/definitions/error'

If we replace it with

  error404:
    $ref: '#/definitions/error'

then the examples are re-rendered correctly.

hkosova avatar Mar 24 '21 10:03 hkosova

@mathis-m This is probably from recent implementation changes for examples in swagger-ui

tim-lai avatar Mar 24 '21 17:03 tim-lai

@tim-lai or it could be an issue with the allOf/$ref resolver. I updated the description with additional observations.

hkosova avatar Mar 24 '21 17:03 hkosova

@tim-lai or it could be an issue with the allOf/$ref resolver. I updated the description with additional observations.

@hkosova yep you are right allOf is not resolved(q is the schema handed to sample-gen): image

mathis-m avatar Mar 24 '21 21:03 mathis-m