@kubb/plugin-zod 3.16.2 → 3.16.4

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.
Files changed (53) hide show
  1. package/dist/components-CJ6RN1R2.js +414 -0
  2. package/dist/components-CJ6RN1R2.js.map +1 -0
  3. package/dist/components-GvkeO2ig.cjs +454 -0
  4. package/dist/components-GvkeO2ig.cjs.map +1 -0
  5. package/dist/components.cjs +3 -15
  6. package/dist/components.d.cts +56 -26
  7. package/dist/components.d.ts +56 -26
  8. package/dist/components.js +3 -3
  9. package/dist/generators-C3ALr3ph.js +254 -0
  10. package/dist/generators-C3ALr3ph.js.map +1 -0
  11. package/dist/generators-D3uH7-vO.cjs +265 -0
  12. package/dist/generators-D3uH7-vO.cjs.map +1 -0
  13. package/dist/generators.cjs +4 -16
  14. package/dist/generators.d.cts +8 -8
  15. package/dist/generators.d.ts +8 -8
  16. package/dist/generators.js +4 -4
  17. package/dist/index.cjs +103 -137
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +6 -7
  20. package/dist/index.d.ts +6 -7
  21. package/dist/index.js +103 -131
  22. package/dist/index.js.map +1 -1
  23. package/dist/types-B0UqdcbG.d.cts +1237 -0
  24. package/dist/types-YpNWeJUW.d.ts +1237 -0
  25. package/dist/utils/v4.cjs +0 -0
  26. package/dist/utils/v4.d.cts +38 -0
  27. package/dist/utils/v4.d.ts +38 -0
  28. package/dist/utils/v4.js +1 -0
  29. package/dist/utils.cjs +0 -4
  30. package/dist/utils.d.cts +18 -24
  31. package/dist/utils.d.ts +18 -24
  32. package/dist/utils.js +1 -3
  33. package/package.json +32 -31
  34. package/src/generators/zodGenerator.tsx +2 -2
  35. package/src/plugin.ts +2 -3
  36. package/src/utils/v4/ToZod.ts +61 -0
  37. package/src/utils/v4/index.ts +1 -0
  38. package/dist/chunk-4QMHDKCS.js +0 -453
  39. package/dist/chunk-4QMHDKCS.js.map +0 -1
  40. package/dist/chunk-6LDDO2JJ.cjs +0 -184
  41. package/dist/chunk-6LDDO2JJ.cjs.map +0 -1
  42. package/dist/chunk-FYI4GRXP.cjs +0 -460
  43. package/dist/chunk-FYI4GRXP.cjs.map +0 -1
  44. package/dist/chunk-I74P26CO.js +0 -181
  45. package/dist/chunk-I74P26CO.js.map +0 -1
  46. package/dist/components.cjs.map +0 -1
  47. package/dist/components.js.map +0 -1
  48. package/dist/generators.cjs.map +0 -1
  49. package/dist/generators.js.map +0 -1
  50. package/dist/types-BOF1ntMm.d.cts +0 -130
  51. package/dist/types-BOF1ntMm.d.ts +0 -130
  52. package/dist/utils.cjs.map +0 -1
  53. package/dist/utils.js.map +0 -1
@@ -0,0 +1,414 @@
1
+ import transformers from "@kubb/core/transformers";
2
+ import { SchemaGenerator, isKeyword, schemaKeywords } from "@kubb/plugin-oas";
3
+ import { Const, File, Type } from "@kubb/react";
4
+ import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
5
+
6
+ //#region src/components/Operations.tsx
7
+ function Operations({ name, operations }) {
8
+ const operationsJSON = operations.reduce((prev, acc) => {
9
+ prev[`"${acc.operation.getOperationId()}"`] = acc.data;
10
+ return prev;
11
+ }, {});
12
+ const pathsJSON = operations.reduce((prev, acc) => {
13
+ prev[`"${acc.operation.path}"`] = {
14
+ ...prev[`"${acc.operation.path}"`] || {},
15
+ [acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
16
+ };
17
+ return prev;
18
+ }, {});
19
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
20
+ name,
21
+ isExportable: true,
22
+ isIndexable: true,
23
+ children: /* @__PURE__ */ jsx(Const, {
24
+ export: true,
25
+ name,
26
+ asConst: true,
27
+ children: `{${transformers.stringifyObject(operationsJSON)}}`
28
+ })
29
+ }), /* @__PURE__ */ jsx(File.Source, {
30
+ name: "paths",
31
+ isExportable: true,
32
+ isIndexable: true,
33
+ children: /* @__PURE__ */ jsx(Const, {
34
+ export: true,
35
+ name: "paths",
36
+ asConst: true,
37
+ children: `{${transformers.stringifyObject(pathsJSON)}}`
38
+ })
39
+ })] });
40
+ }
41
+
42
+ //#endregion
43
+ //#region src/parser.ts
44
+ const zodKeywordMapper = {
45
+ any: () => "z.any()",
46
+ unknown: () => "z.unknown()",
47
+ void: () => "z.void()",
48
+ number: (coercion, min, max) => {
49
+ return [
50
+ coercion ? "z.coerce.number()" : "z.number()",
51
+ min !== void 0 ? `.min(${min})` : void 0,
52
+ max !== void 0 ? `.max(${max})` : void 0
53
+ ].filter(Boolean).join("");
54
+ },
55
+ integer: (coercion, min, max, version = "3") => {
56
+ return [
57
+ coercion ? "z.coerce.number().int()" : version === "4" ? "z.int()" : "z.number().int()",
58
+ min !== void 0 ? `.min(${min})` : void 0,
59
+ max !== void 0 ? `.max(${max})` : void 0
60
+ ].filter(Boolean).join("");
61
+ },
62
+ interface: (value, strict) => {
63
+ if (strict) return `z.strictInterface({
64
+ ${value}
65
+ })`;
66
+ return `z.interface({
67
+ ${value}
68
+ })`;
69
+ },
70
+ object: (value, strict, version = "3") => {
71
+ if (version === "4" && strict) return `z.strictObject({
72
+ ${value}
73
+ })`;
74
+ if (strict) return `z.object({
75
+ ${value}
76
+ }).strict()`;
77
+ return `z.object({
78
+ ${value}
79
+ })`;
80
+ },
81
+ string: (coercion, min, max) => {
82
+ return [
83
+ coercion ? "z.coerce.string()" : "z.string()",
84
+ min !== void 0 ? `.min(${min})` : void 0,
85
+ max !== void 0 ? `.max(${max})` : void 0
86
+ ].filter(Boolean).join("");
87
+ },
88
+ boolean: () => "z.boolean()",
89
+ undefined: () => "z.undefined()",
90
+ nullable: () => ".nullable()",
91
+ null: () => "z.null()",
92
+ nullish: () => ".nullish()",
93
+ array: (items = [], min, max, unique) => {
94
+ return [
95
+ `z.array(${items?.join("")})`,
96
+ min !== void 0 ? `.min(${min})` : void 0,
97
+ max !== void 0 ? `.max(${max})` : void 0,
98
+ unique ? `.refine(items => new Set(items).size === items.length, { message: "Array entries must be unique" })` : void 0
99
+ ].filter(Boolean).join("");
100
+ },
101
+ tuple: (items = []) => `z.tuple([${items?.join(", ")}])`,
102
+ enum: (items = []) => `z.enum([${items?.join(", ")}])`,
103
+ union: (items = []) => `z.union([${items?.join(", ")}])`,
104
+ const: (value) => `z.literal(${value ?? ""})`,
105
+ datetime: (offset = false, local = false, version = "3") => {
106
+ if (offset) return version === "4" ? `z.iso.datetime({ offset: ${offset} })` : `z.string().datetime({ offset: ${offset} })`;
107
+ if (local) return version === "4" ? `z.iso.datetime({ local: ${local} })` : `z.string().datetime({ local: ${local} })`;
108
+ return "z.string().datetime()";
109
+ },
110
+ date: (type = "string", coercion, version = "3") => {
111
+ if (type === "string") return version === "4" ? "z.iso.date()" : "z.string().date()";
112
+ if (coercion) return "z.coerce.date()";
113
+ return "z.date()";
114
+ },
115
+ time: (type = "string", coercion, version = "3") => {
116
+ if (type === "string") return version === "4" ? "z.iso.time()" : "z.string().time()";
117
+ if (coercion) return "z.coerce.date()";
118
+ return "z.date()";
119
+ },
120
+ uuid: (coercion, version = "3") => version === "4" ? coercion ? "z.coerce.string().uuid()" : "z.uuid()" : coercion ? "z.coerce.string().uuid()" : "z.string().uuid()",
121
+ url: (coercion, version = "3") => version === "4" ? coercion ? "z.coerce.string().url()" : "z.url()" : coercion ? "z.coerce.string().url()" : "z.string().url()",
122
+ default: (value) => {
123
+ if (typeof value === "object") return ".default({})";
124
+ return `.default(${value ?? ""})`;
125
+ },
126
+ and: (items = []) => items?.map((item) => `.and(${item})`).join(""),
127
+ describe: (value = "") => `.describe(${value})`,
128
+ min: (value) => `.min(${value ?? ""})`,
129
+ max: (value) => `.max(${value ?? ""})`,
130
+ optional: () => ".optional()",
131
+ matches: (value = "", coercion) => coercion ? `z.coerce.string().regex(${value})` : `z.string().regex(${value})`,
132
+ email: (coercion, version = "3") => version === "4" ? coercion ? "z.coerce.string().email()" : "z.email()" : coercion ? "z.coerce.string().email()" : "z.string().email()",
133
+ firstName: void 0,
134
+ lastName: void 0,
135
+ password: void 0,
136
+ phone: void 0,
137
+ readOnly: void 0,
138
+ writeOnly: void 0,
139
+ ref: (value, version = "3") => {
140
+ if (!value) return void 0;
141
+ return version === "4" ? value : `z.lazy(() => ${value})`;
142
+ },
143
+ blob: () => "z.instanceof(File)",
144
+ deprecated: void 0,
145
+ example: void 0,
146
+ schema: void 0,
147
+ catchall: (value) => value ? `.catchall(${value})` : void 0,
148
+ name: void 0
149
+ };
150
+ /**
151
+ * @link based on https://github.com/cellular/oazapfts/blob/7ba226ebb15374e8483cc53e7532f1663179a22c/src/codegen/generate.ts#L398
152
+ */
153
+ function sort(items) {
154
+ const order = [
155
+ schemaKeywords.string,
156
+ schemaKeywords.datetime,
157
+ schemaKeywords.date,
158
+ schemaKeywords.time,
159
+ schemaKeywords.tuple,
160
+ schemaKeywords.number,
161
+ schemaKeywords.object,
162
+ schemaKeywords.enum,
163
+ schemaKeywords.url,
164
+ schemaKeywords.email,
165
+ schemaKeywords.firstName,
166
+ schemaKeywords.lastName,
167
+ schemaKeywords.password,
168
+ schemaKeywords.matches,
169
+ schemaKeywords.uuid,
170
+ schemaKeywords.null,
171
+ schemaKeywords.min,
172
+ schemaKeywords.max,
173
+ schemaKeywords.default,
174
+ schemaKeywords.describe,
175
+ schemaKeywords.optional,
176
+ schemaKeywords.nullable,
177
+ schemaKeywords.nullish
178
+ ];
179
+ if (!items) return [];
180
+ return transformers.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
181
+ }
182
+ const shouldCoerce = (coercion, type) => {
183
+ if (coercion === void 0) return false;
184
+ if (typeof coercion === "boolean") return coercion;
185
+ return !!coercion[type];
186
+ };
187
+ function parse({ parent, current, name, siblings }, options) {
188
+ const value = zodKeywordMapper[current.keyword];
189
+ const hasMatches = siblings.some((it) => isKeyword(it, schemaKeywords.matches));
190
+ const hasRef = siblings.some((it) => isKeyword(it, schemaKeywords.ref));
191
+ if (hasMatches && hasRef && isKeyword(current, schemaKeywords.matches)) return void 0;
192
+ if (!value) return void 0;
193
+ if (isKeyword(current, schemaKeywords.union)) {
194
+ if (Array.isArray(current.args) && current.args.length === 1) return parse({
195
+ parent,
196
+ name,
197
+ current: current.args[0],
198
+ siblings
199
+ }, options);
200
+ if (Array.isArray(current.args) && !current.args.length) return "";
201
+ return zodKeywordMapper.union(sort(current.args).map((schema, _index, siblings$1) => parse({
202
+ parent: current,
203
+ name,
204
+ current: schema,
205
+ siblings: siblings$1
206
+ }, options)).filter(Boolean));
207
+ }
208
+ if (isKeyword(current, schemaKeywords.and)) {
209
+ const items = sort(current.args).filter((schema) => {
210
+ return ![schemaKeywords.optional, schemaKeywords.describe].includes(schema.keyword);
211
+ }).map((schema, _index, siblings$1) => parse({
212
+ parent: current,
213
+ name,
214
+ current: schema,
215
+ siblings: siblings$1
216
+ }, options)).filter(Boolean);
217
+ return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
218
+ }
219
+ if (isKeyword(current, schemaKeywords.array)) return zodKeywordMapper.array(sort(current.args.items).map((schemas, _index, siblings$1) => parse({
220
+ parent: current,
221
+ name,
222
+ current: schemas,
223
+ siblings: siblings$1
224
+ }, options)).filter(Boolean), current.args.min, current.args.max, current.args.unique);
225
+ if (isKeyword(current, schemaKeywords.enum)) {
226
+ if (current.args.asConst) {
227
+ if (current.args.items.length === 1) {
228
+ const child = {
229
+ keyword: schemaKeywords.const,
230
+ args: current.args.items[0]
231
+ };
232
+ return parse({
233
+ parent: current,
234
+ name,
235
+ current: child,
236
+ siblings: [child]
237
+ }, options);
238
+ }
239
+ return zodKeywordMapper.union(current.args.items.map((schema) => ({
240
+ keyword: schemaKeywords.const,
241
+ args: schema
242
+ })).map((schema, _index, siblings$1) => {
243
+ return parse({
244
+ parent: current,
245
+ name,
246
+ current: schema,
247
+ siblings: siblings$1
248
+ }, options);
249
+ }).filter(Boolean));
250
+ }
251
+ return zodKeywordMapper.enum(current.args.items.map((schema) => {
252
+ if (schema.format === "boolean") return transformers.stringify(schema.value);
253
+ if (schema.format === "number") return transformers.stringify(schema.value);
254
+ return transformers.stringify(schema.value);
255
+ }));
256
+ }
257
+ if (isKeyword(current, schemaKeywords.ref)) return zodKeywordMapper.ref(current.args?.name, options.version);
258
+ if (isKeyword(current, schemaKeywords.object)) {
259
+ const propertyEntries = Object.entries(current.args?.properties || {}).filter((item) => {
260
+ const schema = item[1];
261
+ return schema && typeof schema.map === "function";
262
+ });
263
+ const properties = propertyEntries.map(([name$1, schemas]) => {
264
+ const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name);
265
+ const mappedName = nameSchema?.args || name$1;
266
+ if (options.mapper?.[mappedName]) return `"${name$1}": ${options.mapper?.[mappedName]}`;
267
+ const baseSchemaOutput = sort(schemas).map((schema) => parse({
268
+ parent: current,
269
+ name: name$1,
270
+ current: schema,
271
+ siblings: schemas
272
+ }, options)).filter(Boolean).join("");
273
+ const objectValue = options.wrapOutput ? options.wrapOutput({
274
+ output: baseSchemaOutput,
275
+ schema: options.rawSchema?.properties?.[name$1]
276
+ }) || baseSchemaOutput : baseSchemaOutput;
277
+ if (options.version === "4" && SchemaGenerator.find(schemas, schemaKeywords.ref)) return `get ${name$1}(){
278
+ return ${objectValue}
279
+ }`;
280
+ return `"${name$1}": ${objectValue}`;
281
+ }).join(",\n");
282
+ const additionalProperties = current.args?.additionalProperties?.length ? current.args.additionalProperties.map((schema, _index, siblings$1) => parse({
283
+ parent: current,
284
+ name,
285
+ current: schema,
286
+ siblings: siblings$1
287
+ }, options)).filter(Boolean).join("") : void 0;
288
+ const text = [zodKeywordMapper.object(properties, current.args?.strict, options.version), additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0].filter(Boolean);
289
+ return text.join("");
290
+ }
291
+ if (isKeyword(current, schemaKeywords.tuple)) return zodKeywordMapper.tuple(current.args.items.map((schema, _index, siblings$1) => parse({
292
+ parent: current,
293
+ name,
294
+ current: schema,
295
+ siblings: siblings$1
296
+ }, options)).filter(Boolean));
297
+ if (isKeyword(current, schemaKeywords.const)) {
298
+ if (current.args.format === "number" && current.args.value !== void 0) return zodKeywordMapper.const(Number(current.args.value));
299
+ if (current.args.format === "boolean" && current.args.value !== void 0) return zodKeywordMapper.const(current.args.value);
300
+ return zodKeywordMapper.const(transformers.stringify(current.args.value));
301
+ }
302
+ if (isKeyword(current, schemaKeywords.matches)) {
303
+ if (current.args) return zodKeywordMapper.matches(transformers.toRegExpString(current.args, null), shouldCoerce(options.coercion, "strings"));
304
+ }
305
+ if (isKeyword(current, schemaKeywords.default)) {
306
+ if (current.args) return zodKeywordMapper.default(current.args);
307
+ }
308
+ if (isKeyword(current, schemaKeywords.describe)) {
309
+ if (current.args) return zodKeywordMapper.describe(transformers.stringify(current.args.toString()));
310
+ }
311
+ if (isKeyword(current, schemaKeywords.string)) return zodKeywordMapper.string(shouldCoerce(options.coercion, "strings"));
312
+ if (isKeyword(current, schemaKeywords.uuid)) return zodKeywordMapper.uuid(shouldCoerce(options.coercion, "strings"), options.version);
313
+ if (isKeyword(current, schemaKeywords.email)) return zodKeywordMapper.email(shouldCoerce(options.coercion, "strings"), options.version);
314
+ if (isKeyword(current, schemaKeywords.url)) return zodKeywordMapper.url(shouldCoerce(options.coercion, "strings"), options.version);
315
+ if (isKeyword(current, schemaKeywords.number)) return zodKeywordMapper.number(shouldCoerce(options.coercion, "numbers"));
316
+ if (isKeyword(current, schemaKeywords.integer)) return zodKeywordMapper.integer(shouldCoerce(options.coercion, "numbers"), void 0, void 0, options.version);
317
+ if (isKeyword(current, schemaKeywords.min)) return zodKeywordMapper.min(current.args);
318
+ if (isKeyword(current, schemaKeywords.max)) return zodKeywordMapper.max(current.args);
319
+ if (isKeyword(current, schemaKeywords.datetime)) return zodKeywordMapper.datetime(current.args.offset, current.args.local, options.version);
320
+ if (isKeyword(current, schemaKeywords.date)) return zodKeywordMapper.date(current.args.type, shouldCoerce(options.coercion, "dates"), options.version);
321
+ if (isKeyword(current, schemaKeywords.time)) return zodKeywordMapper.time(current.args.type, shouldCoerce(options.coercion, "dates"), options.version);
322
+ if (current.keyword in zodKeywordMapper && "args" in current) {
323
+ const value$1 = zodKeywordMapper[current.keyword];
324
+ return value$1(current.args);
325
+ }
326
+ if (isKeyword(current, schemaKeywords.optional)) {
327
+ if (siblings.some((schema) => isKeyword(schema, schemaKeywords.default))) return "";
328
+ return value();
329
+ }
330
+ if (current.keyword in zodKeywordMapper) return value();
331
+ return void 0;
332
+ }
333
+
334
+ //#endregion
335
+ //#region src/components/Zod.tsx
336
+ function Zod({ name, typeName, tree, rawSchema, inferTypeName, mapper, coercion, keysToOmit, description, wrapOutput, version, emptySchemaType }) {
337
+ const hasTuple = !!SchemaGenerator.deepSearch(tree, schemaKeywords.tuple);
338
+ const schemas = sort(tree).filter((item) => {
339
+ if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) return false;
340
+ return true;
341
+ });
342
+ const output = schemas.map((schema, _index, siblings) => parse({
343
+ parent: void 0,
344
+ current: schema,
345
+ siblings
346
+ }, {
347
+ name,
348
+ keysToOmit,
349
+ typeName,
350
+ description,
351
+ mapper,
352
+ coercion,
353
+ wrapOutput,
354
+ rawSchema,
355
+ version
356
+ })).filter(Boolean).join("");
357
+ let suffix = "";
358
+ const firstSchema = schemas.at(0);
359
+ const lastSchema = schemas.at(-1);
360
+ if (lastSchema && isKeyword(lastSchema, schemaKeywords.nullable)) if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref)) if (version === "3") suffix = ".unwrap().schema.unwrap()";
361
+ else suffix = ".unwrap().unwrap()";
362
+ else suffix = ".unwrap()";
363
+ else if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref) && version === "3") suffix = ".schema";
364
+ const emptyValue = parse({
365
+ parent: void 0,
366
+ current: { keyword: schemaKeywords[emptySchemaType] },
367
+ siblings: []
368
+ }, {
369
+ name,
370
+ keysToOmit,
371
+ typeName,
372
+ description,
373
+ mapper,
374
+ coercion,
375
+ wrapOutput,
376
+ rawSchema,
377
+ version
378
+ });
379
+ const baseSchemaOutput = [output, keysToOmit?.length ? `${suffix}.omit({ ${keysToOmit.map((key) => `${key}: true`).join(",")} })` : void 0].filter(Boolean).join("") || emptyValue || "";
380
+ const wrappedSchemaOutput = wrapOutput ? wrapOutput({
381
+ output: baseSchemaOutput,
382
+ schema: rawSchema
383
+ }) || baseSchemaOutput : baseSchemaOutput;
384
+ const finalOutput = typeName ? `${wrappedSchemaOutput} as unknown as ToZod<${typeName}>` : wrappedSchemaOutput;
385
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
386
+ name,
387
+ isExportable: true,
388
+ isIndexable: true,
389
+ children: /* @__PURE__ */ jsx(Const, {
390
+ export: true,
391
+ name,
392
+ JSDoc: { comments: [description ? `@description ${transformers.jsStringEscape(description)}` : void 0].filter(Boolean) },
393
+ children: finalOutput
394
+ })
395
+ }), inferTypeName && /* @__PURE__ */ jsxs(File.Source, {
396
+ name: inferTypeName,
397
+ isExportable: true,
398
+ isIndexable: true,
399
+ isTypeOnly: true,
400
+ children: [typeName && /* @__PURE__ */ jsx(Type, {
401
+ export: true,
402
+ name: inferTypeName,
403
+ children: typeName
404
+ }), !typeName && /* @__PURE__ */ jsx(Type, {
405
+ export: true,
406
+ name: inferTypeName,
407
+ children: `z.infer<typeof ${name}>`
408
+ })]
409
+ })] });
410
+ }
411
+
412
+ //#endregion
413
+ export { Operations, Zod };
414
+ //# sourceMappingURL=components-CJ6RN1R2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"components-CJ6RN1R2.js","names":["coercion?: boolean","min?: number","max?: number","version: '3' | '4'","value?: string","strict?: boolean","items: string[]","unique?: boolean","value?: string | number | boolean","type: 'date' | 'string'","value?: string | number | true | object","value?: number","items?: Schema[]","order: string[]","coercion: ParserOptions['coercion'] | undefined","type: 'dates' | 'strings' | 'numbers'","options: ParserOptions","siblings","schema: Schema","name","value"],"sources":["../src/components/Operations.tsx","../src/parser.ts","../src/components/Zod.tsx"],"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'\n\ntype Props = {\n name: string\n operations: Array<{ operation: Operation; data: SchemaNames }>\n}\n\nexport function Operations({ name, operations }: Props) {\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 from '@kubb/core/transformers'\nimport type { SchemaObject } from '@kubb/oas'\n\nimport type { Schema, SchemaKeywordBase, SchemaMapper } from '@kubb/plugin-oas'\nimport { isKeyword, SchemaGenerator, type SchemaKeywordMapper, type SchemaTree, schemaKeywords } from '@kubb/plugin-oas'\n\nconst zodKeywordMapper = {\n any: () => 'z.any()',\n unknown: () => 'z.unknown()',\n void: () => 'z.void()',\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, version: '3' | '4' = '3') => {\n return [\n coercion ? 'z.coerce.number().int()' : version === '4' ? 'z.int()' : 'z.number().int()',\n min !== undefined ? `.min(${min})` : undefined,\n max !== undefined ? `.max(${max})` : undefined,\n ]\n .filter(Boolean)\n .join('')\n },\n interface: (value?: string, strict?: boolean) => {\n if (strict) {\n return `z.strictInterface({\n ${value}\n })`\n }\n return `z.interface({\n ${value}\n })`\n },\n object: (value?: string, strict?: boolean, version: '3' | '4' = '3') => {\n if (version === '4' && strict) {\n return `z.strictObject({\n ${value}\n })`\n }\n\n if (strict) {\n return `z.object({\n ${value}\n }).strict()`\n }\n\n return `z.object({\n ${value}\n })`\n },\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 //support for discriminatedUnion\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, unique?: boolean) => {\n return [\n `z.array(${items?.join('')})`,\n min !== undefined ? `.min(${min})` : undefined,\n max !== undefined ? `.max(${max})` : undefined,\n unique ? `.refine(items => new Set(items).size === items.length, { message: \"Array entries must be unique\" })` : undefined,\n ]\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, version: '3' | '4' = '3') => {\n if (offset) {\n return version === '4' ? `z.iso.datetime({ offset: ${offset} })` : `z.string().datetime({ offset: ${offset} })`\n }\n\n if (local) {\n return version === '4' ? `z.iso.datetime({ local: ${local} })` : `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, version: '3' | '4' = '3') => {\n if (type === 'string') {\n return version === '4' ? 'z.iso.date()' : '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, version: '3' | '4' = '3') => {\n if (type === 'string') {\n return version === '4' ? 'z.iso.time()' : 'z.string().time()'\n }\n\n if (coercion) {\n return 'z.coerce.date()'\n }\n\n return 'z.date()'\n },\n uuid: (coercion?: boolean, version: '3' | '4' = '3') =>\n version === '4' ? (coercion ? 'z.coerce.string().uuid()' : 'z.uuid()') : coercion ? 'z.coerce.string().uuid()' : 'z.string().uuid()',\n url: (coercion?: boolean, version: '3' | '4' = '3') =>\n version === '4' ? (coercion ? 'z.coerce.string().url()' : 'z.url()') : coercion ? 'z.coerce.string().url()' : 'z.string().url()',\n default: (value?: string | number | true | object) => {\n if (typeof value === 'object') {\n return '.default({})'\n }\n return `.default(${value ?? ''})`\n },\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 = '', coercion?: boolean) => (coercion ? `z.coerce.string().regex(${value})` : `z.string().regex(${value})`),\n email: (coercion?: boolean, version: '3' | '4' = '3') =>\n version === '4' ? (coercion ? 'z.coerce.string().email()' : 'z.email()') : coercion ? 'z.coerce.string().email()' : 'z.string().email()',\n firstName: undefined,\n lastName: undefined,\n password: undefined,\n phone: undefined,\n readOnly: undefined,\n writeOnly: undefined,\n ref: (value?: string, version: '3' | '4' = '3') => {\n if (!value) {\n return undefined\n }\n\n return version === '4' ? value : `z.lazy(() => ${value})`\n },\n blob: () => 'z.instanceof(File)',\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.null,\n schemaKeywords.min,\n schemaKeywords.max,\n schemaKeywords.default,\n schemaKeywords.describe,\n schemaKeywords.optional,\n schemaKeywords.nullable,\n schemaKeywords.nullish,\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 wrapOutput?: (opts: { output: string; schema: any }) => string | undefined\n rawSchema: SchemaObject\n version: '3' | '4'\n}\n\nexport function parse({ parent, current, name, siblings }: SchemaTree, options: ParserOptions): string | undefined {\n const value = zodKeywordMapper[current.keyword as keyof typeof zodKeywordMapper]\n\n // Early exit: if siblings contain both matches and ref → skip matches entirely\n const hasMatches = siblings.some((it) => isKeyword(it, schemaKeywords.matches))\n const hasRef = siblings.some((it) => isKeyword(it, schemaKeywords.ref))\n\n if (hasMatches && hasRef && isKeyword(current, schemaKeywords.matches)) {\n return undefined // strip matches\n }\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, name: name, 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, name: name, 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, name: name, 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, name: name, current: schemas, siblings }, options))\n .filter(Boolean),\n current.args.min,\n current.args.max,\n current.args.unique,\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, name: name, 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, name: name, 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, options.version)\n }\n\n if (isKeyword(current, schemaKeywords.object)) {\n const propertyEntries = Object.entries(current.args?.properties || {}).filter((item) => {\n const schema = item[1]\n return schema && typeof schema.map === 'function'\n })\n\n const properties = propertyEntries\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 const baseSchemaOutput = sort(schemas)\n .map((schema) => parse({ parent: current, name, current: schema, siblings: schemas }, options))\n .filter(Boolean)\n .join('')\n\n const objectValue = options.wrapOutput\n ? options.wrapOutput({ output: baseSchemaOutput, schema: options.rawSchema?.properties?.[name] }) || baseSchemaOutput\n : baseSchemaOutput\n\n if (options.version === '4' && SchemaGenerator.find(schemas, schemaKeywords.ref)) {\n return `get ${name}(){\n return ${objectValue}\n }`\n }\n\n return `\"${name}\": ${objectValue}`\n })\n .join(',\\n')\n\n const additionalProperties = current.args?.additionalProperties?.length\n ? current.args.additionalProperties\n .map((schema, _index, siblings) => parse({ parent: current, name: name, current: schema, siblings }, options))\n .filter(Boolean)\n .join('')\n : undefined\n\n const text = [\n zodKeywordMapper.object(properties, current.args?.strict, options.version),\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, name: name, 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(current.args.value))\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, null), shouldCoerce(options.coercion, 'strings'))\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.uuid)) {\n return zodKeywordMapper.uuid(shouldCoerce(options.coercion, 'strings'), options.version)\n }\n\n if (isKeyword(current, schemaKeywords.email)) {\n return zodKeywordMapper.email(shouldCoerce(options.coercion, 'strings'), options.version)\n }\n\n if (isKeyword(current, schemaKeywords.url)) {\n return zodKeywordMapper.url(shouldCoerce(options.coercion, 'strings'), options.version)\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'), undefined, undefined, options.version)\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, options.version)\n }\n\n if (isKeyword(current, schemaKeywords.date)) {\n return zodKeywordMapper.date(current.args.type, shouldCoerce(options.coercion, 'dates'), options.version)\n }\n\n if (isKeyword(current, schemaKeywords.time)) {\n return zodKeywordMapper.time(current.args.type, shouldCoerce(options.coercion, 'dates'), options.version)\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 { SchemaObject } from '@kubb/oas'\nimport { isKeyword, type Schema, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Const, File, Type } from '@kubb/react'\nimport * as parserZod from '../parser.ts'\nimport type { PluginZod } from '../types.ts'\n\ntype Props = {\n name: string\n typeName?: string\n inferTypeName?: string\n tree: Array<Schema>\n rawSchema: SchemaObject\n description?: string\n coercion: PluginZod['resolvedOptions']['coercion']\n mapper: PluginZod['resolvedOptions']['mapper']\n keysToOmit?: string[]\n wrapOutput?: PluginZod['resolvedOptions']['wrapOutput']\n version: '3' | '4'\n emptySchemaType: PluginZod['resolvedOptions']['emptySchemaType']\n}\n\nexport function Zod({\n name,\n typeName,\n tree,\n rawSchema,\n inferTypeName,\n mapper,\n coercion,\n keysToOmit,\n description,\n wrapOutput,\n version,\n emptySchemaType,\n}: Props) {\n const hasTuple = !!SchemaGenerator.deepSearch(tree, schemaKeywords.tuple)\n\n const schemas = parserZod.sort(tree).filter((item) => {\n if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) {\n return false\n }\n\n return true\n })\n\n const output = schemas\n .map((schema, _index, siblings) =>\n parserZod.parse(\n { parent: undefined, current: schema, siblings },\n { name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema, version },\n ),\n )\n .filter(Boolean)\n .join('')\n\n let suffix = ''\n const firstSchema = schemas.at(0)\n const lastSchema = schemas.at(-1)\n\n if (lastSchema && isKeyword(lastSchema, schemaKeywords.nullable)) {\n if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref)) {\n if (version === '3') {\n suffix = '.unwrap().schema.unwrap()'\n } else {\n suffix = '.unwrap().unwrap()'\n }\n } else {\n suffix = '.unwrap()'\n }\n } else {\n if (firstSchema && isKeyword(firstSchema, schemaKeywords.ref) && version === '3') {\n suffix = '.schema'\n }\n }\n\n const emptyValue = parserZod.parse(\n {\n parent: undefined,\n current: {\n keyword: schemaKeywords[emptySchemaType],\n },\n siblings: [],\n },\n { name, keysToOmit, typeName, description, mapper, coercion, wrapOutput, rawSchema, version },\n )\n\n const baseSchemaOutput =\n [output, keysToOmit?.length ? `${suffix}.omit({ ${keysToOmit.map((key) => `${key}: true`).join(',')} })` : undefined].filter(Boolean).join('') ||\n emptyValue ||\n ''\n const wrappedSchemaOutput = wrapOutput ? wrapOutput({ output: baseSchemaOutput, schema: rawSchema }) || baseSchemaOutput : baseSchemaOutput\n const finalOutput = typeName ? `${wrappedSchemaOutput} as unknown as ToZod<${typeName}>` : wrappedSchemaOutput\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 {finalOutput}\n </Const>\n </File.Source>\n {inferTypeName && (\n <File.Source name={inferTypeName} isExportable isIndexable isTypeOnly>\n {typeName && (\n <Type export name={inferTypeName}>\n {typeName}\n </Type>\n )}\n {!typeName && (\n <Type export name={inferTypeName}>\n {`z.infer<typeof ${name}>`}\n </Type>\n )}\n </File.Source>\n )}\n </>\n )\n}\n"],"mappings":";;;;;;AAWA,SAAgB,WAAW,EAAE,MAAM,YAAmB,EAAE;CACtD,MAAM,iBAAiB,WAAW,OAChC,CAAC,MAAM,QAAQ;EACb,KAAK,CAAC,CAAC,EAAE,IAAI,UAAU,gBAAgB,CAAC,CAAC,CAAC,IAAI,IAAI;AAElD,SAAO;CACR,GACD,CAAE,EACH;CAED,MAAM,YAAY,WAAW,OAC3B,CAAC,MAAM,QA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