Skip to content

Commit d86eca6

Browse files
committed
fix: bigint响应为字符串
1 parent e905a04 commit d86eca6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/lib/parse-schema.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export const parseSchema = (
2020
return `(boolean${nullable})`;
2121
case 'integer':
2222
case 'number':
23+
if (parsed.format === 'int64') {
24+
// bigint 在传输过程中会转为字符串
25+
return `(string${nullable})`;
26+
}
2327
return `(number${nullable})`;
2428
case 'string':
2529
if (parsed.format === 'binary') return `(Blob${nullable})`;

test/lib/parse-schema.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ describe('常规', () => {
8282
parseSchema(docs, { enum: ['foo', 'bar', 'baz', 1, 2] }),
8383
).toMatchInlineSnapshot(`"("foo" | "bar" | "baz" | 1 | 2)"`);
8484
});
85+
86+
test('bigint转为字符串', () => {
87+
const type = parseSchema(docs, { type: 'integer', format: 'int64' });
88+
expect(type).toMatchInlineSnapshot(`"(string)"`);
89+
});
8590
});
8691

8792
describe('oneOf', () => {

0 commit comments

Comments
 (0)