Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
glowcloud opened this issue Mar 14, 2024 · 1 comment

Comments

@glowcloud
Copy link
Contributor

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
Copy link
Contributor Author

Investigating a different issue, I found this

onChangeMediaType = ({ value, pathMethod }) => {
let { specActions, oas3Selectors, oas3Actions } = this.props
const userHasEditedBody = oas3Selectors.hasUserEditedBody(...pathMethod)
const shouldRetainRequestBodyValue = oas3Selectors.shouldRetainRequestBodyValue(...pathMethod)
oas3Actions.setRequestContentType({ value, pathMethod })
oas3Actions.initRequestBodyValidateError({ pathMethod })
if (!userHasEditedBody) {
if(!shouldRetainRequestBodyValue) {
oas3Actions.setRequestBodyValue({ value: undefined, pathMethod })
}
specActions.clearResponse(...pathMethod)
specActions.clearRequest(...pathMethod)
specActions.clearValidateParams(pathMethod)
}
}

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant