Skip to content

fix(plugin-fetch,plugin-axios): parse int64 responses without losing precision - #810

Closed
stijnvanhulle wants to merge 2 commits into
mainfrom
claude/validate-issue-786-comment-ifrkh6
Closed

fix(plugin-fetch,plugin-axios): parse int64 responses without losing precision#810
stijnvanhulle wants to merge 2 commits into
mainfrom
claude/validate-issue-786-comment-ifrkh6

Conversation

@stijnvanhulle

Copy link
Copy Markdown
Contributor

🎯 Changes

Follow-up to #797 and #800, closing the gap axel-havukangas-futurice flagged in the last comment on #786.

#797 made format: int64 fields print z.coerce.bigint() so a response validates at all, but the value it coerces from is already wrong: JSON.parse rounds any integer past Number.MAX_SAFE_INTEGER to the nearest representable number before Zod ever sees it. z.coerce.bigint() then faithfully converts that already-rounded number to a bigint with the wrong value.

Both clients now read the response body through a bigint-safe parseJson (added to the shared serializers.ts template):

  • For ordinary payloads it defers straight to the native JSON.parse.
  • Only when the raw text contains a run of 16+ digits (the minimum length for a value past the safe-integer range) does it walk the text itself, reading an out-of-range integer literal directly into a bigint instead of through the lossy intermediate number.

Wired into:

  • plugin-fetch's parseResponse (both the 'json' branch and the opportunistic-parse fallback) and its SSE parseEvent.
  • plugin-axios's transformResponse (axios's own default, with JSON.parse swapped for parseJson) and its SSE parseEvent.

Every example and test snapshot under a .kubb output folder is regenerated; the only diffs are the copied client.ts / serializers.ts templates.

✅ 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).

Closes the precision-loss gap in #786.

Generated by Claude Code


Generated by Claude Code

claude added 2 commits August 28, 2026 15:15
…precision

JSON.parse always rounds an integer past Number.MAX_SAFE_INTEGER to the
nearest representable number, so a format: int64 field lost precision on
the response side even after #797 coerced it to z.coerce.bigint() -
the value was already wrong by the time Zod saw it (#786).

Add a bigint-safe parseJson to the shared serializers template: it defers
to the native JSON.parse for ordinary payloads and only walks the text
itself when an unsafe-length digit run is present, reading an
out-of-range integer literal straight into a bigint. Both plugin-fetch's
parseResponse/parseEvent and plugin-axios's transformResponse/parseEvent
now use it.
Regenerated every example and test snapshot after wiring parseJson
into plugin-fetch and plugin-axios's response parsing (previous
commit). Every changed file is a copied client.ts/serializers.ts
under a .kubb output folder.
@codesandbox

codesandbox Bot commented Aug 28, 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:XXL This PR changes 1000+ lines, ignoring generated files. label Aug 28, 2026
@changeset-bot

changeset-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2fe5d44

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 28, 2026

Copy link
Copy Markdown
More templates

@kubb/plugin-axios

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

@kubb/plugin-cypress

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

@kubb/plugin-faker

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

@kubb/plugin-fetch

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

@kubb/plugin-mcp

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

@kubb/plugin-msw

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

@kubb/plugin-react-query

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

@kubb/plugin-redoc

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

@kubb/plugin-swr

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

@kubb/plugin-ts

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

@kubb/plugin-vue-query

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

@kubb/plugin-zod

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

commit: 2fe5d44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants