Skip to content

feat(openapi-fetch): only parse as JSON if content-type indicates JSON#2575

Open
brunolca wants to merge 2 commits intoopenapi-ts:mainfrom
brunolca:feat/check-content-type-before-json-parse
Open

feat(openapi-fetch): only parse as JSON if content-type indicates JSON#2575
brunolca wants to merge 2 commits intoopenapi-ts:mainfrom
brunolca:feat/check-content-type-before-json-parse

Conversation

@brunolca
Copy link
Contributor

@brunolca brunolca commented Feb 3, 2026

Fixes #2574

Changes

  • For success responses with parseAs: "json" (the default), check if Content-Type includes application/json before calling response.json(). Falls back to response.text() otherwise.
  • For error responses, only attempt JSON.parse() if the Content-Type includes application/json.

How to Review

As I understand this it is a breaking change. You can test by follwing the reproduction steps here #2574

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

@brunolca brunolca requested a review from a team as a code owner February 3, 2026 12:03
@brunolca brunolca requested a review from htunnicliff February 3, 2026 12:03
@netlify
Copy link

netlify bot commented Feb 3, 2026

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit ccbc55d

@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

⚠️ No Changeset found

Latest commit: ccbc55d

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.

Fails to parse responses when Content-Length header is stripped by proxy

1 participant