swagger-api / swagger-api/swagger-ui
Displayed example not updated sometimes when switching between media types
Open
Nobody has claimed this yet.
cat: rendering
type: bug
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
This issue is related to OAS3 examples support.
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 3.0
Content & configuration
Example Swagger/OpenAPI definition:
openapi: 3.0.2
info:
title: test
version: 0.0.0
paths:
/foo:
post:
requestBody:
description: A JSON object, XML object, or text string containing foo data
required: true
content:
application/json:
schema:
type: object
examples:
foo_json:
value:
foo: bar
bar_json:
value:
bar: foo
text/plain:
schema:
type: string
example: Hello, world!
application/xml:
schema:
type: object
examples:
foo_xml:
value: <foo>bar</foo>
bar_xml:
value: <bar>foo</bar>
responses:
201:
description: Created
Describe the bug you're encountering
In certain cases, switching between media types does not update the displayed "Example Value".
Steps to reproduce
- Go to https://editor.swagger.io and paste the spec above.
- Expand the operation.
- From the "Examples" list, select "bar_json".
- From the media types list, select "application/xml".
=> The "Examples" list is updated to contain "foo_xml" and "bar_xml" but the displayed "Example Value" is not updated. - From the media types list, select "text/plain".
=> "Example Value" still contains the JSON example. Should display "Hello, world!".
Screenshots
Screenshot for step 4:

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in editor.swagger.io using the OpenAPI definition and media-type switching steps in the report. Trace the example selection and media-type change flow; done means switching to application/xml or text/plain updates the displayed Example Value to the selected media type's example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100