fix(plugin-fetch,plugin-axios): serialize bigint request bodies - #800
Merged
Conversation
`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.
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
🦋 Changeset detectedLatest commit: 4ec43c5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
Contributor
|
Size Change: 0 B Total Size: 311 kB ℹ️ View Unchanged
|
More templates
@kubb/plugin-axios
@kubb/plugin-cypress
@kubb/plugin-faker
@kubb/plugin-fetch
@kubb/plugin-mcp
@kubb/plugin-msw
@kubb/plugin-react-query
@kubb/plugin-redoc
@kubb/plugin-swr
@kubb/plugin-ts
@kubb/plugin-vue-query
@kubb/plugin-zod
commit: |
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.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Changes
Follow-up to #797, which fixed the response side of #786. This is the request side.
defaultBodySerializerhanded the body to a bareJSON.stringify, which throws on abigint. So any request carrying aformat: int64field failed before it reached the network:A replacer on both
JSON.stringifycall sites inserializers.tsnow emits bigints as JSON numbers.The precision call
Past
Number.MAX_SAFE_INTEGERthe conversion cannot be lossless, so it throws with a message naming the cause instead of sending a truncated value: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.parseand there was nothing left to preserve.serializer.bodyand per-content-type codecs stay available for anyone who needs to send those values.Notes for review
serializers.tsmust stay byte-identical between plugin-fetch and plugin-axios (templatesSync.test.tsenforces it), so both copies carry the change.toValue, which usesString(value).✅ Checklist
pnpm run test.🚀 Release Impact