Skip to content

Commit c264d00

Browse files
committed
properly serialises request bodies that contain int64 (BigInt)
1 parent 6be1c85 commit c264d00

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/fetch-wrapper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { safeParse } from "fast-content-type-parse";
2-
import { JSONParse } from "json-with-bigint";
2+
import { JSONParse, JSONStringify } from "json-with-bigint";
33
import { isPlainObject } from "./is-plain-object.js";
44
import { RequestError } from "@octokit/request-error";
55
import type { EndpointInterface, OctokitResponse } from "@octokit/types";
@@ -27,7 +27,7 @@ export default async function fetchWrapper(
2727

2828
const body =
2929
isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)
30-
? JSON.stringify(requestOptions.body)
30+
? JSONStringify(requestOptions.body)
3131
: requestOptions.body;
3232

3333
// Header values must be `string`

test/request.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
} from "@octokit/types";
1515

1616
import { request } from "../src/index.ts";
17+
import { JSONStringify } from "json-with-bigint";
1718

1819
const userAgent = `octokit-request.js/0.0.0-development ${getUserAgent()}`;
1920
const __filename = new URL(import.meta.url);
@@ -1365,4 +1366,31 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w==
13651366
expect(response.status).toEqual(200);
13661367
expect(response.data[0].id).toEqual(BigInt(Number.MAX_SAFE_INTEGER) + 9n);
13671368
});
1369+
1370+
it("properly serialises request bodies that contain int64 (BigInt)", async () => {
1371+
expect.assertions(2);
1372+
1373+
const id = BigInt(Number.MAX_SAFE_INTEGER) + 9n;
1374+
const mock = fetchMock.createInstance();
1375+
mock.get("https://api.github.com/app/hook/deliveries", {
1376+
status: 200,
1377+
headers: {
1378+
"Content-Type": "application/json; charset=utf-8",
1379+
},
1380+
body: JSONStringify({
1381+
id: id,
1382+
}),
1383+
});
1384+
1385+
const response = await request("GET /app/hook/deliveries/{delivery_id}", {
1386+
// @ts-expect-error The types won't allw BigInt until https://github.com/octokit/openapi-types.ts/pull/489 is merged and released
1387+
delivery_id: id,
1388+
request: {
1389+
fetch: mock.fetchHandler,
1390+
},
1391+
});
1392+
1393+
expect(response.status).toEqual(200);
1394+
expect(response.data.id).toEqual(id);
1395+
});
13681396
});

0 commit comments

Comments
 (0)