Skip to content

Commit ced57a7

Browse files
authored
Merge pull request #2152 from hey-api/fix/zod-bigint-default
fix(validators): correctly generate default value for BigInt
2 parents bfa2c5b + 6d5ad37 commit ced57a7

File tree

13 files changed

+40
-20
lines changed

13 files changed

+40
-20
lines changed

.changeset/tame-stingrays-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/openapi-ts': patch
3+
---
4+
5+
fix(validators): correctly generate default value for `BigInt`

packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as v from 'valibot';
44

55
export const vFoo = v.object({
66
bar: v.optional(v.pipe(v.number(), v.integer())),
7-
foo: v.bigint(),
7+
foo: v.optional(v.bigint(), BigInt(0)),
88
id: v.string()
99
});
1010

packages/openapi-ts-tests/test/__snapshots__/2.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { z } from 'zod';
44

55
export const zFoo = z.object({
66
bar: z.number().int().optional(),
7-
foo: z.coerce.bigint(),
7+
foo: z.coerce.bigint().default(BigInt(0)),
88
id: z.string()
99
});
1010

packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as v from 'valibot';
44

55
export const vFoo = v.object({
66
bar: v.optional(v.pipe(v.number(), v.integer())),
7-
foo: v.bigint(),
7+
foo: v.optional(v.bigint(), BigInt(0)),
88
id: v.string()
99
});
1010

packages/openapi-ts-tests/test/__snapshots__/3.0.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { z } from 'zod';
44

55
export const zFoo = z.object({
66
bar: z.number().int().optional(),
7-
foo: z.coerce.bigint(),
7+
foo: z.coerce.bigint().default(BigInt(0)),
88
id: z.string()
99
});
1010

packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-valibot/valibot.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as v from 'valibot';
44

55
export const vFoo = v.object({
66
bar: v.optional(v.pipe(v.number(), v.integer())),
7-
foo: v.bigint(),
7+
foo: v.optional(v.bigint(), BigInt(0)),
88
id: v.string()
99
});
1010

packages/openapi-ts-tests/test/__snapshots__/3.1.x/plugins/@hey-api/transformers/type-format-zod/zod.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { z } from 'zod';
44

55
export const zFoo = z.object({
66
bar: z.number().int().optional(),
7-
foo: z.coerce.bigint(),
7+
foo: z.coerce.bigint().default(BigInt(0)),
88
id: z.string()
99
});
1010

packages/openapi-ts-tests/test/openapi-ts.config.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ export default defineConfig(() => {
5151
// 'invalid',
5252
// 'servers-entry.yaml',
5353
// ),
54-
// path: path.resolve(__dirname, 'spec', '3.1.x', 'read-write-only.yaml'),
55-
path: '',
54+
path: path.resolve(__dirname, 'spec', '3.1.x', 'type-format.yaml'),
5655
// path: 'http://localhost:4000/',
5756
// path: 'https://get.heyapi.dev/',
5857
// path: 'https://get.heyapi.dev/hey-api/backend?branch=main&version=1.0.0',
@@ -115,9 +114,9 @@ export default defineConfig(() => {
115114
// operationId: false,
116115
// responseStyle: 'data',
117116
// throwOnError: true,
118-
// transformer: '@hey-api/transformers',
117+
transformer: '@hey-api/transformers',
119118
// transformer: true,
120-
// validator: 'zod',
119+
validator: 'zod',
121120
},
122121
{
123122
// bigInt: true,
@@ -146,12 +145,12 @@ export default defineConfig(() => {
146145
{
147146
// comments: false,
148147
// exportFromIndex: true,
149-
// name: 'valibot',
148+
name: 'valibot',
150149
},
151150
{
152151
// comments: false,
153152
// exportFromIndex: true,
154-
// name: 'zod',
153+
name: 'zod',
155154
},
156155
],
157156
// useOptions: false,

packages/openapi-ts-tests/test/spec/2.0.x/type-format.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ definitions:
1919
bar:
2020
type: integer
2121
foo:
22+
default: 0
2223
format: int64
2324
type: integer
2425
id:

packages/openapi-ts-tests/test/spec/3.0.x/type-format.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ components:
2020
bar:
2121
type: integer
2222
foo:
23+
default: 0
2324
format: int64
2425
type: integer
2526
id:

0 commit comments

Comments
 (0)