Skip to content

Commit 6226f6f

Browse files
committed
feat(validators): expose validator resolvers
1 parent e73bc32 commit 6226f6f

File tree

81 files changed

+727
-838
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+727
-838
lines changed

.changeset/proud-pears-share.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+
**valibot**: expose validator resolvers

.changeset/silver-rats-invent.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+
**zod**: expose validator resolvers

dev/openapi-ts.config.ts

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-unused-vars */
1+
/* eslint-disable @typescript-eslint/no-unused-vars, arrow-body-style */
22
// @ts-ignore
33
import path from 'node:path';
44

@@ -13,7 +13,6 @@ import { myClientPlugin } from '../packages/openapi-ts-tests/main/test/custom/cl
1313
import { getSpecsPath } from '../packages/openapi-ts-tests/utils';
1414

1515
// @ts-ignore
16-
// eslint-disable-next-line arrow-body-style
1716
export default defineConfig(() => {
1817
// ...
1918
return [
@@ -41,14 +40,14 @@ export default defineConfig(() => {
4140
// 'circular.yaml',
4241
// 'dutchie.json',
4342
// 'invalid',
44-
'full.yaml',
43+
// 'full.yaml',
4544
// 'openai.yaml',
4645
// 'opencode.yaml',
4746
// 'sdk-instance.yaml',
4847
// 'string-with-format.yaml',
4948
// 'transformers.json',
5049
// 'type-format.yaml',
51-
// 'validators.yaml',
50+
'validators.yaml',
5251
// 'validators-circular-ref.json',
5352
// 'validators-circular-ref-2.yaml',
5453
// 'zoom-video-sdk.json',
@@ -270,7 +269,7 @@ export default defineConfig(() => {
270269
// signature: 'object',
271270
// transformer: '@hey-api/transformers',
272271
transformer: true,
273-
validator: 'zod',
272+
validator: 'valibot',
274273
// validator: {
275274
// request: 'zod',
276275
// response: 'zod',
@@ -410,12 +409,23 @@ export default defineConfig(() => {
410409
// 'date-time': ({ $, pipes }) => pipes.push($('v').attr('isoDateTime').call()),
411410
},
412411
},
412+
validator({ $, schema, v }) {
413+
return [
414+
$.const('parsed').assign(
415+
$(v.placeholder)
416+
.attr('safeParseAsync')
417+
.call(schema.placeholder, 'data')
418+
.await(),
419+
),
420+
$('parsed').return(),
421+
];
422+
},
413423
},
414424
},
415425
{
416426
// case: 'snake_case',
417427
// comments: false,
418-
compatibilityVersion: 4,
428+
compatibilityVersion: 'mini',
419429
dates: {
420430
// local: true,
421431
// offset: true,
@@ -427,7 +437,7 @@ export default defineConfig(() => {
427437
// },
428438
},
429439
// exportFromIndex: true,
430-
// metadata: true,
440+
metadata: true,
431441
name: 'zod',
432442
// requests: {
433443
// // case: 'SCREAMING_SNAKE_CASE',
@@ -465,20 +475,31 @@ export default defineConfig(() => {
465475
},
466476
'~resolvers': {
467477
object: {
468-
base({ $, additional, shape }) {
469-
if (!additional) {
470-
// return $('z').attr('object').call(shape).attr('passthrough').call()
471-
return $('z').attr('looseObject').call(shape);
472-
}
473-
return;
474-
},
478+
// base({ $, additional, shape }) {
479+
// if (!additional) {
480+
// // return $('z').attr('object').call(shape).attr('passthrough').call()
481+
// return $('z').attr('object').call(shape).attr('strict').call();
482+
// }
483+
// return;
484+
// },
475485
},
476486
string: {
477487
formats: {
478488
// date: ({ $ }) => $('z').attr('date').call(),
479489
// 'date-time': ({ $ }) => $('z').attr('date').call(),
480490
},
481491
},
492+
validator({ $, schema }) {
493+
return [
494+
$.const('parsed').assign(
495+
$(schema.placeholder)
496+
.attr('safeParseAsync')
497+
.call('data')
498+
.await(),
499+
),
500+
$('parsed').return(),
501+
];
502+
},
482503
},
483504
},
484505
{

packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/mini/default/zod.gen.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,7 @@ export const zModelWithDictionary = z.object({
294294
*/
295295
export const zModelWithCircularReference = z.object({
296296
get prop() {
297-
return z.optional(z.lazy((): any => {
298-
return zModelWithCircularReference;
299-
}));
297+
return z.optional(z.lazy((): any => zModelWithCircularReference));
300298
}
301299
});
302300

packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v3/default/zod.gen.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,7 @@ export const zModelWithDictionary = z.object({
293293
* This is a model with one property containing a circular reference
294294
*/
295295
export const zModelWithCircularReference: z.AnyZodObject = z.object({
296-
prop: z.lazy(() => {
297-
return zModelWithCircularReference;
298-
}).optional()
296+
prop: z.lazy(() => zModelWithCircularReference).optional()
299297
});
300298

301299
/**

packages/openapi-ts-tests/zod/v3/__snapshots__/2.0.x/v4/default/zod.gen.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,7 @@ export const zModelWithDictionary = z.object({
294294
*/
295295
export const zModelWithCircularReference = z.object({
296296
get prop() {
297-
return z.optional(z.lazy((): any => {
298-
return zModelWithCircularReference;
299-
}));
297+
return z.optional(z.lazy((): any => zModelWithCircularReference));
300298
}
301299
});
302300

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/circular/zod.gen.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,29 @@ import * as z from 'zod/v4-mini';
44

55
export const zFoo = z.object({
66
get quux() {
7-
return z.optional(z.lazy((): any => {
8-
return zQuux;
9-
}));
7+
return z.optional(z.lazy((): any => zQuux));
108
}
119
});
1210

1311
export const zBar = z.object({
1412
get bar() {
15-
return z.optional(z.lazy((): any => {
16-
return zBar;
17-
}));
13+
return z.optional(z.lazy((): any => zBar));
1814
},
1915
get baz() {
20-
return z.optional(z.lazy((): any => {
21-
return zBaz;
22-
}));
16+
return z.optional(z.lazy((): any => zBaz));
2317
}
2418
});
2519

2620
export const zBaz = z.object({
2721
get quux() {
28-
return z.optional(z.lazy((): any => {
29-
return zQuux;
30-
}));
22+
return z.optional(z.lazy((): any => zQuux));
3123
}
3224
});
3325

3426
export const zQux = z.union([
3527
z.intersection(z.object({
3628
type: z.literal("struct")
37-
}), z.lazy(() => {
38-
return z.lazy((): any => {
39-
return zCorge;
40-
});
41-
})),
29+
}), z.lazy(() => z.lazy((): any => zCorge))),
4230
z.intersection(z.object({
4331
type: z.literal("array")
4432
}), zFoo)

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/default/zod.gen.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,7 @@ export const zDeprecatedModel = z.object({
400400
*/
401401
export const zModelWithCircularReference = z.object({
402402
get prop() {
403-
return z.optional(z.lazy((): any => {
404-
return zModelWithCircularReference;
405-
}));
403+
return z.optional(z.lazy((): any => zModelWithCircularReference));
406404
}
407405
});
408406

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/mini/validators/zod.gen.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ export const zFoo = z._default(z.union([
88
z.object({
99
foo: z.optional(z.string().check(z.regex(/^\d{3}-\d{2}-\d{4}$/))),
1010
get bar() {
11-
return z.optional(z.lazy((): any => {
12-
return zBar;
13-
}));
11+
return z.optional(z.lazy((): any => zBar));
1412
},
1513
get baz() {
16-
return z.optional(z.array(z.lazy((): any => {
17-
return zFoo;
18-
})));
14+
return z.optional(z.array(z.lazy((): any => zFoo)));
1915
},
2016
qux: z._default(z.optional(z.int().check(z.gt(0))), 0)
2117
}),

packages/openapi-ts-tests/zod/v3/__snapshots__/3.0.x/v3/circular/zod.gen.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,22 @@
33
import { z } from 'zod';
44

55
export const zFoo: z.AnyZodObject = z.object({
6-
quux: z.lazy(() => {
7-
return zQuux;
8-
}).optional()
6+
quux: z.lazy(() => zQuux).optional()
97
});
108

119
export const zBar: z.AnyZodObject = z.object({
12-
bar: z.lazy(() => {
13-
return zBar;
14-
}).optional(),
15-
baz: z.lazy(() => {
16-
return zBaz;
17-
}).optional()
10+
bar: z.lazy(() => zBar).optional(),
11+
baz: z.lazy(() => zBaz).optional()
1812
});
1913

2014
export const zBaz: z.AnyZodObject = z.object({
21-
quux: z.lazy(() => {
22-
return zQuux;
23-
}).optional()
15+
quux: z.lazy(() => zQuux).optional()
2416
});
2517

2618
export const zQux: z.ZodTypeAny = z.union([
2719
z.object({
2820
type: z.literal("struct")
29-
}).and(z.lazy(() => {
30-
return zCorge;
31-
})),
21+
}).and(z.lazy(() => zCorge)),
3222
z.object({
3323
type: z.literal("array")
3424
}).and(zFoo)

0 commit comments

Comments
 (0)