Skip to content

fix(theme): preserve large integer precision in response panel (#1208) - #1458

Merged
sserrata merged 1 commit into
mainfrom
fix/1208-bigint-precision-loss
May 6, 2026
Merged

sserrata merged 1 commit into
mainfrom
fix/1208-bigint-precision-loss

Conversation

@sserrata

@sserrata sserrata commented May 6, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #1208. The response pretty-printer round-tripped the body through JSON.parse / JSON.stringify, which silently truncated integers beyond Number.MAX_SAFE_INTEGER (e.g. the reported 19-digit ID 1945044589271781376 became 1945044589271781400).

This PR replaces the round trip with a small string-level pretty-printer that re-indents structural tokens only — number literals pass through verbatim, so any precision the upstream service emitted is preserved exactly. JSON.parse is kept solely as a validity check so malformed bodies still fall through to the XML / raw branch.

  • No new dependencies, no bundle-size impact.
  • Single file changed (packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Response/index.tsx).
  • Display-only path — no downstream code consumes the parsed object.

Test plan

  • yarn watch + yarn start, navigate to the demo's httpbin → POST /anything page.
  • Send body {"id": 1945044589271781376} and confirm the response panel shows "id": 1945044589271781376 (not …1400).
  • Send body {"big": 9999999999999999, "neg": -9007199254740993, "sci": 1.10} and confirm each value is preserved verbatim.
  • Send a small/normal JSON body and confirm formatting is unchanged.
  • Send a non-JSON / XML response and confirm the XML branch still renders.

🤖 Generated with Claude Code

The response pretty-printer round-tripped the body through
JSON.parse/JSON.stringify, which silently truncated integers beyond
Number.MAX_SAFE_INTEGER (e.g. 19-digit IDs like 1945044589271781376
became 1945044589271781400).

Replace the round trip with a small string-level pretty-printer that
re-indents structural tokens only, so number literals pass through
verbatim. JSON.parse is kept solely as a validity check so malformed
bodies still fall through to the XML/raw branch.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 2.29 MB

ℹ️ View Unchanged
Filename Size
demo/.docusaurus/codeTranslations.json 2 B
demo/.docusaurus/docusaurus.config.mjs 16.4 kB
demo/.docusaurus/globalData.json 73.4 kB
demo/.docusaurus/i18n.json 372 B
demo/.docusaurus/registry.js 106 kB
demo/.docusaurus/routes.js 100 kB
demo/.docusaurus/routesChunkNames.json 41.7 kB
demo/.docusaurus/site-metadata.json 1.58 kB
demo/build/assets/css/styles.********.css 173 kB
demo/build/assets/js/main.********.js 675 kB
demo/build/assets/js/runtime~main.********.js 24.4 kB
demo/build/index.html 99.5 kB
demo/build/petstore/add-pet/index.html 30 kB
demo/build/petstore/create-user/index.html 24.7 kB
demo/build/petstore/create-users-with-array-input/index.html 24.8 kB
demo/build/petstore/create-users-with-list-input/index.html 24.8 kB
demo/build/petstore/delete-order/index.html 24.5 kB
demo/build/petstore/delete-pet/index.html 24.8 kB
demo/build/petstore/delete-user/index.html 25 kB
demo/build/petstore/find-pets-by-status/index.html 25.5 kB
demo/build/petstore/find-pets-by-tags/index.html 26.1 kB
demo/build/petstore/get-inventory/index.html 23.8 kB
demo/build/petstore/get-order-by-id/index.html 24.8 kB
demo/build/petstore/get-pet-by-id/index.html 25.6 kB
demo/build/petstore/get-user-by-name/index.html 25.1 kB
demo/build/petstore/login-user/index.html 25.6 kB
demo/build/petstore/logout-user/index.html 24.4 kB
demo/build/petstore/new-pet/index.html 25 kB
demo/build/petstore/pet/index.html 23.2 kB
demo/build/petstore/place-order/index.html 24 kB
demo/build/petstore/schemas/apiresponse/index.html 25.2 kB
demo/build/petstore/schemas/cat/index.html 39 kB
demo/build/petstore/schemas/category/index.html 26.3 kB
demo/build/petstore/schemas/dog/index.html 39.3 kB
demo/build/petstore/schemas/honeybee/index.html 39.3 kB
demo/build/petstore/schemas/id/index.html 23.4 kB
demo/build/petstore/schemas/order/index.html 27.3 kB
demo/build/petstore/schemas/pet/index.html 38.8 kB
demo/build/petstore/schemas/tag/index.html 24.7 kB
demo/build/petstore/schemas/user/index.html 40.7 kB
demo/build/petstore/store/index.html 22.2 kB
demo/build/petstore/subscribe-to-the-store-events/index.html 30.9 kB
demo/build/petstore/swagger-petstore-yaml/index.html 30.9 kB
demo/build/petstore/update-pet-with-form/index.html 25 kB
demo/build/petstore/update-pet/index.html 25.4 kB
demo/build/petstore/update-user/index.html 25 kB
demo/build/petstore/upload-file/index.html 24.8 kB
demo/build/petstore/user/index.html 22.9 kB

compressed-size-action

@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit ec0ea49):

https://docusaurus-openapi-36b86--pr1458-02vb6t6e.web.app

(expires Wed, 13 May 2026 15:47:56 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bf293780ee827f578864d92193b8c2866acd459f

@sserrata
sserrata merged commit b4ec363 into main May 6, 2026
12 checks passed
@sserrata
sserrata deleted the fix/1208-bigint-precision-loss branch May 6, 2026 15:58

This branch was previously deployed

1 inactive deployment
preview — ec0ea495 Deployed May 6, 2026 by sserrata via Deploy #2129
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The integer value received when returning the API request is inaccurate

1 participant