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

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

Open glowcloud opened this issue 1 year ago • 1 comments

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 avatar Mar 14 '24 13:03 glowcloud

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?

glowcloud avatar Mar 18 '24 13:03 glowcloud