Skip to content

fix(openapi-fetch): pass string bodies through without JSON serialization#2761

Open
Nedunchezhiyan-M wants to merge 2 commits intoopenapi-ts:mainfrom
Nedunchezhiyan-M:fix/body-serializer-string-passthrough
Open

fix(openapi-fetch): pass string bodies through without JSON serialization#2761
Nedunchezhiyan-M wants to merge 2 commits intoopenapi-ts:mainfrom
Nedunchezhiyan-M:fix/body-serializer-string-passthrough

Conversation

@Nedunchezhiyan-M
Copy link
Copy Markdown

Summary

  • defaultBodySerializer was calling JSON.stringify on all non-FormData bodies, including strings that are already serialized
  • A body: "pre-serialized string" would become '"pre-serialized string"' (double-quoted) in the request
  • Added an early return for string bodies so they are sent as-is

Test plan

  • Existing test for body: "" updated to expect empty string passthrough (was "")
  • New test string body is passed through without JSON serialization covers non-empty string bodies
  • All 456 existing tests continue to pass

Fixes #2555

…tion

defaultBodySerializer was calling JSON.stringify on all non-FormData
bodies, including strings that are already serialized. This caused
string values to gain an extra layer of JSON quoting (e.g. "hello"
became '"hello"'). Add an early return for string bodies so they
are sent as-is.

Fixes openapi-ts#2555
@Nedunchezhiyan-M Nedunchezhiyan-M requested a review from a team as a code owner April 13, 2026 14:26
@Nedunchezhiyan-M Nedunchezhiyan-M requested a review from drwpow April 13, 2026 14:26
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 13, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 124c63d

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 13, 2026

⚠️ No Changeset found

Latest commit: 3a90e59

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

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.

The defaultSerializer adds unwanted quotes when typeof body === "string" (due to JSON.stringify)

2 participants