swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.34k stars 8.92k forks source link

OpenAPI 3.x: request body doesn't update when changing between content type in try it out #9699

Open glowcloud opened 6 months ago

glowcloud commented 6 months ago

Describe the bug you're encountering

Request body value in try it out isn't being updated when switching to a different content type, if the value was edited.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://petstore3.swagger.io/
  2. Click on /pet PUT request
  3. Click on try it out button
  4. Edit the value
  5. Switch to application/xml content type
  6. See that the value didn't update

The same thing will happen if we edit application/xml first and then switch to application/json.

Expected behavior

The value should switch to the default value for the current content type.

Screenshots

When switching from application/json to application/xml:

Screenshot 2024-03-14 at 14 53 20

When switching from application/xml to application/json:

Screenshot 2024-03-14 at 14 54 32
glowcloud commented 6 months ago

Investigating a different issue, I found this https://github.com/swagger-api/swagger-ui/blob/f91ca8237eec4bf92fc6da9e1697810c8f25f1cc/src/core/components/parameters/parameters.jsx#L79-L93 It seems like right now this is an expected behaviour so that we don't override the user's changes if they edited any values. If the user wants the default value for the content type they switched to, they have to click on the reset button.

Is this something that we would like to change or is this behaviour fine?