From cfab9a0985aa772777b5d776edf7951905826de5 Mon Sep 17 00:00:00 2001 From: Lubos Date: Wed, 24 Dec 2025 07:58:43 +0800 Subject: [PATCH] feat: add number base resolvers --- dev/openapi-ts.config.ts | 9 ++++ .../plugins/valibot/default/valibot.gen.ts | 12 ++--- .../plugins/valibot/default/valibot.gen.ts | 12 ++--- .../validators-bigint-min-max/valibot.gen.ts | 2 +- .../3.0.x/mini/default/zod.gen.ts | 12 ++--- .../__snapshots__/3.0.x/v3/default/zod.gen.ts | 12 ++--- .../__snapshots__/3.0.x/v4/default/zod.gen.ts | 12 ++--- .../3.1.x/mini/default/zod.gen.ts | 12 ++--- .../mini/validators-bigint-min-max/zod.gen.ts | 2 +- .../__snapshots__/3.1.x/v3/default/zod.gen.ts | 12 ++--- .../v3/validators-bigint-min-max/zod.gen.ts | 2 +- .../__snapshots__/3.1.x/v4/default/zod.gen.ts | 12 ++--- .../v4/validators-bigint-min-max/zod.gen.ts | 2 +- .../3.0.x/mini/default/zod.gen.ts | 12 ++--- .../__snapshots__/3.0.x/v3/default/zod.gen.ts | 12 ++--- .../__snapshots__/3.0.x/v4/default/zod.gen.ts | 12 ++--- .../3.1.x/mini/default/zod.gen.ts | 12 ++--- .../mini/validators-bigint-min-max/zod.gen.ts | 2 +- .../__snapshots__/3.1.x/v3/default/zod.gen.ts | 12 ++--- .../v3/validators-bigint-min-max/zod.gen.ts | 2 +- .../__snapshots__/3.1.x/v4/default/zod.gen.ts | 12 ++--- .../v4/validators-bigint-min-max/zod.gen.ts | 2 +- .../openapi-ts/src/plugins/valibot/types.d.ts | 18 ++++--- .../src/plugins/valibot/v1/toAst/number.ts | 49 ++++++++++++------- .../src/plugins/valibot/v1/toAst/object.ts | 17 ++++--- .../src/plugins/valibot/v1/toAst/string.ts | 9 +--- .../openapi-ts/src/plugins/zod/mini/api.ts | 10 ++++ .../src/plugins/zod/mini/toAst/object.ts | 17 ++++--- .../src/plugins/zod/mini/toAst/string.ts | 2 +- .../openapi-ts/src/plugins/zod/types.d.ts | 11 ++++- packages/openapi-ts/src/plugins/zod/v3/api.ts | 10 ++++ .../src/plugins/zod/v3/toAst/object.ts | 17 ++++--- .../src/plugins/zod/v3/toAst/string.ts | 2 +- packages/openapi-ts/src/plugins/zod/v4/api.ts | 10 ++++ .../src/plugins/zod/v4/toAst/object.ts | 17 ++++--- .../src/plugins/zod/v4/toAst/string.ts | 8 +-- 36 files changed, 225 insertions(+), 163 deletions(-) diff --git a/dev/openapi-ts.config.ts b/dev/openapi-ts.config.ts index 2fa9cb243..8409fd1ea 100644 --- a/dev/openapi-ts.config.ts +++ b/dev/openapi-ts.config.ts @@ -431,6 +431,15 @@ export default defineConfig(() => { }, }, '~resolvers': { + number: { + // base({ $, pipes, v }) { + // return pipes.push($(v).attr('test').call()); + // }, + formats: { + // date: ({ $, pipes }) => pipes.push($('v').attr('isoDateTime').call()), + // 'date-time': ({ $, pipes }) => pipes.push($('v').attr('isoDateTime').call()), + }, + }, object: { // base({ $, additional, pipes, shape }) { // if (additional === undefined) { diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts index ba6d999dd..d1a8d2901 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.0.x/plugins/valibot/default/valibot.gen.ts @@ -630,8 +630,8 @@ export const vDefault = v.object({ }); export const vPageable = v.object({ - page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'), v.minValue(0)), 0), - size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'), v.minValue(1))), + page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647')), 0), + size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'))), sort: v.optional(v.array(v.string())) }); @@ -962,13 +962,13 @@ export const vCompositionWithOneOfAndProperties = v.intersect([v.union([v.strict }), v.strictObject({ bar: vNonAsciiStringæøåÆøÅöôêÊ字符串 })]), v.object({ - baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'), v.minValue(0)), v.null()]), - qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'), v.minValue(0)) + baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535')), v.null()]), + qux: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255')) })]); export const vModelWithOneOfAndProperties = v.intersect([v.union([vSimpleParameter, vNonAsciiStringæøåÆøÅöôêÊ字符串]), v.object({ - baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'), v.minValue(0)), v.null()]), - qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'), v.minValue(0)) + baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535')), v.null()]), + qux: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255')) })]); /** diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts index bda71b202..3b438ee78 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/valibot/default/valibot.gen.ts @@ -630,8 +630,8 @@ export const vDefault = v.object({ }); export const vPageable = v.object({ - page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'), v.minValue(0)), 0), - size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(-2147483648, 'Invalid value: Expected int32 to be >= -2147483648'), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'), v.minValue(1))), + page: v.optional(v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647')), 0), + size: v.optional(v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(2147483647, 'Invalid value: Expected int32 to be <= 2147483647'))), sort: v.optional(v.array(v.string())) }); @@ -972,13 +972,13 @@ export const vCompositionWithOneOfAndProperties = v.intersect([v.union([v.strict }), v.strictObject({ bar: vNonAsciiStringæøåÆøÅöôêÊ字符串 })]), v.object({ - baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'), v.minValue(0)), v.null()]), - qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'), v.minValue(0)) + baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535')), v.null()]), + qux: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255')) })]); export const vModelWithOneOfAndProperties = v.intersect([v.union([vSimpleParameter, vNonAsciiStringæøåÆøÅöôêÊ字符串]), v.object({ - baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint16 to be >= 0'), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535'), v.minValue(0)), v.null()]), - qux: v.pipe(v.number(), v.integer(), v.minValue(0, 'Invalid value: Expected uint8 to be >= 0'), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255'), v.minValue(0)) + baz: v.union([v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(65535, 'Invalid value: Expected uint16 to be <= 65535')), v.null()]), + qux: v.pipe(v.number(), v.integer(), v.minValue(0), v.maxValue(255, 'Invalid value: Expected uint8 to be <= 255')) })]); /** diff --git a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-bigint-min-max/valibot.gen.ts b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-bigint-min-max/valibot.gen.ts index cbeb18dc2..5a01074a3 100644 --- a/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-bigint-min-max/valibot.gen.ts +++ b/packages/openapi-ts-tests/main/test/__snapshots__/3.1.x/validators-bigint-min-max/valibot.gen.ts @@ -7,5 +7,5 @@ export const vFoo = v.object({ v.number(), v.string(), v.bigint() - ]), v.transform(x => BigInt(x)), v.minValue(BigInt('-9223372036854775808'), 'Invalid value: Expected int64 to be >= -9223372036854775808'), v.maxValue(BigInt('9223372036854775807'), 'Invalid value: Expected int64 to be <= 9223372036854775807'), v.minValue(BigInt(0)), v.maxValue(BigInt(100)))) + ]), v.transform(x => BigInt(x)), v.minValue(BigInt(0)), v.maxValue(BigInt(100)))) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts index eca782560..8c943fbd9 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -710,8 +710,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z._default(z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(0))), 0), - size: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(1))), + page: z._default(z.optional(z.int().check(z.gte(0), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))), 0), + size: z.optional(z.int().check(z.gte(1), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))), sort: z.optional(z.array(z.string())) }); @@ -1127,10 +1127,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), + z.int().check(z.gte(0), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' })), z.null() ]), - qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) + qux: z.int().check(z.gte(0), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' })) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1138,10 +1138,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), + z.int().check(z.gte(0), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' })), z.null() ]), - qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) + qux: z.int().check(z.gte(0), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' })) })); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts index e9bcaf93a..f12f1b5f4 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -708,8 +708,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0).optional().default(0), - size: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1).optional(), + page: z.number().int().gte(0).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional().default(0), + size: z.number().int().gte(1).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional(), sort: z.array(z.string()).optional() }); @@ -1125,10 +1125,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.number().int().gte(0).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.number().int().gte(0).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1136,10 +1136,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.number().int().gte(0).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.number().int().gte(0).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }) })); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts index 1ff6a0a79..6e36a2eef 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -710,8 +710,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0)).default(0), - size: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1)), + page: z.optional(z.int().gte(0).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })).default(0), + size: z.optional(z.int().gte(1).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })), sort: z.optional(z.array(z.string())) }); @@ -1127,10 +1127,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.int().gte(0).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.int().gte(0).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1138,10 +1138,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.int().gte(0).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.int().gte(0).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }) })); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts index f1c5136f7..66435ffcc 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -707,8 +707,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z._default(z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(0))), 0), - size: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(1))), + page: z._default(z.optional(z.int().check(z.gte(0), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))), 0), + size: z.optional(z.int().check(z.gte(1), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))), sort: z.optional(z.array(z.string())) }); @@ -1133,10 +1133,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), + z.int().check(z.gte(0), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' })), z.null() ]), - qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) + qux: z.int().check(z.gte(0), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' })) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1144,10 +1144,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), + z.int().check(z.gte(0), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' })), z.null() ]), - qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) + qux: z.int().check(z.gte(0), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' })) })); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts index 3e765065d..a413f0991 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import * as z from 'zod/v4-mini'; export const zFoo = z.object({ - foo: z.optional(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), z.gte(BigInt(0)), z.lte(BigInt(100)))) + foo: z.optional(z.coerce.bigint().check(z.gte(BigInt(0)), z.lte(BigInt(100)))) }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts index a13f4f5e8..d61228f60 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -705,8 +705,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0).optional().default(0), - size: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1).optional(), + page: z.number().int().gte(0).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional().default(0), + size: z.number().int().gte(1).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional(), sort: z.array(z.string()).optional() }); @@ -1131,10 +1131,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.number().int().gte(0).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.number().int().gte(0).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1142,10 +1142,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.number().int().gte(0).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.number().int().gte(0).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }) })); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts index f43066307..b9a89eb4e 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import { z } from 'zod'; export const zFoo = z.object({ - foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).gte(BigInt(0)).lte(BigInt(100)).optional() + foo: z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100)).optional() }); diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts index 7b0404494..4caa4137f 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -707,8 +707,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0)).default(0), - size: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1)), + page: z.optional(z.int().gte(0).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })).default(0), + size: z.optional(z.int().gte(1).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })), sort: z.optional(z.array(z.string())) }); @@ -1133,10 +1133,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.int().gte(0).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.int().gte(0).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1144,10 +1144,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.int().gte(0).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.int().gte(0).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }) })); /** diff --git a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts index 142f0a8f3..8f2b8f572 100644 --- a/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v3/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import { z } from 'zod/v4'; export const zFoo = z.object({ - foo: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).gte(BigInt(0)).lte(BigInt(100))) + foo: z.optional(z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100))) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts index 823cd0cb8..38d4da2fe 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/mini/default/zod.gen.ts @@ -710,8 +710,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z._default(z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(0))), 0), - size: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(1))), + page: z._default(z.optional(z.int().check(z.gte(0), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))), 0), + size: z.optional(z.int().check(z.gte(1), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))), sort: z.optional(z.array(z.string())) }); @@ -1127,10 +1127,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), + z.int().check(z.gte(0), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' })), z.null() ]), - qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) + qux: z.int().check(z.gte(0), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' })) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1138,10 +1138,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), + z.int().check(z.gte(0), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' })), z.null() ]), - qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) + qux: z.int().check(z.gte(0), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' })) })); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts index 3dd3645b0..6a2d2968e 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v3/default/zod.gen.ts @@ -708,8 +708,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0).optional().default(0), - size: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1).optional(), + page: z.number().int().gte(0).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional().default(0), + size: z.number().int().gte(1).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional(), sort: z.array(z.string()).optional() }); @@ -1125,10 +1125,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.number().int().gte(0).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.number().int().gte(0).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1136,10 +1136,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.number().int().gte(0).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.number().int().gte(0).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }) })); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts index 9ed580eef..8d36b79aa 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.0.x/v4/default/zod.gen.ts @@ -710,8 +710,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0)).default(0), - size: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1)), + page: z.optional(z.int().gte(0).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })).default(0), + size: z.optional(z.int().gte(1).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })), sort: z.optional(z.array(z.string())) }); @@ -1127,10 +1127,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.int().gte(0).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.int().gte(0).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1138,10 +1138,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.int().gte(0).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.int().gte(0).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }) })); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts index 081f00347..5c3ff1e8f 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/default/zod.gen.ts @@ -707,8 +707,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z._default(z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(0))), 0), - size: z.optional(z.int().check(z.minimum(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }), z.gte(1))), + page: z._default(z.optional(z.int().check(z.gte(0), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))), 0), + size: z.optional(z.int().check(z.gte(1), z.maximum(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }))), sort: z.optional(z.array(z.string())) }); @@ -1133,10 +1133,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), + z.int().check(z.gte(0), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' })), z.null() ]), - qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) + qux: z.int().check(z.gte(0), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' })) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1144,10 +1144,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint16 to be >= 0' }), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.gte(0)), + z.int().check(z.gte(0), z.maximum(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' })), z.null() ]), - qux: z.int().check(z.minimum(0, { error: 'Invalid value: Expected uint8 to be >= 0' }), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' }), z.gte(0)) + qux: z.int().check(z.gte(0), z.maximum(255, { error: 'Invalid value: Expected uint8 to be <= 255' })) })); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts index 53111a6ed..4c7407f99 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/mini/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import * as z from 'zod/mini'; export const zFoo = z.object({ - foo: z.optional(z.coerce.bigint().check(z.minimum(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }), z.maximum(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }), z.gte(BigInt(0)), z.lte(BigInt(100)))) + foo: z.optional(z.coerce.bigint().check(z.gte(BigInt(0)), z.lte(BigInt(100)))) }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts index 1c578caa7..856dbff23 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/default/zod.gen.ts @@ -705,8 +705,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0).optional().default(0), - size: z.number().int().min(-2147483648, { message: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1).optional(), + page: z.number().int().gte(0).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional().default(0), + size: z.number().int().gte(1).max(2147483647, { message: 'Invalid value: Expected int32 to be <= 2147483647' }).optional(), sort: z.array(z.string()).optional() }); @@ -1131,10 +1131,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.number().int().gte(0).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.number().int().gte(0).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1142,10 +1142,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.number().int().min(0, { message: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.number().int().gte(0).max(65535, { message: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.number().int().min(0, { message: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.number().int().gte(0).max(255, { message: 'Invalid value: Expected uint8 to be <= 255' }) })); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts index 93d8d8201..d2ab7d427 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v3/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import { z } from 'zod/v3'; export const zFoo = z.object({ - foo: z.coerce.bigint().min(BigInt('-9223372036854775808'), { message: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { message: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).gte(BigInt(0)).lte(BigInt(100)).optional() + foo: z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100)).optional() }); diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts index a211770dc..b046429d3 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/default/zod.gen.ts @@ -707,8 +707,8 @@ export const zDefault = z.object({ }); export const zPageable = z.object({ - page: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(0)).default(0), - size: z.optional(z.int().min(-2147483648, { error: 'Invalid value: Expected int32 to be >= -2147483648' }).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' }).gte(1)), + page: z.optional(z.int().gte(0).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })).default(0), + size: z.optional(z.int().gte(1).max(2147483647, { error: 'Invalid value: Expected int32 to be <= 2147483647' })), sort: z.optional(z.array(z.string())) }); @@ -1133,10 +1133,10 @@ export const zCompositionWithOneOfAndProperties = z.intersection(z.union([ }) ]), z.object({ baz: z.union([ - z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.int().gte(0).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.int().gte(0).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }) })); export const zModelWithOneOfAndProperties = z.intersection(z.union([ @@ -1144,10 +1144,10 @@ export const zModelWithOneOfAndProperties = z.intersection(z.union([ zNonAsciiStringæøåÆøÅöôêÊ字符串 ]), z.object({ baz: z.union([ - z.int().min(0, { error: 'Invalid value: Expected uint16 to be >= 0' }).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }).gte(0), + z.int().gte(0).max(65535, { error: 'Invalid value: Expected uint16 to be <= 65535' }), z.null() ]), - qux: z.int().min(0, { error: 'Invalid value: Expected uint8 to be >= 0' }).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }).gte(0) + qux: z.int().gte(0).max(255, { error: 'Invalid value: Expected uint8 to be <= 255' }) })); /** diff --git a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts index a05845133..f04eccbf2 100644 --- a/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts +++ b/packages/openapi-ts-tests/zod/v4/__snapshots__/3.1.x/v4/validators-bigint-min-max/zod.gen.ts @@ -3,5 +3,5 @@ import { z } from 'zod'; export const zFoo = z.object({ - foo: z.optional(z.coerce.bigint().min(BigInt('-9223372036854775808'), { error: 'Invalid value: Expected int64 to be >= -9223372036854775808' }).max(BigInt('9223372036854775807'), { error: 'Invalid value: Expected int64 to be <= 9223372036854775807' }).gte(BigInt(0)).lte(BigInt(100))) + foo: z.optional(z.coerce.bigint().gte(BigInt(0)).lte(BigInt(100))) }); diff --git a/packages/openapi-ts/src/plugins/valibot/types.d.ts b/packages/openapi-ts/src/plugins/valibot/types.d.ts index ee01cc71d..f79490647 100644 --- a/packages/openapi-ts/src/plugins/valibot/types.d.ts +++ b/packages/openapi-ts/src/plugins/valibot/types.d.ts @@ -334,6 +334,7 @@ type SharedResolverArgs = DollarTsDsl & { */ pipes: Array>; plugin: ValibotPlugin['Instance']; + v: Symbol; }; export type FormatResolverArgs = SharedResolverArgs & { @@ -347,10 +348,11 @@ export type ObjectBaseResolverArgs = SharedResolverArgs & { shape: ReturnType; }; +type ResolverResult = boolean | number; + export type ValidatorResolverArgs = SharedResolverArgs & { operation: IR.Operation; schema: Symbol; - v: Symbol; }; type ValidatorResolver = ( @@ -365,6 +367,12 @@ type Resolvers = Plugin.Resolvers<{ * per-format handling. */ number?: { + /** + * Controls the base segment for number schemas. + * + * Returning `undefined` will execute the default resolver logic. + */ + base?: (args: FormatResolverArgs) => ResolverResult | undefined; /** * Resolvers for number formats (e.g., `float`, `double`, `int32`). * @@ -378,7 +386,7 @@ type Resolvers = Plugin.Resolvers<{ */ formats?: Record< string, - (args: FormatResolverArgs) => boolean | number | undefined + (args: FormatResolverArgs) => ResolverResult | undefined >; }; /** @@ -401,9 +409,7 @@ type Resolvers = Plugin.Resolvers<{ * * Returning `undefined` will execute the default resolver logic. */ - base?: ( - args: ObjectBaseResolverArgs, - ) => ReturnType | undefined; + base?: (args: ObjectBaseResolverArgs) => ResolverResult | undefined; }; /** * Resolvers for string schemas. @@ -425,7 +431,7 @@ type Resolvers = Plugin.Resolvers<{ */ formats?: Record< string, - (args: FormatResolverArgs) => boolean | number | undefined + (args: FormatResolverArgs) => ResolverResult | undefined >; }; /** diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/number.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/number.ts index f4aab05a0..9372684e4 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/number.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/number.ts @@ -8,27 +8,14 @@ import { $ } from '~/ts-dsl'; import { pipesToAst } from '../../shared/pipesToAst'; import type { IrSchemaToAstOptions } from '../../shared/types'; +import type { FormatResolverArgs } from '../../types'; import { identifiers } from '../constants'; -export const numberToAst = ({ - plugin, +const defaultBaseResolver = ({ + pipes, schema, -}: IrSchemaToAstOptions & { - schema: SchemaWithType<'integer' | 'number'>; -}) => { - const v = plugin.referenceSymbol({ - category: 'external', - resource: 'valibot.v', - }); - - if (schema.const !== undefined) { - return $(v) - .attr(identifiers.schemas.literal) - .call(maybeBigInt(schema.const, schema.format)); - } - - const pipes: Array> = []; - + v, +}: FormatResolverArgs): boolean | number => { if (shouldCoerceToBigInt(schema.format)) { pipes.push( $(v) @@ -51,6 +38,32 @@ export const numberToAst = ({ } } + return true; +}; + +export const numberToAst = ({ + plugin, + schema, +}: IrSchemaToAstOptions & { + schema: SchemaWithType<'integer' | 'number'>; +}) => { + const v = plugin.referenceSymbol({ + category: 'external', + resource: 'valibot.v', + }); + + if (schema.const !== undefined) { + return $(v) + .attr(identifiers.schemas.literal) + .call(maybeBigInt(schema.const, schema.format)); + } + + const pipes: Array> = []; + + const args: FormatResolverArgs = { $, pipes, plugin, schema, v }; + const resolver = plugin.config['~resolvers']?.number?.base; + if (!resolver?.(args)) defaultBaseResolver(args); + let hasLowerBound = false; let hasUpperBound = false; diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts index e2a4af103..633d45c4f 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/object.ts @@ -9,17 +9,12 @@ import type { ObjectBaseResolverArgs } from '../../types'; import { identifiers } from '../constants'; import { irSchemaToAst } from '../plugin'; -function defaultObjectBaseResolver({ +function defaultBaseResolver({ additional, pipes, - plugin, shape, + v, }: ObjectBaseResolverArgs): number { - const v = plugin.referenceSymbol({ - category: 'external', - resource: 'valibot.v', - }); - // Handle `additionalProperties: { type: 'never' }` → v.strictObject() if (additional === null) { return pipes.push($(v).attr(identifiers.schemas.strictObject).call(shape)); @@ -52,6 +47,11 @@ export const objectToAst = ({ }: IrSchemaToAstOptions & { schema: SchemaWithType<'object'>; }): Omit => { + const v = plugin.referenceSymbol({ + category: 'external', + resource: 'valibot.v', + }); + const result: Partial> = {}; const pipes: Array> = []; @@ -103,9 +103,10 @@ export const objectToAst = ({ plugin, schema, shape, + v, }; const resolver = plugin.config['~resolvers']?.object?.base; - if (!resolver?.(args)) defaultObjectBaseResolver(args); + if (!resolver?.(args)) defaultBaseResolver(args); result.pipes = [pipesToAst(pipes, plugin)]; return result as Omit; diff --git a/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts b/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts index 13884df71..4f5399083 100644 --- a/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts +++ b/packages/openapi-ts/src/plugins/valibot/v1/toAst/string.ts @@ -8,14 +8,9 @@ import { identifiers } from '../constants'; const defaultFormatResolver = ({ pipes, - plugin, schema, + v, }: FormatResolverArgs): boolean | number => { - const v = plugin.referenceSymbol({ - category: 'external', - resource: 'valibot.v', - }); - switch (schema.format) { case 'date': return pipes.push($(v).attr(identifiers.actions.isoDate).call()); @@ -55,7 +50,7 @@ export const stringToAst = ({ const pipes = [$(v).attr(identifiers.schemas.string).call()]; if (schema.format) { - const args: FormatResolverArgs = { $, pipes, plugin, schema }; + const args: FormatResolverArgs = { $, pipes, plugin, schema, v }; const resolver = plugin.config['~resolvers']?.string?.formats?.[schema.format]; if (!resolver?.(args)) defaultFormatResolver(args); diff --git a/packages/openapi-ts/src/plugins/zod/mini/api.ts b/packages/openapi-ts/src/plugins/zod/mini/api.ts index 41755b8c5..f90894ecc 100644 --- a/packages/openapi-ts/src/plugins/zod/mini/api.ts +++ b/packages/openapi-ts/src/plugins/zod/mini/api.ts @@ -22,12 +22,17 @@ export const createRequestValidatorMini = ({ }); if (!symbol) return; + const z = plugin.referenceSymbol({ + category: 'external', + resource: 'zod.z', + }); const args: ValidatorResolverArgs = { $, chain: undefined, operation, plugin, schema: symbol, + z, }; const validator = plugin.config['~resolvers']?.validator; const resolver = @@ -59,12 +64,17 @@ export const createResponseValidatorMini = ({ }); if (!symbol) return; + const z = plugin.referenceSymbol({ + category: 'external', + resource: 'zod.z', + }); const args: ValidatorResolverArgs = { $, chain: undefined, operation, plugin, schema: symbol, + z, }; const validator = plugin.config['~resolvers']?.validator; const resolver = diff --git a/packages/openapi-ts/src/plugins/zod/mini/toAst/object.ts b/packages/openapi-ts/src/plugins/zod/mini/toAst/object.ts index 74a9cc0fb..0b7f593e2 100644 --- a/packages/openapi-ts/src/plugins/zod/mini/toAst/object.ts +++ b/packages/openapi-ts/src/plugins/zod/mini/toAst/object.ts @@ -8,16 +8,11 @@ import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; import type { ObjectBaseResolverArgs } from '../../types'; import { irSchemaToAst } from '../plugin'; -function defaultObjectBaseResolver({ +function defaultBaseResolver({ additional, - plugin, shape, + z, }: ObjectBaseResolverArgs): ReturnType { - const z = plugin.referenceSymbol({ - category: 'external', - resource: 'zod.z', - }); - if (additional) { return $(z) .attr(identifiers.record) @@ -34,6 +29,11 @@ export const objectToAst = ({ }: IrSchemaToAstOptions & { schema: SchemaWithType<'object'>; }): Omit => { + const z = plugin.referenceSymbol({ + category: 'external', + resource: 'zod.z', + }); + const result: Partial> = {}; // TODO: parser - handle constants @@ -89,9 +89,10 @@ export const objectToAst = ({ plugin, schema, shape, + z, }; const resolver = plugin.config['~resolvers']?.object?.base; - const chain = resolver?.(args) ?? defaultObjectBaseResolver(args); + const chain = resolver?.(args) ?? defaultBaseResolver(args); result.expression = chain; return result as Omit; diff --git a/packages/openapi-ts/src/plugins/zod/mini/toAst/string.ts b/packages/openapi-ts/src/plugins/zod/mini/toAst/string.ts index 9f6bd204d..616db1a68 100644 --- a/packages/openapi-ts/src/plugins/zod/mini/toAst/string.ts +++ b/packages/openapi-ts/src/plugins/zod/mini/toAst/string.ts @@ -71,7 +71,7 @@ export const stringToAst = ({ chain = $(z).attr(identifiers.string).call(); if (schema.format) { - const args: FormatResolverArgs = { $, chain, plugin, schema }; + const args: FormatResolverArgs = { $, chain, plugin, schema, z }; const resolver = plugin.config['~resolvers']?.string?.formats?.[schema.format]; chain = resolver?.(args) ?? defaultFormatResolver(args); diff --git a/packages/openapi-ts/src/plugins/zod/types.d.ts b/packages/openapi-ts/src/plugins/zod/types.d.ts index 28baeb3d5..7709ef049 100644 --- a/packages/openapi-ts/src/plugins/zod/types.d.ts +++ b/packages/openapi-ts/src/plugins/zod/types.d.ts @@ -759,6 +759,7 @@ type SharedResolverArgs = DollarTsDsl & { */ chain?: ReturnType; plugin: ZodPlugin['Instance']; + z: Symbol; }; export type FormatResolverArgs = Required & { @@ -772,6 +773,8 @@ export type ObjectBaseResolverArgs = SharedResolverArgs & { shape: ReturnType; }; +type ResolverResult = boolean | number; + export type ValidatorResolverArgs = SharedResolverArgs & { operation: IR.Operation; schema: Symbol; @@ -789,6 +792,12 @@ type Resolvers = Plugin.Resolvers<{ * per-format handling. */ number?: { + /** + * Controls the base segment for number schemas. + * + * Returning `undefined` will execute the default resolver logic. + */ + base?: (args: FormatResolverArgs) => ResolverResult | undefined; /** * Resolvers for number formats (e.g., `float`, `double`, `int32`). * @@ -802,7 +811,7 @@ type Resolvers = Plugin.Resolvers<{ */ formats?: Record< string, - (args: FormatResolverArgs) => boolean | number | undefined + (args: FormatResolverArgs) => ResolverResult | undefined >; }; /** diff --git a/packages/openapi-ts/src/plugins/zod/v3/api.ts b/packages/openapi-ts/src/plugins/zod/v3/api.ts index 5da1117b5..9c535342f 100644 --- a/packages/openapi-ts/src/plugins/zod/v3/api.ts +++ b/packages/openapi-ts/src/plugins/zod/v3/api.ts @@ -22,12 +22,17 @@ export const createRequestValidatorV3 = ({ }); if (!symbol) return; + const z = plugin.referenceSymbol({ + category: 'external', + resource: 'zod.z', + }); const args: ValidatorResolverArgs = { $, chain: undefined, operation, plugin, schema: symbol, + z, }; const validator = plugin.config['~resolvers']?.validator; const resolver = @@ -59,12 +64,17 @@ export const createResponseValidatorV3 = ({ }); if (!symbol) return; + const z = plugin.referenceSymbol({ + category: 'external', + resource: 'zod.z', + }); const args: ValidatorResolverArgs = { $, chain: undefined, operation, plugin, schema: symbol, + z, }; const validator = plugin.config['~resolvers']?.validator; const resolver = diff --git a/packages/openapi-ts/src/plugins/zod/v3/toAst/object.ts b/packages/openapi-ts/src/plugins/zod/v3/toAst/object.ts index ed9194192..80299e204 100644 --- a/packages/openapi-ts/src/plugins/zod/v3/toAst/object.ts +++ b/packages/openapi-ts/src/plugins/zod/v3/toAst/object.ts @@ -8,16 +8,11 @@ import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; import type { ObjectBaseResolverArgs } from '../../types'; import { irSchemaToAst } from '../plugin'; -function defaultObjectBaseResolver({ +function defaultBaseResolver({ additional, - plugin, shape, + z, }: ObjectBaseResolverArgs): ReturnType { - const z = plugin.referenceSymbol({ - category: 'external', - resource: 'zod.z', - }); - if (additional) { return $(z).attr(identifiers.record).call(additional); } @@ -34,6 +29,11 @@ export const objectToAst = ({ }): Omit & { anyType?: string; } => { + const z = plugin.referenceSymbol({ + category: 'external', + resource: 'zod.z', + }); + let hasLazyExpression = false; // TODO: parser - handle constants @@ -85,9 +85,10 @@ export const objectToAst = ({ plugin, schema, shape, + z, }; const resolver = plugin.config['~resolvers']?.object?.base; - const chain = resolver?.(args) ?? defaultObjectBaseResolver(args); + const chain = resolver?.(args) ?? defaultBaseResolver(args); result.expression = chain; return { diff --git a/packages/openapi-ts/src/plugins/zod/v3/toAst/string.ts b/packages/openapi-ts/src/plugins/zod/v3/toAst/string.ts index d147b4445..9e537026f 100644 --- a/packages/openapi-ts/src/plugins/zod/v3/toAst/string.ts +++ b/packages/openapi-ts/src/plugins/zod/v3/toAst/string.ts @@ -62,7 +62,7 @@ export const stringToAst = ({ chain = $(z).attr(identifiers.string).call(); if (schema.format) { - const args: FormatResolverArgs = { $, chain, plugin, schema }; + const args: FormatResolverArgs = { $, chain, plugin, schema, z }; const resolver = plugin.config['~resolvers']?.string?.formats?.[schema.format]; chain = resolver?.(args) ?? defaultFormatResolver(args); diff --git a/packages/openapi-ts/src/plugins/zod/v4/api.ts b/packages/openapi-ts/src/plugins/zod/v4/api.ts index 8e82ee81f..9feba80dc 100644 --- a/packages/openapi-ts/src/plugins/zod/v4/api.ts +++ b/packages/openapi-ts/src/plugins/zod/v4/api.ts @@ -22,12 +22,17 @@ export const createRequestValidatorV4 = ({ }); if (!symbol) return; + const z = plugin.referenceSymbol({ + category: 'external', + resource: 'zod.z', + }); const args: ValidatorResolverArgs = { $, chain: undefined, operation, plugin, schema: symbol, + z, }; const validator = plugin.config['~resolvers']?.validator; const resolver = @@ -59,12 +64,17 @@ export const createResponseValidatorV4 = ({ }); if (!symbol) return; + const z = plugin.referenceSymbol({ + category: 'external', + resource: 'zod.z', + }); const args: ValidatorResolverArgs = { $, chain: undefined, operation, plugin, schema: symbol, + z, }; const validator = plugin.config['~resolvers']?.validator; const resolver = diff --git a/packages/openapi-ts/src/plugins/zod/v4/toAst/object.ts b/packages/openapi-ts/src/plugins/zod/v4/toAst/object.ts index 69d13fe09..528d7096f 100644 --- a/packages/openapi-ts/src/plugins/zod/v4/toAst/object.ts +++ b/packages/openapi-ts/src/plugins/zod/v4/toAst/object.ts @@ -8,16 +8,11 @@ import type { Ast, IrSchemaToAstOptions } from '../../shared/types'; import type { ObjectBaseResolverArgs } from '../../types'; import { irSchemaToAst } from '../plugin'; -function defaultObjectBaseResolver({ +function defaultBaseResolver({ additional, - plugin, shape, + z, }: ObjectBaseResolverArgs): ReturnType { - const z = plugin.referenceSymbol({ - category: 'external', - resource: 'zod.z', - }); - if (additional) { return $(z) .attr(identifiers.record) @@ -34,6 +29,11 @@ export const objectToAst = ({ }: IrSchemaToAstOptions & { schema: SchemaWithType<'object'>; }): Omit => { + const z = plugin.referenceSymbol({ + category: 'external', + resource: 'zod.z', + }); + const result: Partial> = {}; // TODO: parser - handle constants @@ -89,9 +89,10 @@ export const objectToAst = ({ plugin, schema, shape, + z, }; const resolver = plugin.config['~resolvers']?.object?.base; - const chain = resolver?.(args) ?? defaultObjectBaseResolver(args); + const chain = resolver?.(args) ?? defaultBaseResolver(args); result.expression = chain; // Return with typeName for circular references diff --git a/packages/openapi-ts/src/plugins/zod/v4/toAst/string.ts b/packages/openapi-ts/src/plugins/zod/v4/toAst/string.ts index 84eda4bc1..744e759db 100644 --- a/packages/openapi-ts/src/plugins/zod/v4/toAst/string.ts +++ b/packages/openapi-ts/src/plugins/zod/v4/toAst/string.ts @@ -9,12 +9,8 @@ const defaultFormatResolver = ({ chain, plugin, schema, + z, }: FormatResolverArgs): ReturnType => { - const z = plugin.referenceSymbol({ - category: 'external', - resource: 'zod.z', - }); - switch (schema.format) { case 'date': return $(z).attr(identifiers.iso).attr(identifiers.date).call(); @@ -71,7 +67,7 @@ export const stringToAst = ({ chain = $(z).attr(identifiers.string).call(); if (schema.format) { - const args: FormatResolverArgs = { $, chain, plugin, schema }; + const args: FormatResolverArgs = { $, chain, plugin, schema, z }; const resolver = plugin.config['~resolvers']?.string?.formats?.[schema.format]; chain = resolver?.(args) ?? defaultFormatResolver(args); -- 2.51.2