Skip to content

Conversation

franworks
Copy link

@franworks franworks commented Aug 30, 2025

resolves: #2553

When the options.serializedBody property was introduced, it replaced the body sent in the Request object causing any options.body not requiring a bodySerializer (ie plain/text) to be omitted from the request.

This PR fixes this behavior, ensuring that when an options.body is defined it is sent with the Request 'as-is', or 'serialized' if an options.bodySerializer is defined.

Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

changeset-bot bot commented Aug 30, 2025

⚠️ No Changeset found

Latest commit: 4064f51

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.

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

Copy link

vercel bot commented Aug 30, 2025

Someone is attempting to deploy a commit to the Hey API Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug 🔥 Something isn't working client Client package related labels Aug 30, 2025
@franworks
Copy link
Author

@mrlubos assistance is requested to address next steps in resolving pipeline errors.

@@ -78,9 +78,12 @@ export const createClient = (config: Config = {}): Client => {
const requestInit: ReqInit = {
redirect: 'follow',
...opts,
body: opts.serializedBody,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't all that you want something like this?

body: opts.serializedBody !== undefined ? opts.serializedBody : opts.body,

Copy link
Author

@franworks franworks Aug 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought about going the opts.serializedBody ?? opts.body route but decided to put it in a separate block for readability and clarity.

Body is already a property on the options object, no need to define or reassign if its not necessary. It was confusing for me to see body redefined in the client-next plugin like body: options.body. I had to ask myself if something was different - it wasn't.

Happy to change it if you prefer the one liner.

Copy link
Member

@mrlubos mrlubos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the logic in all clients using serializedBody and then update snapshots with pnpm --filter @test/openapi-ts test:update

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 31, 2025
Copy link

pkg-pr-new bot commented Aug 31, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@2564
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@2564
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@2564
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@2564

commit: b4d06c6

Copy link

codecov bot commented Aug 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 23.98%. Comparing base (fe2803a) to head (b4d06c6).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2564      +/-   ##
==========================================
+ Coverage   23.69%   23.98%   +0.28%     
==========================================
  Files         362      362              
  Lines       36340    36345       +5     
  Branches     1562     1603      +41     
==========================================
+ Hits         8612     8716     +104     
+ Misses      27715    27616      -99     
  Partials       13       13              
Flag Coverage Δ
unittests 23.98% <100.00%> (+0.28%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@franworks
Copy link
Author

@mrlubos the next client was the only client impacted by the serializeBody change - that has issue has now been resolved as part of this PR.

Tests have been added, snapshots updated.

@mrlubos
Copy link
Member

mrlubos commented Aug 31, 2025

@mrlubos the next client was the only client impacted by the serializeBody change - that has issue has now been resolved as part of this PR.

Tests have been added, snapshots updated.

Isn't this line going to have the same issue?

@franworks
Copy link
Author

@mrlubos I reviewed the changes tracked in the issue that triggered the bug which were the client-fetch and client-next clients.

I did not go through and review all of the clients. However, I can do that, starting with your reference to the angular client.

@mrlubos
Copy link
Member

mrlubos commented Aug 31, 2025

@mrlubos I reviewed the changes tracked in the issue that triggered the bug which were the client-fetch and client-next clients.

I did not go through and review all of the clients. However, I can do that, starting with your reference to the angular client.

Yes please. Aside from making sure this bug isn't present in any of the clients, I think there are 2 issues with this change.

  1. if (opts.serializedBody) { requires the serialized body to be truthy, which would not be true for empty strings, 0, etc. I think it should be checking for the presence of serialized body instead fix(client-fetch): ensures plain/text body is sent with request #2564 (comment)
  2. if (opts.body === undefined || opts.body === '') { relies on the raw body for removing the Content-Type header. This is incorrect, it should work based on the final body we'll be sending. Currently it makes it possible to have a body that serializes to empty string and we'd fail to remove the Content-Type header.

@franworks
Copy link
Author

@mrlubos the angular client would not have this issue because serializedBody is initialized with options.body

@franworks
Copy link
Author

@mrlubos - looking at the angular client, would be acceptable to initialize the serializedBody with the options.body?

@mrlubos
Copy link
Member

mrlubos commented Aug 31, 2025

That's either a mistake we want to fix or a valid approach we should use across all clients. I don't know what's the better approach, and I don't feel particularly strongly about either option. The only thing I feel strongly about is having it be consistent so one can easily reason through these features

@franworks
Copy link
Author

Agreed. I'm writing tests for the different scenarios. Will post back when I have it sorted out.

@franworks
Copy link
Author

@mrlubos I pushed just the fetch client changes. If these changes make sense, I will update the other clients.
I do not think serializedBody should be initialized with opts.body - it would be unexpected if no bodySerializer is defined.

@franworks franworks marked this pull request as draft September 1, 2025 14:54
@franworks
Copy link
Author

franworks commented Sep 1, 2025

@mrlubos A body defined as 0 or false with defined bodySerializer will not make it into the expected block

Should this check be updated as part of this PR?

@mrlubos
Copy link
Member

mrlubos commented Sep 2, 2025

@mrlubos A body defined as 0 or false with defined bodySerializer will not make it into the expected block

Should this check be updated as part of this PR?

Yes please

@mrlubos
Copy link
Member

mrlubos commented Sep 2, 2025

I do not think serializedBody should be initialized with opts.body - it would be unexpected if no bodySerializer is defined.

I agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working client Client package related size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fetch client request body is undefined when content-type is text/plain
2 participants