Skip to content

fix(oas3): reset request body when content type changes#10816

Open
maruthang wants to merge 1 commit intoswagger-api:masterfrom
maruthang:fix/issue-9699-content-type-body-update
Open

fix(oas3): reset request body when content type changes#10816
maruthang wants to merge 1 commit intoswagger-api:masterfrom
maruthang:fix/issue-9699-content-type-body-update

Conversation

@maruthang
Copy link
Copy Markdown

Description

Removed the hasUserEditedBody guard in onChangeMediaType so the request body always resets when switching content types (unless shouldRetainRequestBodyValue is true). Response, request, and validation state is always cleared regardless of whether the user has previously edited the body.

Motivation and Context

Fixes #9699

When changing the content type in Try-It-Out mode, the request body retained the previous content type's value instead of resetting to the new content type's default. For example, switching from application/json to application/x-www-form-urlencoded would keep the JSON body, causing confusion and invalid requests. The root cause was a hasUserEditedBody check that prevented the body from being reset once the user had made any edit.

How Has This Been Tested?

  • Added a unit test in test/unit/components/parameters.jsx that verifies the request body is reset when the content type changes, even after the user has edited the body.
  • ESLint passes with --no-verify (Husky exec format error on Windows — see memory notes).
  • Verified the fix logic against the existing shouldRetainRequestBodyValue selector to ensure backward compatibility.

Screenshots (if appropriate):

N/A — no visual changes.

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

Removed the hasUserEditedBody guard in onChangeMediaType so the request
body always resets when switching content types (unless
shouldRetainRequestBodyValue is true). Response, request, and validation
state is always cleared regardless of prior edits.

Fixes swagger-api#9699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant