@kubb/plugin-zod 0.0.0-canary-20241104172400
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/LICENSE +21 -0
- package/README.md +53 -0
- package/dist/chunk-37OP7TSO.cjs +354 -0
- package/dist/chunk-37OP7TSO.cjs.map +1 -0
- package/dist/chunk-OOAUU32I.js +235 -0
- package/dist/chunk-OOAUU32I.js.map +1 -0
- package/dist/chunk-QEYWJ6VH.cjs +244 -0
- package/dist/chunk-QEYWJ6VH.cjs.map +1 -0
- package/dist/chunk-SSOO3TXR.js +347 -0
- package/dist/chunk-SSOO3TXR.js.map +1 -0
- package/dist/components.cjs +16 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +29 -0
- package/dist/components.d.ts +29 -0
- package/dist/components.js +3 -0
- package/dist/components.js.map +1 -0
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +17 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/types-L1fXCZAs.d.cts +100 -0
- package/dist/types-L1fXCZAs.d.ts +100 -0
- package/package.json +95 -0
- package/src/components/Operations.tsx +49 -0
- package/src/components/Zod.tsx +68 -0
- package/src/components/index.ts +2 -0
- package/src/generators/__snapshots__/anyof.ts +3 -0
- package/src/generators/__snapshots__/coercion.ts +3 -0
- package/src/generators/__snapshots__/coercionDates.ts +3 -0
- package/src/generators/__snapshots__/coercionNumbers.ts +3 -0
- package/src/generators/__snapshots__/coercionStrings.ts +3 -0
- package/src/generators/__snapshots__/createPet.ts +15 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeAny.ts +13 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +15 -0
- package/src/generators/__snapshots__/deletePet.ts +3 -0
- package/src/generators/__snapshots__/discriminator.ts +3 -0
- package/src/generators/__snapshots__/enumBooleanLiteral.ts +3 -0
- package/src/generators/__snapshots__/enumNamesType.ts +3 -0
- package/src/generators/__snapshots__/enumNullable.ts +3 -0
- package/src/generators/__snapshots__/enumSingleLiteral.ts +3 -0
- package/src/generators/__snapshots__/enumVarNamesType.ts +3 -0
- package/src/generators/__snapshots__/example.ts +3 -0
- package/src/generators/__snapshots__/getPets.ts +15 -0
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +6 -0
- package/src/generators/__snapshots__/nullableString.ts +3 -0
- package/src/generators/__snapshots__/nullableStringUuid.ts +3 -0
- package/src/generators/__snapshots__/nullableStringWithAnyOf.ts +3 -0
- package/src/generators/__snapshots__/numberValueConst.ts +6 -0
- package/src/generators/__snapshots__/oneof.ts +3 -0
- package/src/generators/__snapshots__/operations.ts +43 -0
- package/src/generators/__snapshots__/optionalPetInfer.ts +5 -0
- package/src/generators/__snapshots__/optionalPetTyped.ts +3 -0
- package/src/generators/__snapshots__/order.ts +3 -0
- package/src/generators/__snapshots__/orderDateTyeString.ts +10 -0
- package/src/generators/__snapshots__/orderDateTypeFalse.ts +3 -0
- package/src/generators/__snapshots__/orderDateTypeString.ts +3 -0
- package/src/generators/__snapshots__/pet.ts +3 -0
- package/src/generators/__snapshots__/petArray.ts +6 -0
- package/src/generators/__snapshots__/petCoercion.ts +3 -0
- package/src/generators/__snapshots__/petTupleObject.ts +6 -0
- package/src/generators/__snapshots__/petWithMapper.ts +3 -0
- package/src/generators/__snapshots__/pets.ts +3 -0
- package/src/generators/__snapshots__/recursive.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +15 -0
- package/src/generators/__snapshots__/stringValueConst.ts +6 -0
- package/src/generators/__snapshots__/uuidSchema.ts +3 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/operationsGenerator.tsx +39 -0
- package/src/generators/zodGenerator.tsx +121 -0
- package/src/index.ts +2 -0
- package/src/parser/index.ts +381 -0
- package/src/plugin.ts +139 -0
- package/src/types.ts +106 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Stijn Van Hulle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<!-- <img src="assets/logo.png" alt="logo" width="200" height="auto" /> -->
|
|
4
|
+
<h1>@kubb/plugin-zod</h1>
|
|
5
|
+
|
|
6
|
+
<p>
|
|
7
|
+
Swagger integration for Zod to generate all the different schemas based on an OpenAPI specification.
|
|
8
|
+
</p>
|
|
9
|
+
<img src="https://raw.githubusercontent.com/kubb-labs/kubb/main/assets/banner.png" alt="logo" height="auto" />
|
|
10
|
+
|
|
11
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
12
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
13
|
+
[![Coverage][coverage-src]][coverage-href]
|
|
14
|
+
[![License][license-src]][license-href]
|
|
15
|
+
|
|
16
|
+
<h4>
|
|
17
|
+
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
18
|
+
<span> · </span>
|
|
19
|
+
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
20
|
+
<span> · </span>
|
|
21
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
22
|
+
<span> · </span>
|
|
23
|
+
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
|
|
24
|
+
</h4>
|
|
25
|
+
</div>
|
|
26
|
+
|
|
27
|
+
## Supporting Kubb
|
|
28
|
+
|
|
29
|
+
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
30
|
+
|
|
31
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
36
|
+
</a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
<!-- Badges -->
|
|
41
|
+
|
|
42
|
+
[npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-zod?flat&colorA=18181B&colorB=f58517
|
|
43
|
+
[npm-version-href]: https://npmjs.com/package/@kubb/plugin-zod
|
|
44
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@kubb/plugin-zod?flat&colorA=18181B&colorB=f58517
|
|
45
|
+
[npm-downloads-href]: https://npmjs.com/package/@kubb/plugin-zod
|
|
46
|
+
[license-src]: https://img.shields.io/github/license/kubb-labs/kubb.svg?flat&colorA=18181B&colorB=f58517
|
|
47
|
+
[license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
|
|
48
|
+
[build-src]: https://img.shields.io/github/actions/workflow/status/kubb-labs/kubb/ci.yaml?style=flat&colorA=18181B&colorB=f58517
|
|
49
|
+
[build-href]: https://www.npmjs.com/package/@kubb/plugin-zod
|
|
50
|
+
[minified-src]: https://img.shields.io/bundlephobia/min/@kubb/plugin-zod?style=flat&colorA=18181B&colorB=f58517
|
|
51
|
+
[minified-href]: https://www.npmjs.com/package/@kubb/plugin-zod
|
|
52
|
+
[coverage-src]: https://img.shields.io/codecov/c/github/kubb-labs/kubb?style=flat&colorA=18181B&colorB=f58517
|
|
53
|
+
[coverage-href]: https://www.npmjs.com/package/@kubb/plugin-zod
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('@kubb/react');
|
|
4
|
+
var transformers2 = require('@kubb/core/transformers');
|
|
5
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
6
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var transformers2__default = /*#__PURE__*/_interopDefault(transformers2);
|
|
11
|
+
|
|
12
|
+
// src/components/Operations.tsx
|
|
13
|
+
function Operations({ name, operations }) {
|
|
14
|
+
const operationsJSON = operations.reduce(
|
|
15
|
+
(prev, acc) => {
|
|
16
|
+
prev[`"${acc.operation.getOperationId()}"`] = acc.data;
|
|
17
|
+
return prev;
|
|
18
|
+
},
|
|
19
|
+
{}
|
|
20
|
+
);
|
|
21
|
+
const pathsJSON = operations.reduce(
|
|
22
|
+
(prev, acc) => {
|
|
23
|
+
prev[`"${acc.operation.path}"`] = {
|
|
24
|
+
...prev[`"${acc.operation.path}"`] || {},
|
|
25
|
+
[acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
|
|
26
|
+
};
|
|
27
|
+
return prev;
|
|
28
|
+
},
|
|
29
|
+
{}
|
|
30
|
+
);
|
|
31
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
32
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Const, { export: true, name, asConst: true, children: `{${transformers2__default.default.stringifyObject(operationsJSON)}}` }) }),
|
|
33
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: "paths", isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Const, { export: true, name: "paths", asConst: true, children: `{${transformers2__default.default.stringifyObject(pathsJSON)}}` }) })
|
|
34
|
+
] });
|
|
35
|
+
}
|
|
36
|
+
var zodKeywordMapper = {
|
|
37
|
+
any: () => "z.any()",
|
|
38
|
+
unknown: () => "z.unknown()",
|
|
39
|
+
number: (coercion, min, max) => {
|
|
40
|
+
return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
41
|
+
},
|
|
42
|
+
integer: (coercion, min, max) => {
|
|
43
|
+
return [
|
|
44
|
+
coercion ? "z.coerce.number().int()" : "z.number().int()",
|
|
45
|
+
min !== void 0 ? `.min(${min})` : void 0,
|
|
46
|
+
max !== void 0 ? `.max(${max})` : void 0
|
|
47
|
+
].filter(Boolean).join("");
|
|
48
|
+
},
|
|
49
|
+
object: (value) => `z.object({${value}})`,
|
|
50
|
+
string: (coercion, min, max) => {
|
|
51
|
+
return [coercion ? "z.coerce.string()" : "z.string()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
52
|
+
},
|
|
53
|
+
boolean: () => "z.boolean()",
|
|
54
|
+
undefined: () => "z.undefined()",
|
|
55
|
+
nullable: () => ".nullable()",
|
|
56
|
+
null: () => "z.null()",
|
|
57
|
+
nullish: () => ".nullish()",
|
|
58
|
+
array: (items = [], min, max) => {
|
|
59
|
+
return [`z.array(${items?.join("")})`, min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
60
|
+
},
|
|
61
|
+
tuple: (items = []) => `z.tuple([${items?.join(", ")}])`,
|
|
62
|
+
enum: (items = []) => `z.enum([${items?.join(", ")}])`,
|
|
63
|
+
union: (items = []) => `z.union([${items?.join(", ")}])`,
|
|
64
|
+
const: (value) => `z.literal(${value ?? ""})`,
|
|
65
|
+
/**
|
|
66
|
+
* ISO 8601
|
|
67
|
+
*/
|
|
68
|
+
datetime: (offset = false, local = false) => {
|
|
69
|
+
if (offset) {
|
|
70
|
+
return `z.string().datetime({ offset: ${offset} })`;
|
|
71
|
+
}
|
|
72
|
+
if (local) {
|
|
73
|
+
return `z.string().datetime({ local: ${local} })`;
|
|
74
|
+
}
|
|
75
|
+
return "z.string().datetime()";
|
|
76
|
+
},
|
|
77
|
+
/**
|
|
78
|
+
* Type `'date'` Date
|
|
79
|
+
* Type `'string'` ISO date format (YYYY-MM-DD)
|
|
80
|
+
* @default ISO date format (YYYY-MM-DD)
|
|
81
|
+
*/
|
|
82
|
+
date: (type = "string", coercion) => {
|
|
83
|
+
if (type === "string") {
|
|
84
|
+
return "z.string().date()";
|
|
85
|
+
}
|
|
86
|
+
if (coercion) {
|
|
87
|
+
return "z.coerce.date()";
|
|
88
|
+
}
|
|
89
|
+
return "z.date()";
|
|
90
|
+
},
|
|
91
|
+
/**
|
|
92
|
+
* Type `'date'` Date
|
|
93
|
+
* Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
|
|
94
|
+
* @default ISO time format (HH:mm:ss[.SSSSSS])
|
|
95
|
+
*/
|
|
96
|
+
time: (type = "string", coercion) => {
|
|
97
|
+
if (type === "string") {
|
|
98
|
+
return "z.string().time()";
|
|
99
|
+
}
|
|
100
|
+
if (coercion) {
|
|
101
|
+
return "z.coerce.date()";
|
|
102
|
+
}
|
|
103
|
+
return "z.date()";
|
|
104
|
+
},
|
|
105
|
+
uuid: () => ".uuid()",
|
|
106
|
+
url: () => ".url()",
|
|
107
|
+
strict: () => ".strict()",
|
|
108
|
+
default: (value) => `.default(${value ?? ""})`,
|
|
109
|
+
and: (items = []) => items?.map((item) => `.and(${item})`).join(""),
|
|
110
|
+
describe: (value = "") => `.describe(${value})`,
|
|
111
|
+
min: (value) => `.min(${value ?? ""})`,
|
|
112
|
+
max: (value) => `.max(${value ?? ""})`,
|
|
113
|
+
optional: () => ".optional()",
|
|
114
|
+
matches: (value = "") => `.regex(${value})`,
|
|
115
|
+
email: () => ".email()",
|
|
116
|
+
firstName: void 0,
|
|
117
|
+
lastName: void 0,
|
|
118
|
+
password: void 0,
|
|
119
|
+
phone: void 0,
|
|
120
|
+
readOnly: void 0,
|
|
121
|
+
writeOnly: void 0,
|
|
122
|
+
ref: (value) => value ? `z.lazy(() => ${value})` : void 0,
|
|
123
|
+
blob: () => "z.string()",
|
|
124
|
+
deprecated: void 0,
|
|
125
|
+
example: void 0,
|
|
126
|
+
schema: void 0,
|
|
127
|
+
catchall: (value) => value ? `.catchall(${value})` : void 0,
|
|
128
|
+
name: void 0
|
|
129
|
+
};
|
|
130
|
+
function sort(items) {
|
|
131
|
+
const order = [
|
|
132
|
+
pluginOas.schemaKeywords.string,
|
|
133
|
+
pluginOas.schemaKeywords.datetime,
|
|
134
|
+
pluginOas.schemaKeywords.date,
|
|
135
|
+
pluginOas.schemaKeywords.time,
|
|
136
|
+
pluginOas.schemaKeywords.tuple,
|
|
137
|
+
pluginOas.schemaKeywords.number,
|
|
138
|
+
pluginOas.schemaKeywords.object,
|
|
139
|
+
pluginOas.schemaKeywords.enum,
|
|
140
|
+
pluginOas.schemaKeywords.url,
|
|
141
|
+
pluginOas.schemaKeywords.email,
|
|
142
|
+
pluginOas.schemaKeywords.firstName,
|
|
143
|
+
pluginOas.schemaKeywords.lastName,
|
|
144
|
+
pluginOas.schemaKeywords.password,
|
|
145
|
+
pluginOas.schemaKeywords.matches,
|
|
146
|
+
pluginOas.schemaKeywords.uuid,
|
|
147
|
+
pluginOas.schemaKeywords.min,
|
|
148
|
+
pluginOas.schemaKeywords.max,
|
|
149
|
+
pluginOas.schemaKeywords.default,
|
|
150
|
+
pluginOas.schemaKeywords.describe,
|
|
151
|
+
pluginOas.schemaKeywords.optional,
|
|
152
|
+
pluginOas.schemaKeywords.nullable,
|
|
153
|
+
pluginOas.schemaKeywords.nullish,
|
|
154
|
+
pluginOas.schemaKeywords.null
|
|
155
|
+
];
|
|
156
|
+
if (!items) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
return transformers2__default.default.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
|
|
160
|
+
}
|
|
161
|
+
var shouldCoerce = (coercion, type) => {
|
|
162
|
+
if (coercion === void 0) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
if (typeof coercion === "boolean") {
|
|
166
|
+
return coercion;
|
|
167
|
+
}
|
|
168
|
+
return !!coercion[type];
|
|
169
|
+
};
|
|
170
|
+
function parse({ parent, current, siblings }, options) {
|
|
171
|
+
const value = zodKeywordMapper[current.keyword];
|
|
172
|
+
if (!value) {
|
|
173
|
+
return void 0;
|
|
174
|
+
}
|
|
175
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.union)) {
|
|
176
|
+
if (Array.isArray(current.args) && current.args.length === 1) {
|
|
177
|
+
return parse({ parent, current: current.args[0], siblings }, options);
|
|
178
|
+
}
|
|
179
|
+
if (Array.isArray(current.args) && !current.args.length) {
|
|
180
|
+
return "";
|
|
181
|
+
}
|
|
182
|
+
return zodKeywordMapper.union(
|
|
183
|
+
sort(current.args).map((schema, _index, siblings2) => parse({ parent: current, current: schema, siblings: siblings2 }, options)).filter(Boolean)
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.and)) {
|
|
187
|
+
const items = sort(current.args).filter((schema) => {
|
|
188
|
+
return ![pluginOas.schemaKeywords.optional, pluginOas.schemaKeywords.describe].includes(schema.keyword);
|
|
189
|
+
}).map((schema, _index, siblings2) => parse({ parent: current, current: schema, siblings: siblings2 }, options)).filter(Boolean);
|
|
190
|
+
return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
|
|
191
|
+
}
|
|
192
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.array)) {
|
|
193
|
+
return zodKeywordMapper.array(
|
|
194
|
+
sort(current.args.items).map((schemas, _index, siblings2) => parse({ parent: current, current: schemas, siblings: siblings2 }, options)).filter(Boolean),
|
|
195
|
+
current.args.min,
|
|
196
|
+
current.args.max
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.enum)) {
|
|
200
|
+
if (current.args.asConst) {
|
|
201
|
+
if (current.args.items.length === 1) {
|
|
202
|
+
const child = {
|
|
203
|
+
keyword: pluginOas.schemaKeywords.const,
|
|
204
|
+
args: current.args.items[0]
|
|
205
|
+
};
|
|
206
|
+
return parse({ parent: current, current: child, siblings: [child] }, options);
|
|
207
|
+
}
|
|
208
|
+
return zodKeywordMapper.union(
|
|
209
|
+
current.args.items.map((schema) => ({
|
|
210
|
+
keyword: pluginOas.schemaKeywords.const,
|
|
211
|
+
args: schema
|
|
212
|
+
})).map((schema, _index, siblings2) => {
|
|
213
|
+
return parse({ parent: current, current: schema, siblings: siblings2 }, options);
|
|
214
|
+
}).filter(Boolean)
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
return zodKeywordMapper.enum(
|
|
218
|
+
current.args.items.map((schema) => {
|
|
219
|
+
if (schema.format === "boolean") {
|
|
220
|
+
return transformers2__default.default.stringify(schema.value);
|
|
221
|
+
}
|
|
222
|
+
if (schema.format === "number") {
|
|
223
|
+
return transformers2__default.default.stringify(schema.value);
|
|
224
|
+
}
|
|
225
|
+
return transformers2__default.default.stringify(schema.value);
|
|
226
|
+
})
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.ref)) {
|
|
230
|
+
return zodKeywordMapper.ref(current.args?.name);
|
|
231
|
+
}
|
|
232
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.object)) {
|
|
233
|
+
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
234
|
+
const schema = item[1];
|
|
235
|
+
return schema && typeof schema.map === "function";
|
|
236
|
+
}).map(([name, schemas]) => {
|
|
237
|
+
const nameSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.name);
|
|
238
|
+
const mappedName = nameSchema?.args || name;
|
|
239
|
+
if (options.mapper?.[mappedName]) {
|
|
240
|
+
return `"${name}": ${options.mapper?.[mappedName]}`;
|
|
241
|
+
}
|
|
242
|
+
return `"${name}": ${sort(schemas).map((schema, array, siblings2) => {
|
|
243
|
+
return parse({ parent: current, current: schema, siblings: siblings2 }, options);
|
|
244
|
+
}).filter(Boolean).join("")}`;
|
|
245
|
+
}).join(",");
|
|
246
|
+
const additionalProperties = current.args?.additionalProperties?.length ? current.args.additionalProperties.map((schema, _index, siblings2) => parse({ parent: current, current: schema, siblings: siblings2 }, options)).filter(Boolean).join("") : void 0;
|
|
247
|
+
const text = [
|
|
248
|
+
zodKeywordMapper.object(properties),
|
|
249
|
+
current.args?.strict ? zodKeywordMapper.strict() : void 0,
|
|
250
|
+
additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0
|
|
251
|
+
].filter(Boolean);
|
|
252
|
+
return text.join("");
|
|
253
|
+
}
|
|
254
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.tuple)) {
|
|
255
|
+
return zodKeywordMapper.tuple(
|
|
256
|
+
current.args.items.map((schema, _index, siblings2) => parse({ parent: current, current: schema, siblings: siblings2 }, options)).filter(Boolean)
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.const)) {
|
|
260
|
+
if (current.args.format === "number" && current.args.value !== void 0) {
|
|
261
|
+
return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
|
|
262
|
+
}
|
|
263
|
+
if (current.args.format === "boolean" && current.args.value !== void 0) {
|
|
264
|
+
return zodKeywordMapper.const(current.args.value);
|
|
265
|
+
}
|
|
266
|
+
return zodKeywordMapper.const(transformers2__default.default.stringify(current.args.value));
|
|
267
|
+
}
|
|
268
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.matches)) {
|
|
269
|
+
if (current.args) {
|
|
270
|
+
return zodKeywordMapper.matches(transformers2__default.default.toRegExpString(current.args));
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.default)) {
|
|
274
|
+
if (current.args) {
|
|
275
|
+
return zodKeywordMapper.default(current.args);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.describe)) {
|
|
279
|
+
if (current.args) {
|
|
280
|
+
return zodKeywordMapper.describe(transformers2__default.default.stringify(current.args.toString()));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.string)) {
|
|
284
|
+
return zodKeywordMapper.string(shouldCoerce(options.coercion, "strings"));
|
|
285
|
+
}
|
|
286
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.number)) {
|
|
287
|
+
return zodKeywordMapper.number(shouldCoerce(options.coercion, "numbers"));
|
|
288
|
+
}
|
|
289
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.integer)) {
|
|
290
|
+
return zodKeywordMapper.integer(shouldCoerce(options.coercion, "numbers"));
|
|
291
|
+
}
|
|
292
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.min)) {
|
|
293
|
+
return zodKeywordMapper.min(current.args);
|
|
294
|
+
}
|
|
295
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.max)) {
|
|
296
|
+
return zodKeywordMapper.max(current.args);
|
|
297
|
+
}
|
|
298
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.datetime)) {
|
|
299
|
+
return zodKeywordMapper.datetime(current.args.offset, current.args.local);
|
|
300
|
+
}
|
|
301
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.date)) {
|
|
302
|
+
return zodKeywordMapper.date(current.args.type, shouldCoerce(options.coercion, "dates"));
|
|
303
|
+
}
|
|
304
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.time)) {
|
|
305
|
+
return zodKeywordMapper.time(current.args.type, shouldCoerce(options.coercion, "dates"));
|
|
306
|
+
}
|
|
307
|
+
if (current.keyword in zodKeywordMapper && "args" in current) {
|
|
308
|
+
const value2 = zodKeywordMapper[current.keyword];
|
|
309
|
+
return value2(current.args);
|
|
310
|
+
}
|
|
311
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.optional)) {
|
|
312
|
+
if (siblings.some((schema) => pluginOas.isKeyword(schema, pluginOas.schemaKeywords.default))) return "";
|
|
313
|
+
return value();
|
|
314
|
+
}
|
|
315
|
+
if (current.keyword in zodKeywordMapper) {
|
|
316
|
+
return value();
|
|
317
|
+
}
|
|
318
|
+
return void 0;
|
|
319
|
+
}
|
|
320
|
+
function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, keysToOmit, description }) {
|
|
321
|
+
const hasTuple = tree.some((item) => pluginOas.isKeyword(item, pluginOas.schemaKeywords.tuple));
|
|
322
|
+
const output = sort(tree).filter((item) => {
|
|
323
|
+
if (hasTuple && (pluginOas.isKeyword(item, pluginOas.schemaKeywords.min) || pluginOas.isKeyword(item, pluginOas.schemaKeywords.max))) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
return true;
|
|
327
|
+
}).map(
|
|
328
|
+
(schema, _index, siblings) => parse({ parent: void 0, current: schema, siblings }, { name, keysToOmit, typeName, description, mapper, coercion })
|
|
329
|
+
).filter(Boolean).join("");
|
|
330
|
+
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
331
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
332
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
333
|
+
react.Const,
|
|
334
|
+
{
|
|
335
|
+
export: true,
|
|
336
|
+
name,
|
|
337
|
+
JSDoc: {
|
|
338
|
+
comments: [description ? `@description ${transformers2__default.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
339
|
+
},
|
|
340
|
+
children: [
|
|
341
|
+
output,
|
|
342
|
+
keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(",")} }))` : void 0,
|
|
343
|
+
typeName ? ` as z.ZodType<${typeName}>` : ""
|
|
344
|
+
].filter(Boolean).join("") || "z.undefined()"
|
|
345
|
+
}
|
|
346
|
+
) }),
|
|
347
|
+
inferTypeName && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: inferTypeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { export: true, name: inferTypeName, children: `z.infer<typeof ${name}>` }) })
|
|
348
|
+
] });
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
exports.Operations = Operations;
|
|
352
|
+
exports.Zod = Zod;
|
|
353
|
+
//# sourceMappingURL=chunk-37OP7TSO.cjs.map
|
|
354
|
+
//# sourceMappingURL=chunk-37OP7TSO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/Operations.tsx","../src/parser/index.ts","../src/components/Zod.tsx"],"names":["jsxs","Fragment","jsx","File","Const","transformers","schemaKeywords","isKeyword","siblings","value","Type"],"mappings":";;;;;;;;;;;;AAYO,SAAS,UAAW,CAAA,EAAE,IAAM,EAAA,UAAA,EAA+B,EAAA;AAChE,EAAA,MAAM,iBAAiB,UAAW,CAAA,MAAA;AAAA,IAChC,CAAC,MAAM,GAAQ,KAAA;AACb,MAAA,IAAA,CAAK,IAAI,GAAI,CAAA,SAAA,CAAU,gBAAgB,CAAA,CAAA,CAAG,IAAI,GAAI,CAAA,IAAA;AAElD,MAAO,OAAA,IAAA;AAAA,KACT;AAAA,IACA;AAAC,GACH;AAEA,EAAA,MAAM,YAAY,UAAW,CAAA,MAAA;AAAA,IAC3B,CAAC,MAAM,GAAQ,KAAA;AACb,MAAA,IAAA,CAAK,CAAI,CAAA,EAAA,GAAA,CAAI,SAAU,CAAA,IAAI,GAAG,CAAI,GAAA;AAAA,QAChC,GAAI,KAAK,CAAI,CAAA,EAAA,GAAA,CAAI,UAAU,IAAI,CAAA,CAAA,CAAG,KAAM,EAAC;AAAA,QACzC,CAAC,IAAI,SAAU,CAAA,MAAM,GAAG,CAAe,YAAA,EAAA,GAAA,CAAI,SAAU,CAAA,cAAA,EAAgB,CAAA,EAAA;AAAA,OACvE;AAEA,MAAO,OAAA,IAAA;AAAA,KACT;AAAA,IACA;AAAC,GACH;AAEA,EAAA,uBAEIA,eAAA,CAAAC,mBAAA,EAAA,EAAA,QAAA,EAAA;AAAA,oBAACC,cAAA,CAAAC,UAAA,CAAK,QAAL,EAAY,IAAA,EAAY,cAAY,IAAC,EAAA,WAAA,EAAW,MAC/C,QAAC,kBAAAD,cAAA,CAAAE,WAAA,EAAA,EAAM,QAAM,IAAC,EAAA,IAAA,EAAY,SAAO,IAC9B,EAAA,QAAA,EAAA,CAAA,CAAA,EAAIC,+BAAa,eAAg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AA,CAAA;AAAA,IACC,aAAA,oBACCH,cAAAA,CAACC,UAAK,CAAA,MAAA,EAAL,EAAY,IAAM,EAAA,aAAA,EAAe,YAAY,EAAA,IAAA,EAAC,WAAW,EAAA,IAAA,EAAC,YAAU,IACnE,EAAA,QAAA,kBAAAD,cAAC,CAAAQ,UAAA,EAAA,EAAK,MAAM,EAAA,IAAA,EAAC,MAAM,aAChB,EAAA,QAAA,EAAA,CAAA,eAAA,EAAkB,IAAI,CAAA,CAAA,CAAA,EACzB,CACF,EAAA;AAAA,GAEJ,EAAA,CAAA;AAEJ","file":"chunk-37OP7TSO.cjs","sourcesContent":["import type { SchemaNames } from '@kubb/plugin-oas/hooks'\nimport { Const, File } from '@kubb/react'\n\nimport transformers from '@kubb/core/transformers'\nimport type { HttpMethod, Operation } from '@kubb/oas'\nimport type { KubbNode } from '@kubb/react/types'\n\ntype Props = {\n name: string\n operations: Array<{ operation: Operation; data: SchemaNames }>\n}\n\nexport function Operations({ name, operations }: Props): KubbNode {\n const operationsJSON = operations.reduce(\n (prev, acc) => {\n prev[`\"${acc.operation.getOperationId()}\"`] = acc.data\n\n return prev\n },\n {} as Record<string, unknown>,\n )\n\n const pathsJSON = operations.reduce(\n (prev, acc) => {\n prev[`\"${acc.operation.path}\"`] = {\n ...(prev[`\"${acc.operation.path}\"`] || ({} as Record<HttpMethod, string>)),\n [acc.operation.method]: `operations[\"${acc.operation.getOperationId()}\"]`,\n }\n\n return prev\n },\n {} as Record<string, Record<HttpMethod, string>>,\n )\n\n return (\n <>\n <File.Source name={name} isExportable isIndexable>\n <Const export name={name} asConst>\n {`{${transformers.stringifyObject(operationsJSON)}}`}\n </Const>\n </File.Source>\n <File.Source name={'paths'} isExportable isIndexable>\n <Const export name={'paths'} asConst>\n {`{${transformers.stringifyObject(pathsJSON)}}`}\n </Const>\n </File.Source>\n </>\n )\n}\n","import transformers, { createJSDocBlockText } from '@kubb/core/transformers'\nimport { type SchemaKeywordMapper, type SchemaTree, isKeyword, schemaKeywords } from '@kubb/plugin-oas'\n\nimport type { Schema, SchemaKeywordBase, SchemaMapper } from '@kubb/plugin-oas'\n\nconst zodKeywordMapper = {\n any: () => 'z.any()',\n unknown: () => 'z.unknown()',\n number: (coercion?: boolean, min?: number, max?: number) => {\n return [coercion ? 'z.coerce.number()' : 'z.number()', min !== undefined ? `.min(${min})` : undefined, max !== undefined ? `.max(${max})` : undefined]\n .filter(Boolean)\n .join('')\n },\n integer: (coercion?: boolean, min?: number, max?: number) => {\n return [\n coercion ? 'z.coerce.number().int()' : 'z.number().int()',\n min !== undefined ? `.min(${min})` : undefined,\n max !== undefined ? `.max(${max})` : undefined,\n ]\n .filter(Boolean)\n .join('')\n },\n object: (value?: string) => `z.object({${value}})`,\n string: (coercion?: boolean, min?: number, max?: number) => {\n return [coercion ? 'z.coerce.string()' : 'z.string()', min !== undefined ? `.min(${min})` : undefined, max !== undefined ? `.max(${max})` : undefined]\n .filter(Boolean)\n .join('')\n },\n boolean: () => 'z.boolean()',\n undefined: () => 'z.undefined()',\n nullable: () => '.nullable()',\n null: () => 'z.null()',\n nullish: () => '.nullish()',\n array: (items: string[] = [], min?: number, max?: number) => {\n return [`z.array(${items?.join('')})`, min !== undefined ? `.min(${min})` : undefined, max !== undefined ? `.max(${max})` : undefined]\n .filter(Boolean)\n .join('')\n },\n tuple: (items: string[] = []) => `z.tuple([${items?.join(', ')}])`,\n enum: (items: string[] = []) => `z.enum([${items?.join(', ')}])`,\n union: (items: string[] = []) => `z.union([${items?.join(', ')}])`,\n const: (value?: string | number | boolean) => `z.literal(${value ?? ''})`,\n /**\n * ISO 8601\n */\n datetime: (offset = false, local = false) => {\n if (offset) {\n return `z.string().datetime({ offset: ${offset} })`\n }\n\n if (local) {\n return `z.string().datetime({ local: ${local} })`\n }\n\n return 'z.string().datetime()'\n },\n /**\n * Type `'date'` Date\n * Type `'string'` ISO date format (YYYY-MM-DD)\n * @default ISO date format (YYYY-MM-DD)\n */\n date: (type: 'date' | 'string' = 'string', coercion?: boolean) => {\n if (type === 'string') {\n return 'z.string().date()'\n }\n\n if (coercion) {\n return 'z.coerce.date()'\n }\n\n return 'z.date()'\n },\n /**\n * Type `'date'` Date\n * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])\n * @default ISO time format (HH:mm:ss[.SSSSSS])\n */\n time: (type: 'date' | 'string' = 'string', coercion?: boolean) => {\n if (type === 'string') {\n return 'z.string().time()'\n }\n\n if (coercion) {\n return 'z.coerce.date()'\n }\n\n return 'z.date()'\n },\n uuid: () => '.uuid()',\n url: () => '.url()',\n strict: () => '.strict()',\n default: (value?: string | number | true) => `.default(${value ?? ''})`,\n and: (items: string[] = []) => items?.map((item) => `.and(${item})`).join(''),\n describe: (value = '') => `.describe(${value})`,\n min: (value?: number) => `.min(${value ?? ''})`,\n max: (value?: number) => `.max(${value ?? ''})`,\n optional: () => '.optional()',\n matches: (value = '') => `.regex(${value})`,\n email: () => '.email()',\n firstName: undefined,\n lastName: undefined,\n password: undefined,\n phone: undefined,\n readOnly: undefined,\n writeOnly: undefined,\n ref: (value?: string) => (value ? `z.lazy(() => ${value})` : undefined),\n blob: () => 'z.string()',\n deprecated: undefined,\n example: undefined,\n schema: undefined,\n catchall: (value?: string) => (value ? `.catchall(${value})` : undefined),\n name: undefined,\n} satisfies SchemaMapper<string | null | undefined>\n\n/**\n * @link based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398\n */\n\nexport function sort(items?: Schema[]): Schema[] {\n const order: string[] = [\n schemaKeywords.string,\n schemaKeywords.datetime,\n schemaKeywords.date,\n schemaKeywords.time,\n schemaKeywords.tuple,\n schemaKeywords.number,\n schemaKeywords.object,\n schemaKeywords.enum,\n schemaKeywords.url,\n schemaKeywords.email,\n schemaKeywords.firstName,\n schemaKeywords.lastName,\n schemaKeywords.password,\n schemaKeywords.matches,\n schemaKeywords.uuid,\n schemaKeywords.min,\n schemaKeywords.max,\n schemaKeywords.default,\n schemaKeywords.describe,\n schemaKeywords.optional,\n schemaKeywords.nullable,\n schemaKeywords.nullish,\n schemaKeywords.null,\n ]\n\n if (!items) {\n return []\n }\n\n return transformers.orderBy(items, [(v) => order.indexOf(v.keyword)], ['asc'])\n}\n\nconst shouldCoerce = (coercion: ParserOptions['coercion'] | undefined, type: 'dates' | 'strings' | 'numbers'): boolean => {\n if (coercion === undefined) {\n return false\n }\n if (typeof coercion === 'boolean') {\n return coercion\n }\n\n return !!coercion[type]\n}\n\ntype ParserOptions = {\n name: string\n typeName?: string\n description?: string\n keysToOmit?: string[]\n mapper?: Record<string, string>\n coercion?: boolean | { dates?: boolean; strings?: boolean; numbers?: boolean }\n}\n\nexport function parse({ parent, current, siblings }: SchemaTree, options: ParserOptions): string | undefined {\n const value = zodKeywordMapper[current.keyword as keyof typeof zodKeywordMapper]\n\n if (!value) {\n return undefined\n }\n\n if (isKeyword(current, schemaKeywords.union)) {\n // zod union type needs at least 2 items\n if (Array.isArray(current.args) && current.args.length === 1) {\n return parse({ parent, current: current.args[0] as Schema, siblings }, options)\n }\n if (Array.isArray(current.args) && !current.args.length) {\n return ''\n }\n\n return zodKeywordMapper.union(\n sort(current.args)\n .map((schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options))\n .filter(Boolean),\n )\n }\n\n if (isKeyword(current, schemaKeywords.and)) {\n const items = sort(current.args)\n .filter((schema: Schema) => {\n return ![schemaKeywords.optional, schemaKeywords.describe].includes(schema.keyword as typeof schemaKeywords.describe)\n })\n .map((schema: Schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options))\n .filter(Boolean)\n\n return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`\n }\n\n if (isKeyword(current, schemaKeywords.array)) {\n return zodKeywordMapper.array(\n sort(current.args.items)\n .map((schemas, _index, siblings) => parse({ parent: current, current: schemas, siblings }, options))\n .filter(Boolean),\n current.args.min,\n current.args.max,\n )\n }\n\n if (isKeyword(current, schemaKeywords.enum)) {\n if (current.args.asConst) {\n if (current.args.items.length === 1) {\n const child = {\n keyword: schemaKeywords.const,\n args: current.args.items[0],\n }\n return parse({ parent: current, current: child, siblings: [child] }, options)\n }\n\n return zodKeywordMapper.union(\n current.args.items\n .map((schema) => ({\n keyword: schemaKeywords.const,\n args: schema,\n }))\n .map((schema, _index, siblings) => {\n return parse({ parent: current, current: schema, siblings }, options)\n })\n .filter(Boolean),\n )\n }\n\n return zodKeywordMapper.enum(\n current.args.items.map((schema) => {\n if (schema.format === 'boolean') {\n return transformers.stringify(schema.value)\n }\n\n if (schema.format === 'number') {\n return transformers.stringify(schema.value)\n }\n return transformers.stringify(schema.value)\n }),\n )\n }\n\n if (isKeyword(current, schemaKeywords.ref)) {\n return zodKeywordMapper.ref(current.args?.name)\n }\n\n if (isKeyword(current, schemaKeywords.object)) {\n const properties = Object.entries(current.args?.properties || {})\n .filter((item) => {\n const schema = item[1]\n return schema && typeof schema.map === 'function'\n })\n .map(([name, schemas]) => {\n const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name) as SchemaKeywordMapper['name']\n const mappedName = nameSchema?.args || name\n\n // custom mapper(pluginOptions)\n if (options.mapper?.[mappedName]) {\n return `\"${name}\": ${options.mapper?.[mappedName]}`\n }\n\n return `\"${name}\": ${sort(schemas)\n .map((schema, array, siblings) => {\n return parse({ parent: current, current: schema, siblings }, options)\n })\n .filter(Boolean)\n .join('')}`\n })\n .join(',')\n\n const additionalProperties = current.args?.additionalProperties?.length\n ? current.args.additionalProperties\n .map((schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options))\n .filter(Boolean)\n .join('')\n : undefined\n\n const text = [\n zodKeywordMapper.object(properties),\n current.args?.strict ? zodKeywordMapper.strict() : undefined,\n additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : undefined,\n ].filter(Boolean)\n\n return text.join('')\n }\n\n if (isKeyword(current, schemaKeywords.tuple)) {\n return zodKeywordMapper.tuple(\n current.args.items.map((schema, _index, siblings) => parse({ parent: current, current: schema, siblings }, options)).filter(Boolean),\n )\n }\n\n if (isKeyword(current, schemaKeywords.const)) {\n if (current.args.format === 'number' && current.args.value !== undefined) {\n return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()))\n }\n\n if (current.args.format === 'boolean' && current.args.value !== undefined) {\n return zodKeywordMapper.const(current.args.value)\n }\n return zodKeywordMapper.const(transformers.stringify(current.args.value))\n }\n\n if (isKeyword(current, schemaKeywords.matches)) {\n if (current.args) {\n return zodKeywordMapper.matches(transformers.toRegExpString(current.args))\n }\n }\n\n if (isKeyword(current, schemaKeywords.default)) {\n if (current.args) {\n return zodKeywordMapper.default(current.args)\n }\n }\n\n if (isKeyword(current, schemaKeywords.describe)) {\n if (current.args) {\n return zodKeywordMapper.describe(transformers.stringify(current.args.toString()))\n }\n }\n\n if (isKeyword(current, schemaKeywords.string)) {\n return zodKeywordMapper.string(shouldCoerce(options.coercion, 'strings'))\n }\n\n if (isKeyword(current, schemaKeywords.number)) {\n return zodKeywordMapper.number(shouldCoerce(options.coercion, 'numbers'))\n }\n\n if (isKeyword(current, schemaKeywords.integer)) {\n return zodKeywordMapper.integer(shouldCoerce(options.coercion, 'numbers'))\n }\n\n if (isKeyword(current, schemaKeywords.min)) {\n return zodKeywordMapper.min(current.args)\n }\n if (isKeyword(current, schemaKeywords.max)) {\n return zodKeywordMapper.max(current.args)\n }\n\n if (isKeyword(current, schemaKeywords.datetime)) {\n return zodKeywordMapper.datetime(current.args.offset, current.args.local)\n }\n\n if (isKeyword(current, schemaKeywords.date)) {\n return zodKeywordMapper.date(current.args.type, shouldCoerce(options.coercion, 'dates'))\n }\n\n if (isKeyword(current, schemaKeywords.time)) {\n return zodKeywordMapper.time(current.args.type, shouldCoerce(options.coercion, 'dates'))\n }\n\n if (current.keyword in zodKeywordMapper && 'args' in current) {\n const value = zodKeywordMapper[current.keyword as keyof typeof zodKeywordMapper] as (typeof zodKeywordMapper)['const']\n\n return value((current as SchemaKeywordBase<unknown>).args as any)\n }\n\n if (isKeyword(current, schemaKeywords.optional)) {\n if (siblings.some((schema) => isKeyword(schema, schemaKeywords.default))) return ''\n\n return value()\n }\n\n if (current.keyword in zodKeywordMapper) {\n return value()\n }\n\n return undefined\n}\n","import transformers from '@kubb/core/transformers'\nimport { type Schema, schemaKeywords } from '@kubb/plugin-oas'\nimport { isKeyword } from '@kubb/plugin-oas'\nimport { Const, File, Type } from '@kubb/react'\nimport type { KubbNode } from '@kubb/react/types'\nimport * as parserZod from '../parser/index.ts'\nimport type { PluginZod } from '../types.ts'\n\ntype Props = {\n name: string\n typeName?: string\n inferTypeName?: string\n tree: Array<Schema>\n description?: string\n coercion: PluginZod['resolvedOptions']['coercion']\n mapper: PluginZod['resolvedOptions']['mapper']\n keysToOmit?: string[]\n}\n\nexport function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, keysToOmit, description }: Props): KubbNode {\n const hasTuple = tree.some((item) => isKeyword(item, schemaKeywords.tuple))\n\n const output = parserZod\n .sort(tree)\n .filter((item) => {\n if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) {\n return false\n }\n\n return true\n })\n .map((schema, _index, siblings) =>\n parserZod.parse({ parent: undefined, current: schema, siblings }, { name, keysToOmit, typeName: typeName, description, mapper, coercion }),\n )\n .filter(Boolean)\n .join('')\n\n const suffix = output.endsWith('.nullable()') ? '.unwrap().and' : '.and'\n\n return (\n <>\n <File.Source name={name} isExportable isIndexable>\n <Const\n export\n name={name}\n JSDoc={{\n comments: [description ? `@description ${transformers.jsStringEscape(description)}` : undefined].filter(Boolean),\n }}\n >\n {[\n output,\n keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(',')} }))` : undefined,\n typeName ? ` as z.ZodType<${typeName}>` : '',\n ]\n .filter(Boolean)\n .join('') || 'z.undefined()'}\n </Const>\n </File.Source>\n {inferTypeName && (\n <File.Source name={inferTypeName} isExportable isIndexable isTypeOnly>\n <Type export name={inferTypeName}>\n {`z.infer<typeof ${name}>`}\n </Type>\n </File.Source>\n )}\n </>\n )\n}\n"]}
|