swagger-api / swagger-api/swagger-ui

Displayed example not updated sometimes when switching between media types

Open
#5,460 0 comments 0 reactions 0 assignees View on GitHub

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
  1. Go to https://editor.swagger.io and paste the spec above.
  2. Expand the operation.
  3. From the "Examples" list, select "bar_json".
  4. 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.
  5. From the media types list, select "text/plain".
    => "Example Value" still contains the JSON example. Should display "Hello, world!".
Screenshots

Screenshot for step 4:
image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.