Skip to content

fix(plugin-zod): coerce bigint so int64 responses validate - #797

Merged
stijnvanhulle merged 3 commits into
mainfrom
fix/int64-coerce-bigint
Aug 27, 2026
Merged

fix(plugin-zod): coerce bigint so int64 responses validate#797
stijnvanhulle merged 3 commits into
mainfrom
fix/int64-coerce-bigint

Conversation

@stijnvanhulle

Copy link
Copy Markdown
Contributor

🎯 Changes

Closes #786.

format: int64 printed z.bigint(). JSON.parse hands back a number for those fields, so z.bigint() rejected every response containing one when using pluginFetch({ validator: 'zod' }). The default config of plugin-zod and plugin-fetch could not work together.

Both Zod printers now emit z.coerce.bigint():

-export const tagSchema = z.object({ id: z.bigint().optional() })
+export const tagSchema = z.object({ id: z.coerce.bigint().optional() })

Notes for review

  • Coercion is unconditional and identical for encode and decode, so no ${name}InputSchema variant is generated for components carrying an int64.
  • The coercion option no longer gates bigint. coercion: { numbers: true } produced z.coerce.bigint() before and still does, so that path is unchanged. The JSDoc on Options.coercion records the new behavior.
  • Verified against zod 4.4.3 and zod/mini: 42 → 42n, an existing bigint passes through, and a non-integer like 1.5 is still rejected.
  • Precision beyond 2^53-1 is already lost inside JSON.parse, before Zod runs. Fixing that needs a precision-preserving parser in plugin-fetch and is out of scope here. The integerType: 'number' workaround has the same limit.
  • 165 snapshot and example files regenerated.

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

@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

@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bd19587

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

This PR includes changesets to release 1 package
Name Type
@kubb/plugin-zod 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

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 27, 2026
@github-actions github-actions Bot added the bug Something isn't working label Aug 27, 2026
@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@797

@kubb/plugin-cypress

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

@kubb/plugin-faker

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

@kubb/plugin-fetch

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

@kubb/plugin-mcp

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

@kubb/plugin-msw

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

@kubb/plugin-react-query

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

@kubb/plugin-redoc

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

@kubb/plugin-swr

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

@kubb/plugin-ts

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

@kubb/plugin-vue-query

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

@kubb/plugin-zod

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

commit: 4f97e63

@github-actions

github-actions Bot commented Aug 27, 2026

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

Stijn Van Hulle and others added 2 commits August 27, 2026 11:50
`format: int64` printed `z.bigint()`, but `JSON.parse` hands back a
`number`, so every response containing such a field failed validation
under `pluginFetch({ validator: 'zod' })`.

Both printers now emit `z.coerce.bigint()`, unconditionally and in both
directions, so no `InputSchema` variant is generated. Precision past
2^53-1 is already gone by the time Zod runs, which the existing
`integerType: 'number'` workaround does not change either.

Closes #786
@stijnvanhulle
stijnvanhulle force-pushed the fix/int64-coerce-bigint branch from 6d03220 to 4f97e63 Compare August 27, 2026 09:50
@stijnvanhulle
stijnvanhulle merged commit 92a2a33 into main Aug 27, 2026
12 of 13 checks passed
@stijnvanhulle
stijnvanhulle deleted the fix/int64-coerce-bigint 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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-fetch runtime values don't match types for int64 data

1 participant