swagger-editor
swagger-editor copied to clipboard
Response example is sometimes replaced with "(no example available)" after re-rendering
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:
- Go to https://editor.swagger.io and paste the YAML provided above.
- Expand both operations in the UI panel. Note that both operations show response examples.
- Scroll the UI so that both response examples are visible.
- 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
Additional context or thoughts
1) It's not just examples, the Model/Schema also loses info
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.
@mathis-m This is probably from recent implementation changes for examples
in swagger-ui
@tim-lai or it could be an issue with the allOf
/$ref
resolver. I updated the description with additional observations.
@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):