@kubb/plugin-zod 3.2.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-NOXYTLKS.cjs → chunk-3GKEJ22H.cjs} +8 -6
- package/dist/chunk-3GKEJ22H.cjs.map +1 -0
- package/dist/{chunk-SGDZKF6Z.js → chunk-FVOT2O3G.js} +26 -13
- package/dist/chunk-FVOT2O3G.js.map +1 -0
- package/dist/{chunk-YMVA7BZZ.js → chunk-XZM3WHFN.js} +5 -3
- package/dist/chunk-XZM3WHFN.js.map +1 -0
- package/dist/{chunk-D2WPMTC7.cjs → chunk-Y7GXPHOG.cjs} +26 -13
- package/dist/chunk-Y7GXPHOG.cjs.map +1 -0
- package/dist/components.cjs +3 -3
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.js +2 -2
- package/dist/index.cjs +4 -4
- package/dist/index.js +2 -2
- package/dist/utils.cjs +4 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +15 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.js +3 -0
- package/dist/utils.js.map +1 -0
- package/package.json +19 -10
- package/src/components/Zod.tsx +13 -10
- package/src/generators/__snapshots__/anyof.ts +14 -2
- package/src/generators/__snapshots__/coercion.ts +13 -2
- package/src/generators/__snapshots__/coercionDates.ts +13 -2
- package/src/generators/__snapshots__/coercionNumbers.ts +13 -2
- package/src/generators/__snapshots__/coercionStrings.ts +13 -2
- package/src/generators/__snapshots__/createPet.ts +10 -7
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +10 -7
- package/src/generators/__snapshots__/deletePet.ts +2 -2
- package/src/generators/__snapshots__/discriminator.ts +31 -2
- package/src/generators/__snapshots__/enumBooleanLiteral.ts +2 -2
- package/src/generators/__snapshots__/enumNamesType.ts +2 -2
- package/src/generators/__snapshots__/enumNullable.ts +2 -2
- package/src/generators/__snapshots__/enumSingleLiteral.ts +2 -2
- package/src/generators/__snapshots__/enumVarNamesType.ts +2 -2
- package/src/generators/__snapshots__/example.ts +4 -2
- package/src/generators/__snapshots__/getPets.ts +12 -7
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +7 -3
- package/src/generators/__snapshots__/nullableString.ts +2 -2
- package/src/generators/__snapshots__/nullableStringUuid.ts +2 -2
- package/src/generators/__snapshots__/nullableStringWithAnyOf.ts +2 -2
- package/src/generators/__snapshots__/numberValueConst.ts +7 -3
- package/src/generators/__snapshots__/oneof.ts +9 -2
- package/src/generators/__snapshots__/operations.ts +61 -44
- package/src/generators/__snapshots__/optionalPetInfer.ts +7 -3
- package/src/generators/__snapshots__/optionalPetTyped.ts +7 -2
- package/src/generators/__snapshots__/order.ts +9 -2
- package/src/generators/__snapshots__/orderDateTypeFalse.ts +9 -2
- package/src/generators/__snapshots__/orderDateTypeString.ts +9 -2
- package/src/generators/__snapshots__/pet.ts +13 -2
- package/src/generators/__snapshots__/petArray.ts +7 -3
- package/src/generators/__snapshots__/petCoercion.ts +13 -2
- package/src/generators/__snapshots__/petTupleObject.ts +7 -3
- package/src/generators/__snapshots__/petWithMapper.ts +13 -2
- package/src/generators/__snapshots__/pets.ts +9 -2
- package/src/generators/__snapshots__/recursive.ts +5 -2
- package/src/generators/__snapshots__/showPetById.ts +10 -7
- package/src/generators/__snapshots__/stringValueConst.ts +7 -3
- package/src/generators/__snapshots__/toy.ts +8 -2
- package/src/generators/__snapshots__/uuidSchema.ts +2 -2
- package/src/generators/zodGenerator.tsx +2 -0
- package/src/{parser/index.ts → parser.ts} +19 -5
- package/src/utils/ToZod.ts +28 -0
- package/src/utils/index.ts +1 -0
- package/dist/chunk-D2WPMTC7.cjs.map +0 -1
- package/dist/chunk-NOXYTLKS.cjs.map +0 -1
- package/dist/chunk-SGDZKF6Z.js.map +0 -1
- package/dist/chunk-YMVA7BZZ.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"utils.cjs"}
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ZodArray, ZodNullable, ZodOptional, ZodType, ZodDefault, ZodEffects } from 'zod';
|
|
2
|
+
|
|
3
|
+
type IsNullable<T> = Extract<T, null> extends never ? false : true;
|
|
4
|
+
type IsOptional<T> = Extract<T, undefined> extends never ? false : true;
|
|
5
|
+
type ZodWithEffects<T> = T | ZodType<T> | ZodDefault<T extends ZodType ? T : ZodType<T>> | ZodEffects<T extends ZodType ? T : ZodType<T>, any, any>;
|
|
6
|
+
/**
|
|
7
|
+
* See https://github.com/colinhacks/tozod/blob/master/src/index.ts
|
|
8
|
+
* Adapted based on https://github.com/colinhacks/zod/issues/372
|
|
9
|
+
*/
|
|
10
|
+
type ToZod<T> = T extends any[] ? ZodArray<ToZod<T[number]>> : T extends Record<string, any> ? {
|
|
11
|
+
[K in keyof T]-?: T[K] extends any[] ? ZodArray<ToZod<T[K][number]>> : ToZodSchemaPrimitive<T[K]>;
|
|
12
|
+
} : ZodWithEffects<T>;
|
|
13
|
+
type ToZodSchemaPrimitive<T> = IsNullable<T> extends true ? IsOptional<T> extends true ? ZodWithEffects<ZodNullable<ZodOptional<ZodType<Exclude<Exclude<T, null>, undefined>>>>> | ZodWithEffects<ZodOptional<ZodNullable<ZodType<Exclude<Exclude<T, null>, undefined>>>>> : ZodWithEffects<ZodNullable<ZodType<Exclude<T, null>>>> : IsOptional<T> extends true ? ZodWithEffects<ZodOptional<ZodType<Exclude<T, undefined>>>> | ZodWithEffects<ZodDefault<ZodType<Exclude<T, undefined>>>> : ZodWithEffects<T>;
|
|
14
|
+
|
|
15
|
+
export type { ToZod };
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ZodArray, ZodNullable, ZodOptional, ZodType, ZodDefault, ZodEffects } from 'zod';
|
|
2
|
+
|
|
3
|
+
type IsNullable<T> = Extract<T, null> extends never ? false : true;
|
|
4
|
+
type IsOptional<T> = Extract<T, undefined> extends never ? false : true;
|
|
5
|
+
type ZodWithEffects<T> = T | ZodType<T> | ZodDefault<T extends ZodType ? T : ZodType<T>> | ZodEffects<T extends ZodType ? T : ZodType<T>, any, any>;
|
|
6
|
+
/**
|
|
7
|
+
* See https://github.com/colinhacks/tozod/blob/master/src/index.ts
|
|
8
|
+
* Adapted based on https://github.com/colinhacks/zod/issues/372
|
|
9
|
+
*/
|
|
10
|
+
type ToZod<T> = T extends any[] ? ZodArray<ToZod<T[number]>> : T extends Record<string, any> ? {
|
|
11
|
+
[K in keyof T]-?: T[K] extends any[] ? ZodArray<ToZod<T[K][number]>> : ToZodSchemaPrimitive<T[K]>;
|
|
12
|
+
} : ZodWithEffects<T>;
|
|
13
|
+
type ToZodSchemaPrimitive<T> = IsNullable<T> extends true ? IsOptional<T> extends true ? ZodWithEffects<ZodNullable<ZodOptional<ZodType<Exclude<Exclude<T, null>, undefined>>>>> | ZodWithEffects<ZodOptional<ZodNullable<ZodType<Exclude<Exclude<T, null>, undefined>>>>> : ZodWithEffects<ZodNullable<ZodType<Exclude<T, null>>>> : IsOptional<T> extends true ? ZodWithEffects<ZodOptional<ZodType<Exclude<T, undefined>>>> | ZodWithEffects<ZodDefault<ZodType<Exclude<T, undefined>>>> : ZodWithEffects<T>;
|
|
14
|
+
|
|
15
|
+
export type { ToZod };
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"utils.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Generator plugin-zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -35,6 +35,11 @@
|
|
|
35
35
|
"require": "./dist/components.cjs",
|
|
36
36
|
"default": "./dist/components.cjs"
|
|
37
37
|
},
|
|
38
|
+
"./utils": {
|
|
39
|
+
"import": "./dist/utils.js",
|
|
40
|
+
"require": "./dist/utils.cjs",
|
|
41
|
+
"default": "./dist/utils.cjs"
|
|
42
|
+
},
|
|
38
43
|
"./package.json": "./package.json",
|
|
39
44
|
"./*": "./*"
|
|
40
45
|
},
|
|
@@ -48,6 +53,9 @@
|
|
|
48
53
|
],
|
|
49
54
|
"generators": [
|
|
50
55
|
"./dist/generators.d.ts"
|
|
56
|
+
],
|
|
57
|
+
"utils": [
|
|
58
|
+
"./dist/utils.d.ts"
|
|
51
59
|
]
|
|
52
60
|
}
|
|
53
61
|
},
|
|
@@ -58,18 +66,19 @@
|
|
|
58
66
|
"!/**/__tests__/**"
|
|
59
67
|
],
|
|
60
68
|
"dependencies": {
|
|
61
|
-
"@kubb/core": "3.
|
|
62
|
-
"@kubb/fs": "3.
|
|
63
|
-
"@kubb/oas": "3.
|
|
64
|
-
"@kubb/parser-ts": "3.
|
|
65
|
-
"@kubb/plugin-oas": "3.
|
|
66
|
-
"@kubb/plugin-ts": "3.
|
|
67
|
-
"@kubb/react": "3.
|
|
69
|
+
"@kubb/core": "3.3.1",
|
|
70
|
+
"@kubb/fs": "3.3.1",
|
|
71
|
+
"@kubb/oas": "3.3.1",
|
|
72
|
+
"@kubb/parser-ts": "3.3.1",
|
|
73
|
+
"@kubb/plugin-oas": "3.3.1",
|
|
74
|
+
"@kubb/plugin-ts": "3.3.1",
|
|
75
|
+
"@kubb/react": "3.3.1"
|
|
68
76
|
},
|
|
69
77
|
"devDependencies": {
|
|
70
78
|
"tsup": "^8.3.5",
|
|
71
|
-
"
|
|
72
|
-
"@kubb/config-
|
|
79
|
+
"zod": "~3.24.1",
|
|
80
|
+
"@kubb/config-ts": "3.3.1",
|
|
81
|
+
"@kubb/config-tsup": "3.3.1"
|
|
73
82
|
},
|
|
74
83
|
"peerDependencies": {
|
|
75
84
|
"@kubb/react": "^3.0.0"
|
package/src/components/Zod.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import { type Schema, schemaKeywords } from '@kubb/plugin-oas'
|
|
|
3
3
|
import { isKeyword } from '@kubb/plugin-oas'
|
|
4
4
|
import { Const, File, Type } from '@kubb/react'
|
|
5
5
|
import type { KubbNode } from '@kubb/react/types'
|
|
6
|
-
import * as parserZod from '../parser
|
|
6
|
+
import * as parserZod from '../parser.ts'
|
|
7
7
|
import type { PluginZod } from '../types.ts'
|
|
8
8
|
|
|
9
9
|
type Props = {
|
|
@@ -30,7 +30,7 @@ export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, key
|
|
|
30
30
|
return true
|
|
31
31
|
})
|
|
32
32
|
.map((schema, _index, siblings) =>
|
|
33
|
-
parserZod.parse({ parent: undefined, current: schema, siblings }, { name, keysToOmit, typeName
|
|
33
|
+
parserZod.parse({ parent: undefined, current: schema, siblings }, { name, keysToOmit, typeName, description, mapper, coercion }),
|
|
34
34
|
)
|
|
35
35
|
.filter(Boolean)
|
|
36
36
|
.join('')
|
|
@@ -47,20 +47,23 @@ export function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, key
|
|
|
47
47
|
comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),
|
|
48
48
|
}}
|
|
49
49
|
>
|
|
50
|
-
{[
|
|
51
|
-
output,
|
|
52
|
-
keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined,
|
|
53
|
-
typeName ? ` as z.ZodType<${typeName}>` : '',
|
|
54
|
-
]
|
|
50
|
+
{[output, keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined]
|
|
55
51
|
.filter(Boolean)
|
|
56
52
|
.join('') || 'z.undefined()'}
|
|
57
53
|
</Const>
|
|
58
54
|
</File.Source>
|
|
59
55
|
{inferTypeName && (
|
|
60
56
|
<File.Source name={inferTypeName} isExportable isIndexable isTypeOnly>
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
{typeName && (
|
|
58
|
+
<Type export name={inferTypeName}>
|
|
59
|
+
{typeName}
|
|
60
|
+
</Type>
|
|
61
|
+
)}
|
|
62
|
+
{!typeName && (
|
|
63
|
+
<Type export name={inferTypeName}>
|
|
64
|
+
{`z.infer<typeof ${name}>`}
|
|
65
|
+
</Type>
|
|
66
|
+
)}
|
|
64
67
|
</File.Source>
|
|
65
68
|
)}
|
|
66
69
|
</>
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const test = z.union([
|
|
4
|
+
z
|
|
5
|
+
.object({
|
|
6
|
+
propertyA: z.string(),
|
|
7
|
+
})
|
|
8
|
+
.strict(),
|
|
9
|
+
z
|
|
10
|
+
.object({
|
|
11
|
+
propertyA: z.string(),
|
|
12
|
+
propertyB: z.string(),
|
|
13
|
+
})
|
|
14
|
+
.strict(),
|
|
15
|
+
])
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const pet = z.object({
|
|
4
|
+
id: z.coerce.number().int(),
|
|
5
|
+
name: z.coerce.string(),
|
|
6
|
+
date: z.coerce.date().optional(),
|
|
7
|
+
uuid: z.coerce.string().uuid().optional(),
|
|
8
|
+
email: z.coerce.string().email().optional(),
|
|
9
|
+
pattern: z.coerce
|
|
10
|
+
.string()
|
|
11
|
+
.regex(/^[a-zA-Z0-9]{3}$/)
|
|
12
|
+
.optional(),
|
|
13
|
+
tag: z.coerce.string().min(5).max(100).optional(),
|
|
14
|
+
})
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const pet = z.object({
|
|
4
|
+
id: z.number().int(),
|
|
5
|
+
name: z.string(),
|
|
6
|
+
date: z.coerce.date().optional(),
|
|
7
|
+
uuid: z.string().uuid().optional(),
|
|
8
|
+
email: z.string().email().optional(),
|
|
9
|
+
pattern: z
|
|
10
|
+
.string()
|
|
11
|
+
.regex(/^[a-zA-Z0-9]{3}$/)
|
|
12
|
+
.optional(),
|
|
13
|
+
tag: z.string().min(5).max(100).optional(),
|
|
14
|
+
})
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const pet = z.object({
|
|
4
|
+
id: z.coerce.number().int(),
|
|
5
|
+
name: z.string(),
|
|
6
|
+
date: z.date().optional(),
|
|
7
|
+
uuid: z.string().uuid().optional(),
|
|
8
|
+
email: z.string().email().optional(),
|
|
9
|
+
pattern: z
|
|
10
|
+
.string()
|
|
11
|
+
.regex(/^[a-zA-Z0-9]{3}$/)
|
|
12
|
+
.optional(),
|
|
13
|
+
tag: z.string().min(5).max(100).optional(),
|
|
14
|
+
})
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const pet = z.object({
|
|
4
|
+
id: z.number().int(),
|
|
5
|
+
name: z.coerce.string(),
|
|
6
|
+
date: z.date().optional(),
|
|
7
|
+
uuid: z.coerce.string().uuid().optional(),
|
|
8
|
+
email: z.coerce.string().email().optional(),
|
|
9
|
+
pattern: z.coerce
|
|
10
|
+
.string()
|
|
11
|
+
.regex(/^[a-zA-Z0-9]{3}$/)
|
|
12
|
+
.optional(),
|
|
13
|
+
tag: z.coerce.string().min(5).max(100).optional(),
|
|
14
|
+
})
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
4
|
* @description Null response
|
|
5
5
|
*/
|
|
6
|
-
export const createPets201 = z.any()
|
|
6
|
+
export const createPets201 = z.any()
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
9
|
* @description unexpected error
|
|
10
10
|
*/
|
|
11
|
-
export const createPetsError = z.lazy(() => error)
|
|
11
|
+
export const createPetsError = z.lazy(() => error)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
export const createPetsMutationRequest = z.object({
|
|
14
|
+
name: z.string(),
|
|
15
|
+
tag: z.string(),
|
|
16
|
+
})
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
export const createPetsMutationResponse = z.lazy(() => createPets201)
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
4
|
* @description Null response
|
|
5
5
|
*/
|
|
6
|
-
export const createPets201 = z.unknown()
|
|
6
|
+
export const createPets201 = z.unknown()
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
9
|
* @description unexpected error
|
|
10
10
|
*/
|
|
11
|
-
export const createPetsError = z.lazy(() => error)
|
|
11
|
+
export const createPetsError = z.lazy(() => error)
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
export const createPetsMutationRequest = z.object({
|
|
14
|
+
name: z.string(),
|
|
15
|
+
tag: z.string(),
|
|
16
|
+
})
|
|
14
17
|
|
|
15
|
-
|
|
18
|
+
export const createPetsMutationResponse = z.lazy(() => createPets201)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const deletePetsPetidMutationResponse = z.any()
|
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const advanced = z.union([
|
|
4
|
+
z
|
|
5
|
+
.lazy(() => enumerationValueSpecificationDto)
|
|
6
|
+
.and(
|
|
7
|
+
z.object({
|
|
8
|
+
type: z.enum(['enum', 'range', 'regex', 'slider']),
|
|
9
|
+
}),
|
|
10
|
+
),
|
|
11
|
+
z
|
|
12
|
+
.lazy(() => rangeValueSpecificationDto)
|
|
13
|
+
.and(
|
|
14
|
+
z.object({
|
|
15
|
+
type: z.enum(['enum', 'range', 'regex', 'slider']),
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
z
|
|
19
|
+
.lazy(() => regexValueSpecificationDto)
|
|
20
|
+
.and(
|
|
21
|
+
z.object({
|
|
22
|
+
type: z.enum(['enum', 'range', 'regex', 'slider']),
|
|
23
|
+
}),
|
|
24
|
+
),
|
|
25
|
+
z
|
|
26
|
+
.lazy(() => sliderValueSpecificationDto)
|
|
27
|
+
.and(
|
|
28
|
+
z.object({
|
|
29
|
+
type: z.enum(['enum', 'range', 'regex', 'slider']),
|
|
30
|
+
}),
|
|
31
|
+
),
|
|
32
|
+
])
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const enumBooleanLiteral = z.union([z.literal(true), z.literal(false)])
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const enumNamesType = z.enum(['0', '1'])
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const enumNullable = z.enum(['Pending', 'Received']).nullable()
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const enumSingleLiteral = z.literal(0)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const enumVarNamesType = z.union([z.literal(0), z.literal(1)])
|
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const listPetsQueryParams = z
|
|
4
|
+
.object({
|
|
5
|
+
limit: z.string().describe('How many items to return at one time (max 100)').optional(),
|
|
6
|
+
offset: z.number().int().default(0),
|
|
7
|
+
})
|
|
8
|
+
.optional()
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
/**
|
|
6
11
|
* @description A paged array of pets
|
|
7
12
|
*/
|
|
8
|
-
export const listPets200 = z.lazy(() => pets)
|
|
13
|
+
export const listPets200 = z.lazy(() => pets)
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
/**
|
|
11
16
|
* @description unexpected error
|
|
12
17
|
*/
|
|
13
|
-
export const listPetsError = z.lazy(() => error)
|
|
18
|
+
export const listPetsError = z.lazy(() => error)
|
|
14
19
|
|
|
15
|
-
|
|
20
|
+
export const listPetsQueryResponse = z.lazy(() => listPets200)
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
4
|
* @description This probably should fail miserably
|
|
5
5
|
*/
|
|
6
|
-
export const mixedValueTypeConst = z
|
|
6
|
+
export const mixedValueTypeConst = z
|
|
7
|
+
.object({
|
|
8
|
+
foobar: z.literal('foobar'),
|
|
9
|
+
})
|
|
10
|
+
.describe('This probably should fail miserably')
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const nullableString = z.string().nullable()
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const nullableStringUuid = z.string().uuid().nullable()
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const nullableStringWithAnyOf = z.union([z.string(), z.null()])
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
4
|
* @description its value is equal to the value of the keyword
|
|
5
5
|
*/
|
|
6
|
-
export const numberValueConst = z
|
|
6
|
+
export const numberValueConst = z
|
|
7
|
+
.object({
|
|
8
|
+
foobar: z.literal(42),
|
|
9
|
+
})
|
|
10
|
+
.describe('its value is equal to the value of the keyword')
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const test = z.union([
|
|
4
|
+
z.object({
|
|
5
|
+
propertyA: z.string().optional(),
|
|
6
|
+
}),
|
|
7
|
+
z.object({
|
|
8
|
+
propertyA: z.string().optional(),
|
|
9
|
+
}),
|
|
10
|
+
])
|
|
@@ -1,46 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
listPets200,
|
|
3
|
+
listPetsQueryResponse,
|
|
4
|
+
listPetsQueryParams,
|
|
5
|
+
createPetsMutationRequest,
|
|
6
|
+
createPets201,
|
|
7
|
+
createPetsMutationResponse,
|
|
8
|
+
showPetById200,
|
|
9
|
+
showPetByIdQueryResponse,
|
|
10
|
+
showPetByIdPathParams,
|
|
11
|
+
} from './showPetById'
|
|
2
12
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
13
|
+
export const operations = {
|
|
14
|
+
listPets: {
|
|
15
|
+
request: undefined,
|
|
16
|
+
parameters: {
|
|
17
|
+
path: undefined,
|
|
18
|
+
query: listPetsQueryParams,
|
|
19
|
+
header: undefined,
|
|
20
|
+
},
|
|
21
|
+
responses: {
|
|
22
|
+
200: listPets200,
|
|
23
|
+
default: listPetsQueryResponse,
|
|
24
|
+
},
|
|
25
|
+
errors: {},
|
|
26
|
+
},
|
|
27
|
+
createPets: {
|
|
28
|
+
request: createPetsMutationRequest,
|
|
29
|
+
parameters: {
|
|
30
|
+
path: undefined,
|
|
31
|
+
query: undefined,
|
|
32
|
+
header: undefined,
|
|
33
|
+
},
|
|
34
|
+
responses: {
|
|
35
|
+
201: createPets201,
|
|
36
|
+
default: createPetsMutationResponse,
|
|
37
|
+
},
|
|
38
|
+
errors: {},
|
|
39
|
+
},
|
|
40
|
+
showPetById: {
|
|
41
|
+
request: undefined,
|
|
42
|
+
parameters: {
|
|
43
|
+
path: showPetByIdPathParams,
|
|
44
|
+
query: undefined,
|
|
45
|
+
header: undefined,
|
|
46
|
+
},
|
|
47
|
+
responses: {
|
|
48
|
+
200: showPetById200,
|
|
49
|
+
default: showPetByIdQueryResponse,
|
|
50
|
+
},
|
|
51
|
+
errors: {},
|
|
52
|
+
},
|
|
53
|
+
} as const
|
|
40
54
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
55
|
+
export const paths = {
|
|
56
|
+
'/pets': {
|
|
57
|
+
get: operations['listPets'],
|
|
58
|
+
post: operations['createPets'],
|
|
59
|
+
},
|
|
60
|
+
'/pets/{petId}': {
|
|
61
|
+
get: operations['showPetById'],
|
|
62
|
+
},
|
|
63
|
+
} as const
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const optionalPet = z.object({
|
|
4
|
+
id: z.number().int().optional(),
|
|
5
|
+
name: z.string().optional(),
|
|
6
|
+
tag: z.string().optional(),
|
|
7
|
+
})
|
|
4
8
|
|
|
5
|
-
|
|
9
|
+
export type OptionalPet = z.infer<typeof optionalPet>
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ToZod } from '@kubb/plugin-zod/utils'
|
|
2
|
+
import { z } from 'zod'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
export const optionalPet = z.object({
|
|
5
|
+
id: z.number().int().optional(),
|
|
6
|
+
name: z.string().optional(),
|
|
7
|
+
tag: z.string().optional(),
|
|
8
|
+
} satisfies ToZod<OptionalPet>)
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from 'zod'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const order = z.object({
|
|
4
|
+
id: z.number().int().optional(),
|
|
5
|
+
petId: z.number().int().optional(),
|
|
6
|
+
quantity: z.number().int().optional(),
|
|
7
|
+
shipDate: z.date().optional(),
|
|
8
|
+
status: z.enum(['placed', 'approved', 'delivered']).describe('Order Status').optional(),
|
|
9
|
+
complete: z.boolean().optional(),
|
|
10
|
+
})
|