@kubb/plugin-zod 3.0.0-alpha.17 → 3.0.0-alpha.19
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/README.md +0 -4
- package/dist/{chunk-HH7DZZUF.cjs → chunk-EZIBUHZO.cjs} +51 -39
- package/dist/chunk-EZIBUHZO.cjs.map +1 -0
- package/dist/{chunk-ORFIAMY6.js → chunk-GZX3ETVC.js} +28 -16
- package/dist/chunk-GZX3ETVC.js.map +1 -0
- package/dist/{chunk-Q7F7N57F.cjs → chunk-IFCC7VQX.cjs} +4 -4
- package/dist/{chunk-Q7F7N57F.cjs.map → chunk-IFCC7VQX.cjs.map} +1 -1
- package/dist/{chunk-35K4FTRK.js → chunk-LOZEOT4J.js} +4 -4
- package/dist/{chunk-35K4FTRK.js.map → chunk-LOZEOT4J.js.map} +1 -1
- package/dist/components.cjs +3 -3
- package/dist/components.d.cts +1 -2
- package/dist/components.d.ts +1 -2
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.d.cts +1 -2
- package/dist/generators.d.ts +1 -2
- package/dist/generators.js +2 -2
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +2 -2
- package/dist/{types-29VBUXHk.d.cts → types-D7_wds1i.d.cts} +5 -23
- package/dist/{types-29VBUXHk.d.ts → types-D7_wds1i.d.ts} +5 -23
- package/package.json +10 -15
- package/src/generators/__snapshots__/anyof.ts +2 -2
- package/src/generators/__snapshots__/createPet.ts +7 -7
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +7 -7
- package/src/generators/__snapshots__/deletePet.ts +2 -2
- package/src/generators/__snapshots__/enumNamesType.ts +2 -2
- package/src/generators/__snapshots__/enumNullable.ts +2 -2
- package/src/generators/__snapshots__/enumVarNamesType.ts +2 -2
- package/src/generators/__snapshots__/example.ts +2 -2
- package/src/generators/__snapshots__/getPets.ts +8 -8
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +3 -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 +3 -3
- package/src/generators/__snapshots__/oneof.ts +2 -2
- package/src/generators/__snapshots__/operations.ts +44 -58
- package/src/generators/__snapshots__/optionalPetInfer.ts +3 -3
- package/src/generators/__snapshots__/optionalPetTyped.ts +2 -2
- package/src/generators/__snapshots__/order.ts +2 -9
- package/src/generators/__snapshots__/orderDateTypeFalse.ts +2 -9
- package/src/generators/__snapshots__/orderDateTypeString.ts +2 -9
- package/src/generators/__snapshots__/pet.ts +2 -2
- package/src/generators/__snapshots__/petArray.ts +3 -7
- package/src/generators/__snapshots__/petCoercion.ts +2 -7
- package/src/generators/__snapshots__/petTupleObject.ts +3 -3
- package/src/generators/__snapshots__/petWithMapper.ts +2 -2
- package/src/generators/__snapshots__/pets.ts +2 -2
- package/src/generators/__snapshots__/recursive.ts +2 -2
- package/src/generators/__snapshots__/showPetById.ts +8 -11
- package/src/generators/__snapshots__/stringValueConst.ts +3 -3
- package/src/generators/__snapshots__/uuidSchema.ts +2 -2
- package/src/generators/operationsGenerator.tsx +6 -3
- package/src/generators/zodGenerator.tsx +7 -2
- package/src/parser/index.ts +1 -1
- package/src/types.ts +5 -28
- package/dist/chunk-HH7DZZUF.cjs.map +0 -1
- package/dist/chunk-ORFIAMY6.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.19",
|
|
4
4
|
"description": "Generator plugin-zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -58,25 +58,20 @@
|
|
|
58
58
|
"!/**/__tests__/**"
|
|
59
59
|
],
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@kubb/core": "3.0.0-alpha.
|
|
62
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
63
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
64
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
65
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
66
|
-
"@kubb/react": "3.0.0-alpha.
|
|
67
|
-
"@kubb/types": "3.0.0-alpha.17"
|
|
61
|
+
"@kubb/core": "3.0.0-alpha.19",
|
|
62
|
+
"@kubb/fs": "3.0.0-alpha.19",
|
|
63
|
+
"@kubb/oas": "3.0.0-alpha.19",
|
|
64
|
+
"@kubb/parser-ts": "3.0.0-alpha.19",
|
|
65
|
+
"@kubb/plugin-oas": "3.0.0-alpha.19",
|
|
66
|
+
"@kubb/react": "3.0.0-alpha.19"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
70
|
-
"@types/react": "^18.3.5",
|
|
71
|
-
"prettier": "^3.3.3",
|
|
72
|
-
"react": "^18.3.1",
|
|
73
69
|
"tsup": "^8.2.4",
|
|
74
|
-
"@kubb/config-
|
|
75
|
-
"@kubb/config-
|
|
76
|
-
"@kubb/config-tsup": "3.0.0-alpha.17"
|
|
70
|
+
"@kubb/config-ts": "3.0.0-alpha.19",
|
|
71
|
+
"@kubb/config-tsup": "3.0.0-alpha.19"
|
|
77
72
|
},
|
|
78
73
|
"peerDependencies": {
|
|
79
|
-
"@kubb/react": "3.0.0-alpha.
|
|
74
|
+
"@kubb/react": "3.0.0-alpha.19"
|
|
80
75
|
},
|
|
81
76
|
"engines": {
|
|
82
77
|
"node": ">=20"
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const test = z.union([z.object({ propertyA: z.string() }).strict(), z.object({ propertyA: z.string(), propertyB: z.string() }).strict()])
|
|
3
|
+
export const test = z.union([z.object({ "propertyA": z.string() }).strict(), z.object({ "propertyA": z.string(), "propertyB": z.string() }).strict()]);
|
|
@@ -1,15 +1,15 @@
|
|
|
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
|
-
export const createPetsMutationRequest = z.object({ name: z.string(), tag: z.string() })
|
|
13
|
+
export const createPetsMutationRequest = z.object({ "name": z.string(), "tag": z.string() });
|
|
14
14
|
|
|
15
|
-
export const createPetsMutationResponse = z.any()
|
|
15
|
+
export const createPetsMutationResponse = z.any();
|
|
@@ -1,15 +1,15 @@
|
|
|
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
|
-
export const createPetsMutationRequest = z.object({ name: z.string(), tag: z.string() })
|
|
13
|
+
export const createPetsMutationRequest = z.object({ "name": z.string(), "tag": z.string() });
|
|
14
14
|
|
|
15
|
-
export const createPetsMutationResponse = z.unknown()
|
|
15
|
+
export const createPetsMutationResponse = z.unknown();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const deletePetsPetidMutationResponse = z.any()
|
|
3
|
+
export const deletePetsPetidMutationResponse = z.any();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const enumNamesType = z.enum([
|
|
3
|
+
export const enumNamesType = z.enum(["0", "1"]);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const enumNullable = z.enum([
|
|
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
|
-
export const enumVarNamesType = z.union([z.literal(0), z.literal(1)])
|
|
3
|
+
export const enumVarNamesType = z.union([z.literal(0), z.literal(1)]);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const example = z.object({ nestedExamples: z.lazy(() => example).optional() })
|
|
3
|
+
export const example = z.object({ "nestedExamples": z.lazy(() => example).optional() });
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const listPetsQueryParams = z.object({ limit: z.string().describe(
|
|
3
|
+
export const listPetsQueryParams = z.object({ "limit": z.string().describe("How many items to return at one time (max 100)").optional() }).optional();
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
6
|
* @description A paged array of pets
|
|
7
7
|
*/
|
|
8
|
-
export const listPets200 = z.lazy(() => pets)
|
|
8
|
+
export const listPets200 = z.lazy(() => pets);
|
|
9
9
|
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
11
|
* @description unexpected error
|
|
12
12
|
*/
|
|
13
|
-
export const listPetsError = z.lazy(() => error)
|
|
13
|
+
export const listPetsError = z.lazy(() => error);
|
|
14
14
|
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
16
|
* @description A paged array of pets
|
|
17
17
|
*/
|
|
18
|
-
export const listPetsQueryResponse = z.lazy(() => pets)
|
|
18
|
+
export const listPetsQueryResponse = z.lazy(() => pets);
|
|
@@ -1,6 +1,6 @@
|
|
|
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.object({ foobar: z.literal(
|
|
6
|
+
export const mixedValueTypeConst = z.object({ "foobar": z.literal("foobar") }).describe("This probably should fail miserably");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const nullableString = z.string().nullable()
|
|
3
|
+
export const nullableString = z.string().nullable();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const nullableStringUuid = z.string().uuid().nullable()
|
|
3
|
+
export const nullableStringUuid = z.string().uuid().nullable();
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const nullableStringWithAnyOf = z.union([z.string(), z.null()])
|
|
3
|
+
export const nullableStringWithAnyOf = z.union([z.string(), z.null()]);
|
|
@@ -1,6 +1,6 @@
|
|
|
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.object({ foobar: z.literal(42) }).describe(
|
|
6
|
+
export const numberValueConst = z.object({ "foobar": z.literal(42) }).describe("its value is equal to the value of the keyword");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const test = z.union([z.object({ propertyA: z.string().optional() }), z.object({ propertyA: z.string().optional() })])
|
|
3
|
+
export const test = z.union([z.object({ "propertyA": z.string().optional() }), z.object({ "propertyA": z.string().optional() })]);
|
|
@@ -1,60 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
listPetsQueryResponse,
|
|
3
|
-
listPetsQueryParams,
|
|
4
|
-
createPetsMutationRequest,
|
|
5
|
-
createPetsMutationResponse,
|
|
6
|
-
showPetByIdQueryResponse,
|
|
7
|
-
showPetByIdPathParams,
|
|
8
|
-
} from './showPetById.ts'
|
|
1
|
+
import { listPetsQueryResponse, listPetsQueryParams, createPetsMutationRequest, createPetsMutationResponse, showPetByIdQueryResponse, showPetByIdPathParams } from "./showPetById.ts";
|
|
9
2
|
|
|
10
|
-
export const operations = {
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
errors: {},
|
|
49
|
-
},
|
|
50
|
-
} as const
|
|
3
|
+
export const operations = { "listPets": {
|
|
4
|
+
request: undefined,
|
|
5
|
+
parameters: {
|
|
6
|
+
path: undefined,
|
|
7
|
+
query: listPetsQueryParams,
|
|
8
|
+
header: undefined
|
|
9
|
+
},
|
|
10
|
+
responses: {
|
|
11
|
+
200: listPetsQueryResponse,
|
|
12
|
+
default: listPetsQueryResponse
|
|
13
|
+
},
|
|
14
|
+
errors: {}
|
|
15
|
+
}, "createPets": {
|
|
16
|
+
request: createPetsMutationRequest,
|
|
17
|
+
parameters: {
|
|
18
|
+
path: undefined,
|
|
19
|
+
query: undefined,
|
|
20
|
+
header: undefined
|
|
21
|
+
},
|
|
22
|
+
responses: {
|
|
23
|
+
201: createPetsMutationResponse,
|
|
24
|
+
default: createPetsMutationResponse
|
|
25
|
+
},
|
|
26
|
+
errors: {}
|
|
27
|
+
}, "showPetById": {
|
|
28
|
+
request: undefined,
|
|
29
|
+
parameters: {
|
|
30
|
+
path: showPetByIdPathParams,
|
|
31
|
+
query: undefined,
|
|
32
|
+
header: undefined
|
|
33
|
+
},
|
|
34
|
+
responses: {
|
|
35
|
+
200: showPetByIdQueryResponse,
|
|
36
|
+
default: showPetByIdQueryResponse
|
|
37
|
+
},
|
|
38
|
+
errors: {}
|
|
39
|
+
} } as const;
|
|
51
40
|
|
|
52
|
-
export const paths = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
get: operations['showPetById'],
|
|
59
|
-
},
|
|
60
|
-
} as const
|
|
41
|
+
export const paths = { "/pets": {
|
|
42
|
+
get: operations["listPets"],
|
|
43
|
+
post: operations["createPets"]
|
|
44
|
+
}, "/pets/{petId}": {
|
|
45
|
+
get: operations["showPetById"]
|
|
46
|
+
} } as const;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const optionalPet = z.object({ id: z.number().int().optional(), name: z.string().optional(), tag: z.string().optional() })
|
|
3
|
+
export const optionalPet = z.object({ "id": z.number().int().optional(), "name": z.string().optional(), "tag": z.string().optional() });
|
|
4
4
|
|
|
5
|
-
export type OptionalPet = z.infer<typeof optionalPet
|
|
5
|
+
export type OptionalPet = z.infer<typeof optionalPet>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const optionalPet = z.object({ id: z.number().int().optional(), name: z.string().optional(), tag: z.string().optional() }) as z.ZodType<OptionalPet
|
|
3
|
+
export const optionalPet = z.object({ "id": z.number().int().optional(), "name": z.string().optional(), "tag": z.string().optional() }) as z.ZodType<OptionalPet>;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
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
|
-
})
|
|
3
|
+
export const order = z.object({ "id": z.number().int().optional(), "petId": z.number().int().optional(), "quantity": z.number().int().optional(), "shipDate": z.date().optional(), "status": z.enum(["placed", "approved", "delivered"]).describe("Order Status").optional(), "complete": z.boolean().optional() });
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
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.string().optional(),
|
|
8
|
-
status: z.enum(['placed', 'approved', 'delivered']).describe('Order Status').optional(),
|
|
9
|
-
complete: z.boolean().optional(),
|
|
10
|
-
})
|
|
3
|
+
export const order = z.object({ "id": z.number().int().optional(), "petId": z.number().int().optional(), "quantity": z.number().int().optional(), "shipDate": z.string().optional(), "status": z.enum(["placed", "approved", "delivered"]).describe("Order Status").optional(), "complete": z.boolean().optional() });
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
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.string().datetime().optional(),
|
|
8
|
-
status: z.enum(['placed', 'approved', 'delivered']).describe('Order Status').optional(),
|
|
9
|
-
complete: z.boolean().optional(),
|
|
10
|
-
})
|
|
3
|
+
export const order = z.object({ "id": z.number().int().optional(), "petId": z.number().int().optional(), "quantity": z.number().int().optional(), "shipDate": z.string().datetime().optional(), "status": z.enum(["placed", "approved", "delivered"]).describe("Order Status").optional(), "complete": z.boolean().optional() });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const pet = z.object({ id: z.number().int(), name: z.string(), date: z.date().optional(), tag: z.string().min(5).max(100).optional() })
|
|
3
|
+
export const pet = z.object({ "id": z.number().int(), "name": z.string(), "date": z.date().optional(), "tag": z.string().min(5).max(100).optional() });
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
4
|
* @description List of Pet object
|
|
5
5
|
*/
|
|
6
|
-
export const petArray = z
|
|
7
|
-
.array(z.lazy(() => pet))
|
|
8
|
-
.min(1)
|
|
9
|
-
.max(3)
|
|
10
|
-
.describe('List of Pet object')
|
|
6
|
+
export const petArray = z.array(z.lazy(() => pet)).min(1).max(3).describe("List of Pet object");
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const pet = z.object({
|
|
4
|
-
id: z.coerce.number().int(),
|
|
5
|
-
name: z.coerce.string(),
|
|
6
|
-
date: z.coerce.date().optional(),
|
|
7
|
-
tag: z.coerce.string().min(5).max(100).optional(),
|
|
8
|
-
})
|
|
3
|
+
export const pet = z.object({ "id": z.coerce.number().int(), "name": z.coerce.string(), "date": z.coerce.date().optional(), "tag": z.coerce.string().min(5).max(100).optional() });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
4
|
* @description Tuple of exact length 2 nested in an object
|
|
5
5
|
*/
|
|
6
|
-
export const petTupleObject = z.object({ tupleProperty: z.tuple([z.string(), z.string()]).optional() }).describe(
|
|
6
|
+
export const petTupleObject = z.object({ "tupleProperty": z.tuple([z.string(), z.string()]).optional() }).describe("Tuple of exact length 2 nested in an object");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const pet = z.object({ id: z.number().int(), name: z.string().email(), date: z.date().optional(), tag: z.string().min(5).max(100).optional() })
|
|
3
|
+
export const pet = z.object({ "id": z.number().int(), "name": z.string().email(), "date": z.date().optional(), "tag": z.string().min(5).max(100).optional() });
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const pets = z.array(z.object({ id: z.number().int(), name: z.string(), tag: z.string().optional() })) as z.ZodType<Pets
|
|
3
|
+
export const pets = z.array(z.object({ "id": z.number().int(), "name": z.string(), "tag": z.string().optional() })) as z.ZodType<Pets>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const example = z.object({ name: z.string(), children: z.array(z.lazy(() => example)) })
|
|
3
|
+
export const example = z.object({ "name": z.string(), "children": z.array(z.lazy(() => example)) });
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const showPetByIdPathParams = z.object({
|
|
4
|
-
petId: z.string().describe('The id of the pet to retrieve'),
|
|
5
|
-
testId: z.string().describe('The id of the pet to retrieve'),
|
|
6
|
-
})
|
|
3
|
+
export const showPetByIdPathParams = z.object({ "petId": z.string().describe("The id of the pet to retrieve"), "testId": z.string().describe("The id of the pet to retrieve") });
|
|
7
4
|
|
|
8
|
-
/**
|
|
5
|
+
/**
|
|
9
6
|
* @description Expected response to a valid request
|
|
10
7
|
*/
|
|
11
|
-
export const showPetById200 = z.lazy(() => pet)
|
|
8
|
+
export const showPetById200 = z.lazy(() => pet);
|
|
12
9
|
|
|
13
|
-
/**
|
|
10
|
+
/**
|
|
14
11
|
* @description unexpected error
|
|
15
12
|
*/
|
|
16
|
-
export const showPetByIdError = z.lazy(() => error)
|
|
13
|
+
export const showPetByIdError = z.lazy(() => error);
|
|
17
14
|
|
|
18
|
-
/**
|
|
15
|
+
/**
|
|
19
16
|
* @description Expected response to a valid request
|
|
20
17
|
*/
|
|
21
|
-
export const showPetByIdQueryResponse = z.lazy(() => pet)
|
|
18
|
+
export const showPetByIdQueryResponse = z.lazy(() => pet);
|
|
@@ -1,6 +1,6 @@
|
|
|
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 stringValueConst = z.object({ foobar: z.literal(
|
|
6
|
+
export const stringValueConst = z.object({ "foobar": z.literal("foobar") }).describe("its value is equal to the value of the keyword");
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
export const uuidSchema = z.string().uuid()
|
|
3
|
+
export const uuidSchema = z.string().uuid();
|
|
@@ -7,8 +7,11 @@ import type { PluginZod } from '../types'
|
|
|
7
7
|
|
|
8
8
|
export const operationsGenerator = createReactGenerator<PluginZod>({
|
|
9
9
|
name: 'operations',
|
|
10
|
-
Operations({ operations
|
|
11
|
-
const {
|
|
10
|
+
Operations({ operations }) {
|
|
11
|
+
const {
|
|
12
|
+
pluginManager,
|
|
13
|
+
plugin: { output },
|
|
14
|
+
} = useApp<PluginZod>()
|
|
12
15
|
const { getFile, groupSchemasByName } = useOperationManager()
|
|
13
16
|
|
|
14
17
|
const name = 'operations'
|
|
@@ -25,7 +28,7 @@ export const operationsGenerator = createReactGenerator<PluginZod>({
|
|
|
25
28
|
.filter(Boolean)
|
|
26
29
|
|
|
27
30
|
return (
|
|
28
|
-
<File baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
31
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>
|
|
29
32
|
{imports}
|
|
30
33
|
<Operations name={name} operations={transformedOperations} />
|
|
31
34
|
</File>
|
|
@@ -69,7 +69,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
return (
|
|
72
|
-
<File baseName={file.baseName} path={file.path} meta={file.meta}>
|
|
72
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.output?.banner} footer={plugin.output?.footer}>
|
|
73
73
|
<File.Import name={['z']} path={plugin.options.importPath} />
|
|
74
74
|
{operationSchemas.map(mapOperationSchema)}
|
|
75
75
|
</File>
|
|
@@ -77,7 +77,12 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
77
77
|
},
|
|
78
78
|
Schema({ schema, options }) {
|
|
79
79
|
const { coercion, inferred, typed, mapper, importPath } = options
|
|
80
|
+
|
|
80
81
|
const { getName, getFile, getImports } = useSchemaManager()
|
|
82
|
+
const {
|
|
83
|
+
plugin: { output },
|
|
84
|
+
} = useApp<PluginZod>()
|
|
85
|
+
|
|
81
86
|
const imports = getImports(schema.tree)
|
|
82
87
|
|
|
83
88
|
const zod = {
|
|
@@ -92,7 +97,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
return (
|
|
95
|
-
<File baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta}>
|
|
100
|
+
<File baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={output?.banner} footer={output?.footer}>
|
|
96
101
|
<File.Import name={['z']} path={importPath} />
|
|
97
102
|
{typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}
|
|
98
103
|
{imports.map((imp, index) => (
|
package/src/parser/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type SchemaKeywordMapper, isKeyword, schemaKeywords } from '@kubb/plugi
|
|
|
3
3
|
|
|
4
4
|
import type { Schema, SchemaKeywordBase, SchemaMapper } from '@kubb/plugin-oas'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const zodKeywordMapper = {
|
|
7
7
|
any: () => 'z.any()',
|
|
8
8
|
unknown: () => 'z.unknown()',
|
|
9
9
|
number: (coercion?: boolean, min?: number, max?: number) => {
|
package/src/types.ts
CHANGED
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type * as KubbFile from '@kubb/fs/types'
|
|
1
|
+
import type { Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
3
2
|
import type { SchemaObject } from '@kubb/oas'
|
|
4
3
|
import type { Exclude, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas'
|
|
5
4
|
|
|
6
5
|
export type Options = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* @default 'zod'
|
|
12
|
-
*/
|
|
13
|
-
path: string
|
|
14
|
-
/**
|
|
15
|
-
* Name to be used for the `export * as {{exportAs}} from './'`
|
|
16
|
-
*/
|
|
17
|
-
exportAs?: string
|
|
18
|
-
/**
|
|
19
|
-
* Add an extension to the generated imports and exports, default it will not use an extension
|
|
20
|
-
*/
|
|
21
|
-
extName?: KubbFile.Extname
|
|
22
|
-
/**
|
|
23
|
-
* Define what needs to exported, here you can also disable the export of barrel files
|
|
24
|
-
* @default `'barrel'`
|
|
25
|
-
*/
|
|
26
|
-
exportType?: 'barrel' | 'barrelNamed' | false
|
|
27
|
-
}
|
|
6
|
+
/**
|
|
7
|
+
* @default 'zod'
|
|
8
|
+
*/
|
|
9
|
+
output?: Output
|
|
28
10
|
/**
|
|
29
11
|
* Group the Zod schemas based on the provided name.
|
|
30
12
|
*/
|
|
@@ -128,9 +110,4 @@ type ResolvedOptions = {
|
|
|
128
110
|
operations: NonNullable<Options['coercion']>
|
|
129
111
|
}
|
|
130
112
|
|
|
131
|
-
export type FileMeta = {
|
|
132
|
-
pluginKey?: Plugin['key']
|
|
133
|
-
tag?: string
|
|
134
|
-
}
|
|
135
|
-
|
|
136
113
|
export type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>
|