Skip to content

fix(plugin-fetch,plugin-axios): serialize bigint request bodies - #800

Merged
stijnvanhulle merged 3 commits into
mainfrom
fix/int64-request-body
Aug 27, 2026
Merged

fix(plugin-fetch,plugin-axios): serialize bigint request bodies#800
stijnvanhulle merged 3 commits into
mainfrom
fix/int64-request-body

Conversation

@stijnvanhulle

Copy link
Copy Markdown
Contributor

🎯 Changes

Follow-up to #797, which fixed the response side of #786. This is the request side.

defaultBodySerializer handed the body to a bare JSON.stringify, which throws on a bigint. So any request carrying a format: int64 field failed before it reached the network:

defaultBodySerializer({ body: { id: 42n }, contentType: 'application/json' })
// TypeError: Do not know how to serialize a BigInt

A replacer on both JSON.stringify call sites in serializers.ts now emits bigints as JSON numbers.

The precision call

Past Number.MAX_SAFE_INTEGER the conversion cannot be lossless, so it throws with a message naming the cause instead of sending a truncated value:

Cannot serialize 9007199254740993n as JSON without losing precision, register a serializer.body to send it another way.

A silently wrong ID going out is worse than a loud failure, which is why this differs from the read side, where the truncation already happened inside JSON.parse and there was nothing left to preserve. serializer.body and per-content-type codecs stay available for anyone who needs to send those values.

Notes for review

  • serializers.ts must stay byte-identical between plugin-fetch and plugin-axios (templatesSync.test.ts enforces it), so both copies carry the change.
  • Form data and query params were already correct. They go through toValue, which uses String(value).
  • 49 test snapshots and 9 example copies updated. Every example copy was byte-identical to the old template beforehand, so the copy matches what regeneration produces.
  • Three tests added covering a top-level bigint, one nested in a multipart part, and the overflow throw.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is for the docs (no release).

`defaultBodySerializer` handed the body to a bare `JSON.stringify`, which
throws on a `bigint`. Any request carrying a `format: int64` field failed
before it reached the network.

A replacer now emits bigints as JSON numbers. Past
`Number.MAX_SAFE_INTEGER` it throws with a message naming the cause,
since a silently truncated ID on the way out is worse than a loud
failure. `serializer.body` and per-content-type codecs remain the escape
hatch for those.

Mirror of the response-side fix in #797.
@codesandbox

codesandbox Bot commented Aug 27, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 27, 2026
@github-actions github-actions Bot added the bug Something isn't working label Aug 27, 2026
@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4ec43c5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@kubb/plugin-fetch Patch
@kubb/plugin-axios Patch

Not sure what this means? Click here to learn what changesets are.

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

@github-actions

Copy link
Copy Markdown
Contributor

Size Change: 0 B

Total Size: 311 kB

ℹ️ View Unchanged
Filename Size
packages/plugin-axios/dist/index.cjs 15.3 kB
packages/plugin-axios/dist/index.js 14.8 kB
packages/plugin-axios/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-cypress/dist/index.cjs 5.71 kB
packages/plugin-cypress/dist/index.js 5.62 kB
packages/plugin-cypress/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-faker/dist/index.cjs 14.5 kB
packages/plugin-faker/dist/index.js 14.4 kB
packages/plugin-faker/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-fetch/dist/index.cjs 15.3 kB
packages/plugin-fetch/dist/index.js 14.8 kB
packages/plugin-fetch/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-mcp/dist/index.cjs 10 kB
packages/plugin-mcp/dist/index.js 9.54 kB
packages/plugin-mcp/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-msw/dist/index.cjs 5.81 kB
packages/plugin-msw/dist/index.js 5.72 kB
packages/plugin-msw/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-react-query/dist/index.cjs 17.6 kB
packages/plugin-react-query/dist/index.js 17.1 kB
packages/plugin-react-query/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-redoc/dist/index.cjs 2.21 kB
packages/plugin-redoc/dist/index.js 1.74 kB
packages/plugin-redoc/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-swr/dist/index.cjs 11.9 kB
packages/plugin-swr/dist/index.js 11.4 kB
packages/plugin-swr/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-ts/dist/index.cjs 23.8 kB
packages/plugin-ts/dist/index.js 23.1 kB
packages/plugin-ts/dist/rolldown-runtime-CNktS9qV.js 291 B
packages/plugin-vue-query/dist/index.cjs 14.8 kB
packages/plugin-vue-query/dist/index.js 14.2 kB
packages/plugin-vue-query/dist/rolldown-runtime-C0LytTxp.js 168 B
packages/plugin-zod/dist/index.cjs 19.7 kB
packages/plugin-zod/dist/index.js 19.5 kB
packages/plugin-zod/dist/rolldown-runtime-C0LytTxp.js 168 B

compressed-size-action

@pkg-pr-new

pkg-pr-new Bot commented Aug 27, 2026

Copy link
Copy Markdown
More templates

@kubb/plugin-axios

npm i https://pkg.pr.new/@kubb/plugin-axios@800

@kubb/plugin-cypress

npm i https://pkg.pr.new/@kubb/plugin-cypress@800

@kubb/plugin-faker

npm i https://pkg.pr.new/@kubb/plugin-faker@800

@kubb/plugin-fetch

npm i https://pkg.pr.new/@kubb/plugin-fetch@800

@kubb/plugin-mcp

npm i https://pkg.pr.new/@kubb/plugin-mcp@800

@kubb/plugin-msw

npm i https://pkg.pr.new/@kubb/plugin-msw@800

@kubb/plugin-react-query

npm i https://pkg.pr.new/@kubb/plugin-react-query@800

@kubb/plugin-redoc

npm i https://pkg.pr.new/@kubb/plugin-redoc@800

@kubb/plugin-swr

npm i https://pkg.pr.new/@kubb/plugin-swr@800

@kubb/plugin-ts

npm i https://pkg.pr.new/@kubb/plugin-ts@800

@kubb/plugin-vue-query

npm i https://pkg.pr.new/@kubb/plugin-vue-query@800

@kubb/plugin-zod

npm i https://pkg.pr.new/@kubb/plugin-zod@800

commit: 4ec43c5

Stijn Van Hulle and others added 2 commits August 27, 2026 11:02
Compare the bigint against the safe-integer bounds directly instead of
routing through an intermediate number, and cut the doc to the length
its siblings in this file use. Adds the negative bound to the test.
@stijnvanhulle
stijnvanhulle merged commit c13b8fe into main Aug 27, 2026
15 checks passed
@stijnvanhulle
stijnvanhulle deleted the fix/int64-request-body branch August 27, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant