@kubb/plugin-zod 3.0.0-alpha.5 → 3.0.0-alpha.6

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.
@@ -1,1250 +0,0 @@
1
- // src/components/Operations.tsx
2
- import { useOperationManager, useOperations } from "@kubb/plugin-oas/hooks";
3
- import { Const, File, Parser, useApp } from "@kubb/react";
4
- import transformers from "@kubb/core/transformers";
5
- import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
6
- function Template({ operationsName, pathsName, operations }) {
7
- const { groupSchemasByName } = useOperationManager();
8
- const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
9
- const operationsJSON = transformedOperations.reduce(
10
- (prev, acc) => {
11
- prev[`"${acc.operation.getOperationId()}"`] = acc.data;
12
- return prev;
13
- },
14
- {}
15
- );
16
- const pathsJSON = transformedOperations.reduce(
17
- (prev, acc) => {
18
- prev[`"${acc.operation.path}"`] = {
19
- ...prev[`"${acc.operation.path}"`] || {},
20
- [acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
21
- };
22
- return prev;
23
- },
24
- {}
25
- );
26
- return /* @__PURE__ */ jsxs(Fragment, { children: [
27
- /* @__PURE__ */ jsx(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers.stringifyObject(operationsJSON)}}` }),
28
- /* @__PURE__ */ jsx(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers.stringifyObject(pathsJSON)}}` })
29
- ] });
30
- }
31
- function RootTemplate({ children }) {
32
- const {
33
- mode,
34
- pluginManager,
35
- plugin: {
36
- key: pluginKey,
37
- options: { extName }
38
- }
39
- } = useApp();
40
- const { getFile } = useOperationManager();
41
- const operations = useOperations();
42
- const { groupSchemasByName } = useOperationManager();
43
- const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
44
- const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
45
- const imports = Object.entries(transformedOperations).map(([_key, { data, operation }], index) => {
46
- const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
47
- return /* @__PURE__ */ jsx(File.Import, { extName, name: names, root: file.path, path: getFile(operation).path }, index);
48
- }).filter(Boolean);
49
- return /* @__PURE__ */ jsx(Parser, { language: "typescript", children: /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, exportable: false, children: [
50
- mode === "split" && imports,
51
- /* @__PURE__ */ jsx(File.Source, { children })
52
- ] }) });
53
- }
54
- var defaultTemplates = { default: Template, root: RootTemplate };
55
- function Operations({ Template: Template3 = defaultTemplates.default }) {
56
- const operations = useOperations();
57
- return /* @__PURE__ */ jsx(Template3, { operationsName: "operations", pathsName: "paths", operations });
58
- }
59
- Operations.File = function(props) {
60
- const templates = { ...defaultTemplates, ...props.templates };
61
- const Template3 = templates.default;
62
- const RootTemplate2 = templates.root;
63
- return /* @__PURE__ */ jsx(RootTemplate2, { children: /* @__PURE__ */ jsx(Operations, { Template: Template3 }) });
64
- };
65
- Operations.templates = defaultTemplates;
66
-
67
- // src/components/Schema.tsx
68
- import { Oas as Oas6 } from "@kubb/plugin-oas/components";
69
- import { Const as Const2, File as File6, Type as Type2, useApp as useApp6, useFile } from "@kubb/react";
70
-
71
- // ../plugin-ts/src/plugin.ts
72
- import path from "path";
73
- import { FileManager, PluginManager, createPlugin } from "@kubb/core";
74
- import { camelCase, pascalCase } from "@kubb/core/transformers";
75
- import { renderTemplate } from "@kubb/core/utils";
76
- import { pluginOasName } from "@kubb/plugin-oas";
77
-
78
- // ../plugin-ts/src/OperationGenerator.tsx
79
- import { OperationGenerator as Generator2 } from "@kubb/plugin-oas";
80
- import { Oas as Oas4 } from "@kubb/plugin-oas/components";
81
- import { App as App2, createRoot as createRoot2 } from "@kubb/react";
82
-
83
- // ../plugin-ts/src/components/OasType.tsx
84
- import { Parser as Parser2, File as File2, Type, useApp as useApp2 } from "@kubb/react";
85
- import { useOas } from "@kubb/plugin-oas/hooks";
86
- import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
87
- function Template2({ name, typeName, api }) {
88
- return /* @__PURE__ */ jsxs2(Fragment2, { children: [
89
- `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
90
- /* @__PURE__ */ jsx2("br", {}),
91
- /* @__PURE__ */ jsx2(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` })
92
- ] });
93
- }
94
- var defaultTemplates2 = { default: Template2 };
95
- function OasType({ name, typeName, Template: Template3 = defaultTemplates2.default }) {
96
- const oas = useOas();
97
- return /* @__PURE__ */ jsx2(Template3, { name, typeName, api: oas.api });
98
- }
99
- OasType.File = function({ name, typeName, templates = defaultTemplates2 }) {
100
- const {
101
- pluginManager,
102
- plugin: { key: pluginKey }
103
- } = useApp2();
104
- const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
105
- const Template3 = templates.default;
106
- return /* @__PURE__ */ jsx2(Parser2, { language: "typescript", children: /* @__PURE__ */ jsxs2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
107
- /* @__PURE__ */ jsx2(File2.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
108
- /* @__PURE__ */ jsx2(File2.Source, { children: /* @__PURE__ */ jsx2(OasType, { Template: Template3, name, typeName }) })
109
- ] }) });
110
- };
111
- OasType.templates = defaultTemplates2;
112
-
113
- // ../plugin-ts/src/components/OperationSchema.tsx
114
- import transformers4 from "@kubb/core/transformers";
115
- import { print as print2 } from "@kubb/parser-ts";
116
- import * as factory3 from "@kubb/parser-ts/factory";
117
- import { Oas as Oas3 } from "@kubb/plugin-oas/components";
118
- import { useOas as useOas2, useOperation, useOperationManager as useOperationManager2 } from "@kubb/plugin-oas/hooks";
119
- import { File as File4, Parser as Parser3, useApp as useApp4 } from "@kubb/react";
120
-
121
- // ../plugin-ts/src/SchemaGenerator.tsx
122
- import { SchemaGenerator as Generator } from "@kubb/plugin-oas";
123
- import { Oas as Oas2 } from "@kubb/plugin-oas/components";
124
- import { App, createRoot } from "@kubb/react";
125
-
126
- // ../plugin-ts/src/components/Schema.tsx
127
- import { Oas } from "@kubb/plugin-oas/components";
128
- import { File as File3, useApp as useApp3 } from "@kubb/react";
129
- import transformers3 from "@kubb/core/transformers";
130
- import { print } from "@kubb/parser-ts";
131
- import * as factory2 from "@kubb/parser-ts/factory";
132
- import { SchemaGenerator, schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
133
- import { useSchema } from "@kubb/plugin-oas/hooks";
134
-
135
- // ../plugin-ts/src/parser/index.ts
136
- import transformers2 from "@kubb/core/transformers";
137
- import * as factory from "@kubb/parser-ts/factory";
138
- import { isKeyword, schemaKeywords } from "@kubb/plugin-oas";
139
- var typeKeywordMapper = {
140
- any: () => factory.keywordTypeNodes.any,
141
- unknown: () => factory.keywordTypeNodes.unknown,
142
- number: () => factory.keywordTypeNodes.number,
143
- integer: () => factory.keywordTypeNodes.number,
144
- object: (nodes) => {
145
- if (!nodes || !nodes.length) {
146
- return factory.keywordTypeNodes.object;
147
- }
148
- return factory.createTypeLiteralNode(nodes);
149
- },
150
- string: () => factory.keywordTypeNodes.string,
151
- boolean: () => factory.keywordTypeNodes.boolean,
152
- undefined: () => factory.keywordTypeNodes.undefined,
153
- nullable: void 0,
154
- null: () => factory.keywordTypeNodes.null,
155
- nullish: void 0,
156
- array: (nodes) => {
157
- if (!nodes) {
158
- return void 0;
159
- }
160
- return factory.createArrayDeclaration({ nodes });
161
- },
162
- tuple: (nodes) => {
163
- if (!nodes) {
164
- return void 0;
165
- }
166
- return factory.createTupleTypeNode(nodes);
167
- },
168
- enum: (name) => {
169
- if (!name) {
170
- return void 0;
171
- }
172
- return factory.createTypeReferenceNode(name, void 0);
173
- },
174
- union: (nodes) => {
175
- if (!nodes) {
176
- return void 0;
177
- }
178
- return factory.createUnionDeclaration({
179
- withParentheses: true,
180
- nodes
181
- });
182
- },
183
- const: (name, format) => {
184
- if (!name) {
185
- return void 0;
186
- }
187
- if (format === "number") {
188
- return factory.createLiteralTypeNode(factory.createNumericLiteral(name));
189
- }
190
- return factory.createLiteralTypeNode(factory.createStringLiteral(name.toString()));
191
- },
192
- datetime: () => factory.keywordTypeNodes.string,
193
- date: (type = "string") => type === "string" ? factory.keywordTypeNodes.string : factory.createTypeReferenceNode(factory.createIdentifier("Date")),
194
- time: (type = "string") => type === "string" ? factory.keywordTypeNodes.string : factory.createTypeReferenceNode(factory.createIdentifier("Date")),
195
- uuid: void 0,
196
- url: void 0,
197
- strict: void 0,
198
- default: void 0,
199
- and: (nodes) => {
200
- if (!nodes) {
201
- return void 0;
202
- }
203
- return factory.createIntersectionDeclaration({
204
- withParentheses: true,
205
- nodes
206
- });
207
- },
208
- describe: void 0,
209
- min: void 0,
210
- max: void 0,
211
- optional: void 0,
212
- matches: void 0,
213
- email: void 0,
214
- firstName: void 0,
215
- lastName: void 0,
216
- password: void 0,
217
- phone: void 0,
218
- readOnly: void 0,
219
- ref: (propertyName) => {
220
- if (!propertyName) {
221
- return void 0;
222
- }
223
- return factory.createTypeReferenceNode(propertyName, void 0);
224
- },
225
- blob: () => factory.createTypeReferenceNode("Blob", []),
226
- deprecated: void 0,
227
- example: void 0,
228
- schema: void 0,
229
- catchall: void 0,
230
- name: void 0
231
- };
232
- function parse(parent, current, options) {
233
- const value = typeKeywordMapper[current.keyword];
234
- if (!value) {
235
- return void 0;
236
- }
237
- if (isKeyword(current, schemaKeywords.union)) {
238
- return typeKeywordMapper.union(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
239
- }
240
- if (isKeyword(current, schemaKeywords.and)) {
241
- return typeKeywordMapper.and(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
242
- }
243
- if (isKeyword(current, schemaKeywords.array)) {
244
- return typeKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
245
- }
246
- if (isKeyword(current, schemaKeywords.enum)) {
247
- return typeKeywordMapper.enum(current.args.typeName);
248
- }
249
- if (isKeyword(current, schemaKeywords.ref)) {
250
- return typeKeywordMapper.ref(current.args.name);
251
- }
252
- if (isKeyword(current, schemaKeywords.blob)) {
253
- return value();
254
- }
255
- if (isKeyword(current, schemaKeywords.tuple)) {
256
- return typeKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
257
- }
258
- if (isKeyword(current, schemaKeywords.const)) {
259
- return typeKeywordMapper.const(current.args.name, current.args.format);
260
- }
261
- if (isKeyword(current, schemaKeywords.object)) {
262
- const properties = Object.entries(current.args?.properties || {}).filter((item) => {
263
- const schemas = item[1];
264
- return schemas && typeof schemas.map === "function";
265
- }).map(([name, schemas]) => {
266
- const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name);
267
- const mappedName = nameSchema?.args || name;
268
- if (options.mapper?.[mappedName]) {
269
- return options.mapper?.[mappedName];
270
- }
271
- const isNullish = schemas.some((schema) => schema.keyword === schemaKeywords.nullish);
272
- const isNullable = schemas.some((schema) => schema.keyword === schemaKeywords.nullable);
273
- const isOptional = schemas.some((schema) => schema.keyword === schemaKeywords.optional);
274
- const isReadonly = schemas.some((schema) => schema.keyword === schemaKeywords.readOnly);
275
- const describeSchema = schemas.find((schema) => schema.keyword === schemaKeywords.describe);
276
- const deprecatedSchema = schemas.find((schema) => schema.keyword === schemaKeywords.deprecated);
277
- const defaultSchema = schemas.find((schema) => schema.keyword === schemaKeywords.default);
278
- const exampleSchema = schemas.find((schema) => schema.keyword === schemaKeywords.example);
279
- const schemaSchema = schemas.find((schema) => schema.keyword === schemaKeywords.schema);
280
- let type = schemas.map((schema) => parse(current, schema, options)).filter(Boolean)[0];
281
- if (isNullable) {
282
- type = factory.createUnionDeclaration({
283
- nodes: [type, factory.keywordTypeNodes.null]
284
- });
285
- }
286
- if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
287
- type = factory.createUnionDeclaration({
288
- nodes: [type, factory.keywordTypeNodes.undefined]
289
- });
290
- }
291
- if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
292
- type = factory.createUnionDeclaration({
293
- nodes: [type, factory.keywordTypeNodes.undefined]
294
- });
295
- }
296
- const propertySignature = factory.createPropertySignature({
297
- questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
298
- name: mappedName,
299
- type,
300
- readOnly: isReadonly
301
- });
302
- return factory.appendJSDocToNode({
303
- node: propertySignature,
304
- comments: [
305
- describeSchema ? `@description ${transformers2.jsStringEscape(describeSchema.args)}` : void 0,
306
- deprecatedSchema ? "@deprecated" : void 0,
307
- defaultSchema ? `@default ${defaultSchema.args}` : void 0,
308
- exampleSchema ? `@example ${exampleSchema.args}` : void 0,
309
- schemaSchema?.args?.type || schemaSchema?.args?.format ? [`@type ${schemaSchema?.args?.type || "unknown"}${!isOptional ? "" : " | undefined"}`, schemaSchema?.args?.format].filter(Boolean).join(", ") : void 0
310
- ].filter(Boolean)
311
- });
312
- });
313
- const additionalProperties = current.args?.additionalProperties?.length ? factory.createIndexSignature(
314
- current.args.additionalProperties.map((schema) => parse(current, schema, options)).filter(Boolean).at(0)
315
- ) : void 0;
316
- return typeKeywordMapper.object([...properties, additionalProperties].filter(Boolean));
317
- }
318
- if (isKeyword(current, schemaKeywords.datetime)) {
319
- return typeKeywordMapper.datetime();
320
- }
321
- if (isKeyword(current, schemaKeywords.date)) {
322
- return typeKeywordMapper.date(current.args.type);
323
- }
324
- if (isKeyword(current, schemaKeywords.time)) {
325
- return typeKeywordMapper.time(current.args.type);
326
- }
327
- if (current.keyword in typeKeywordMapper) {
328
- return value();
329
- }
330
- return void 0;
331
- }
332
-
333
- // ../plugin-ts/src/components/Schema.tsx
334
- import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
335
- function Schema(props) {
336
- const { keysToOmit, description } = props;
337
- const { tree, name } = useSchema();
338
- const {
339
- pluginManager,
340
- plugin: {
341
- options: { mapper, enumType, optionalType }
342
- }
343
- } = useApp3();
344
- const resolvedName = pluginManager.resolveName({
345
- name,
346
- pluginKey: [pluginTsName],
347
- type: "function"
348
- });
349
- const typeName = pluginManager.resolveName({
350
- name,
351
- pluginKey: [pluginTsName],
352
- type: "type"
353
- });
354
- const nodes = [];
355
- const extraNodes = [];
356
- if (!tree.length) {
357
- return "";
358
- }
359
- const isNullish = tree.some((item) => item.keyword === schemaKeywords2.nullish);
360
- const isNullable = tree.some((item) => item.keyword === schemaKeywords2.nullable);
361
- const isOptional = tree.some((item) => item.keyword === schemaKeywords2.optional);
362
- let type = tree.map((schema) => parse(void 0, schema, { name: resolvedName, typeName, description, keysToOmit, optionalType, enumType, mapper })).filter(Boolean).at(0) || typeKeywordMapper.undefined();
363
- if (isNullable) {
364
- type = factory2.createUnionDeclaration({
365
- nodes: [type, factory2.keywordTypeNodes.null]
366
- });
367
- }
368
- if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
369
- type = factory2.createUnionDeclaration({
370
- nodes: [type, factory2.keywordTypeNodes.undefined]
371
- });
372
- }
373
- if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
374
- type = factory2.createUnionDeclaration({
375
- nodes: [type, factory2.keywordTypeNodes.undefined]
376
- });
377
- }
378
- const node = factory2.createTypeAliasDeclaration({
379
- modifiers: [factory2.modifiers.export],
380
- name: resolvedName,
381
- type: keysToOmit?.length ? factory2.createOmitDeclaration({
382
- keys: keysToOmit,
383
- type,
384
- nonNullable: true
385
- }) : type
386
- });
387
- const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords2.enum);
388
- if (enumSchemas) {
389
- enumSchemas.forEach((enumSchema) => {
390
- extraNodes.push(
391
- ...factory2.createEnumDeclaration({
392
- name: transformers3.camelCase(enumSchema.args.name),
393
- typeName: enumSchema.args.typeName,
394
- enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers3.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
395
- type: enumType
396
- })
397
- );
398
- });
399
- }
400
- nodes.push(
401
- factory2.appendJSDocToNode({
402
- node,
403
- comments: [description ? `@description ${transformers3.jsStringEscape(description)}` : void 0].filter(Boolean)
404
- })
405
- );
406
- const filterdNodes = nodes.filter(
407
- (node2) => !extraNodes.some(
408
- (extraNode) => extraNode?.name?.escapedText === node2?.name?.escapedText
409
- )
410
- );
411
- return print([...extraNodes, ...filterdNodes]);
412
- }
413
- Schema.File = function({}) {
414
- const { pluginManager } = useApp3();
415
- const { schema } = useSchema();
416
- return /* @__PURE__ */ jsx3(Oas.Schema.File, { output: pluginManager.config.output.path, children: /* @__PURE__ */ jsx3(File3.Source, { children: /* @__PURE__ */ jsx3(Schema, { description: schema?.description }) }) });
417
- };
418
-
419
- // ../plugin-ts/src/SchemaGenerator.tsx
420
- import { jsx as jsx4 } from "@kubb/react/jsx-runtime";
421
- var SchemaGenerator2 = class extends Generator {
422
- async schema(name, schema, options) {
423
- const { oas, pluginManager, plugin, mode, output } = this.context;
424
- const root = createRoot({
425
- logger: pluginManager.logger
426
- });
427
- const tree = this.parse({ schema, name });
428
- root.render(
429
- /* @__PURE__ */ jsx4(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx4(Oas2, { oas, children: /* @__PURE__ */ jsx4(Oas2.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx4(Schema.File, {}) }) }) })
430
- );
431
- return root.files;
432
- }
433
- };
434
-
435
- // ../plugin-ts/src/components/OperationSchema.tsx
436
- import { jsx as jsx5, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
437
- function printCombinedSchema({
438
- name,
439
- operation,
440
- schemas,
441
- pluginManager
442
- }) {
443
- const properties = {};
444
- if (schemas.response) {
445
- const identifier = pluginManager.resolveName({
446
- name: schemas.response.name,
447
- pluginKey: [pluginTsName],
448
- type: "function"
449
- });
450
- properties["response"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
451
- }
452
- if (schemas.request) {
453
- const identifier = pluginManager.resolveName({
454
- name: schemas.request.name,
455
- pluginKey: [pluginTsName],
456
- type: "function"
457
- });
458
- properties["request"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
459
- }
460
- if (schemas.pathParams) {
461
- const identifier = pluginManager.resolveName({
462
- name: schemas.pathParams.name,
463
- pluginKey: [pluginTsName],
464
- type: "function"
465
- });
466
- properties["pathParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
467
- }
468
- if (schemas.queryParams) {
469
- const identifier = pluginManager.resolveName({
470
- name: schemas.queryParams.name,
471
- pluginKey: [pluginTsName],
472
- type: "function"
473
- });
474
- properties["queryParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
475
- }
476
- if (schemas.headerParams) {
477
- const identifier = pluginManager.resolveName({
478
- name: schemas.headerParams.name,
479
- pluginKey: [pluginTsName],
480
- type: "function"
481
- });
482
- properties["headerParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
483
- }
484
- if (schemas.errors) {
485
- properties["errors"] = factory3.createUnionDeclaration({
486
- nodes: schemas.errors.map((error) => {
487
- const identifier = pluginManager.resolveName({
488
- name: error.name,
489
- pluginKey: [pluginTsName],
490
- type: "function"
491
- });
492
- return factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
493
- })
494
- });
495
- }
496
- const namespaceNode = factory3.createTypeAliasDeclaration({
497
- name: operation.method === "get" ? `${name}Query` : `${name}Mutation`,
498
- type: factory3.createTypeLiteralNode(
499
- Object.keys(properties).map((key) => {
500
- const type = properties[key];
501
- if (!type) {
502
- return void 0;
503
- }
504
- return factory3.createPropertySignature({
505
- name: transformers4.pascalCase(key),
506
- type
507
- });
508
- }).filter(Boolean)
509
- ),
510
- modifiers: [factory3.modifiers.export]
511
- });
512
- return print2(namespaceNode);
513
- }
514
- function OperationSchema({ keysToOmit, description }) {
515
- return /* @__PURE__ */ jsx5(Schema, { keysToOmit, description });
516
- }
517
- OperationSchema.File = function({}) {
518
- const { pluginManager, plugin, mode, fileManager } = useApp4();
519
- const oas = useOas2();
520
- const { getSchemas, getFile, getName } = useOperationManager2();
521
- const operation = useOperation();
522
- const file = getFile(operation);
523
- const schemas = getSchemas(operation);
524
- const factoryName = getName(operation, { type: "type" });
525
- const generator = new SchemaGenerator2(plugin.options, {
526
- oas,
527
- plugin,
528
- pluginManager,
529
- mode,
530
- override: plugin.options.override
531
- });
532
- const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
533
- const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
534
- const tree = generator.parse({ schema, name });
535
- return /* @__PURE__ */ jsxs3(Oas3.Schema, { name, value: schema, tree, children: [
536
- mode === "split" && /* @__PURE__ */ jsx5(Oas3.Schema.Imports, { extName: plugin.options.extName, isTypeOnly: true }),
537
- /* @__PURE__ */ jsx5(File4.Source, { children: /* @__PURE__ */ jsx5(OperationSchema, { description, keysToOmit }) })
538
- ] }, i);
539
- };
540
- return /* @__PURE__ */ jsx5(Parser3, { language: "typescript", children: /* @__PURE__ */ jsxs3(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
541
- items.map(mapItem),
542
- /* @__PURE__ */ jsx5(File4.Source, { children: printCombinedSchema({ name: factoryName, operation, schemas, pluginManager }) })
543
- ] }) });
544
- };
545
-
546
- // ../plugin-ts/src/OperationGenerator.tsx
547
- import { jsx as jsx6 } from "@kubb/react/jsx-runtime";
548
- var OperationGenerator = class extends Generator2 {
549
- async all(operations) {
550
- const { oas, pluginManager, plugin, mode } = this.context;
551
- const root = createRoot2({
552
- logger: pluginManager.logger
553
- });
554
- root.render(
555
- /* @__PURE__ */ jsx6(App2, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx6(Oas4, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsx6(OasType.File, { name: "oas", typeName: "Oas" }) }) })
556
- );
557
- return root.files;
558
- }
559
- async operation(operation, options) {
560
- const { oas, pluginManager, plugin, mode } = this.context;
561
- const root = createRoot2({
562
- logger: pluginManager.logger
563
- });
564
- root.render(
565
- /* @__PURE__ */ jsx6(App2, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx6(Oas4, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx6(Oas4.Operation, { operation, children: /* @__PURE__ */ jsx6(OperationSchema.File, {}) }) }) })
566
- );
567
- return root.files;
568
- }
569
- };
570
-
571
- // ../plugin-ts/src/plugin.ts
572
- var pluginTsName = "plugin-ts";
573
- var pluginTs = createPlugin((options) => {
574
- const {
575
- output = { path: "types" },
576
- group,
577
- exclude = [],
578
- include,
579
- override = [],
580
- enumType = "asConst",
581
- enumSuffix = "",
582
- dateType = "string",
583
- unknownType = "any",
584
- optionalType = "questionToken",
585
- transformers: transformers7 = {},
586
- oasType = false,
587
- mapper = {}
588
- } = options;
589
- const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
590
- return {
591
- name: pluginTsName,
592
- options: {
593
- extName: output.extName,
594
- transformers: transformers7,
595
- dateType,
596
- optionalType,
597
- oasType,
598
- enumType,
599
- enumSuffix,
600
- // keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)
601
- usedEnumNames: {},
602
- unknownType,
603
- override,
604
- mapper
605
- },
606
- pre: [pluginOasName],
607
- resolvePath(baseName, pathMode, options2) {
608
- const root = path.resolve(this.config.root, this.config.output.path);
609
- const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
610
- if (mode === "single") {
611
- return path.resolve(root, output.path);
612
- }
613
- if (options2?.tag && group?.type === "tag") {
614
- const tag = camelCase(options2.tag);
615
- return path.resolve(root, renderTemplate(template, { tag }), baseName);
616
- }
617
- return path.resolve(root, output.path, baseName);
618
- },
619
- resolveName(name, type) {
620
- const resolvedName = pascalCase(name, { isFile: type === "file" });
621
- if (type) {
622
- return transformers7?.name?.(resolvedName, type) || resolvedName;
623
- }
624
- return resolvedName;
625
- },
626
- async buildStart() {
627
- const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
628
- const oas = await swaggerPlugin.context.getOas();
629
- const root = path.resolve(this.config.root, this.config.output.path);
630
- const mode = FileManager.getMode(path.resolve(root, output.path));
631
- const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
632
- oas,
633
- pluginManager: this.pluginManager,
634
- plugin: this.plugin,
635
- contentType: swaggerPlugin.context.contentType,
636
- include: void 0,
637
- override,
638
- mode,
639
- output: output.path
640
- });
641
- const schemaFiles = await schemaGenerator.build();
642
- await this.addFile(...schemaFiles);
643
- const operationGenerator = new OperationGenerator(this.plugin.options, {
644
- oas,
645
- pluginManager: this.pluginManager,
646
- plugin: this.plugin,
647
- contentType: swaggerPlugin.context.contentType,
648
- exclude,
649
- include,
650
- override,
651
- mode
652
- });
653
- const operationFiles = await operationGenerator.build();
654
- await this.addFile(...operationFiles);
655
- },
656
- async buildEnd() {
657
- if (this.config.output.write === false) {
658
- return;
659
- }
660
- const root = path.resolve(this.config.root, this.config.output.path);
661
- const files = await this.fileManager.getIndexFiles({
662
- root,
663
- output,
664
- plugin: this.plugin,
665
- logger: this.logger
666
- });
667
- await this.fileManager.processFiles({
668
- logger: this.logger,
669
- files
670
- });
671
- }
672
- };
673
- });
674
-
675
- // src/components/Schema.tsx
676
- import transformers6 from "@kubb/core/transformers";
677
- import { isKeyword as isKeyword3, schemaKeywords as schemaKeywords5 } from "@kubb/plugin-oas";
678
- import { useSchema as useSchema2 } from "@kubb/plugin-oas/hooks";
679
-
680
- // src/parser/index.ts
681
- import transformers5 from "@kubb/core/transformers";
682
- import { isKeyword as isKeyword2, schemaKeywords as schemaKeywords3 } from "@kubb/plugin-oas";
683
- var zodKeywordMapper = {
684
- any: () => "z.any()",
685
- unknown: () => "z.unknown()",
686
- number: (coercion, min, max) => {
687
- return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
688
- },
689
- integer: (coercion, min, max) => {
690
- return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
691
- },
692
- object: (value) => `z.object({${value}})`,
693
- string: (coercion, min, max) => {
694
- return [coercion ? "z.coerce.string()" : "z.string()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
695
- },
696
- boolean: () => "z.boolean()",
697
- undefined: () => "z.undefined()",
698
- nullable: () => ".nullable()",
699
- null: () => "z.null()",
700
- nullish: () => ".nullish()",
701
- array: (items = [], min, max) => {
702
- return [`z.array(${items?.join("")})`, min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
703
- },
704
- tuple: (items = []) => `z.tuple([${items?.join(", ")}])`,
705
- enum: (items = []) => `z.enum([${items?.join(", ")}])`,
706
- union: (items = []) => `z.union([${items?.join(", ")}])`,
707
- const: (value) => `z.literal(${value ?? ""})`,
708
- /**
709
- * ISO 8601
710
- */
711
- datetime: (offset = false, local = false) => {
712
- if (offset) {
713
- return `z.string().datetime({ offset: ${offset} })`;
714
- }
715
- if (local) {
716
- return `z.string().datetime({ local: ${local} })`;
717
- }
718
- return "z.string().datetime()";
719
- },
720
- /**
721
- * Type `'date'` Date
722
- * Type `'string'` ISO date format (YYYY-MM-DD)
723
- * @default ISO date format (YYYY-MM-DD)
724
- */
725
- date: (type = "string", coercion) => {
726
- if (type === "string") {
727
- return "z.string().date()";
728
- }
729
- if (coercion) {
730
- return "z.coerce.date()";
731
- }
732
- return "z.date()";
733
- },
734
- /**
735
- * Type `'date'` Date
736
- * Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
737
- * @default ISO time format (HH:mm:ss[.SSSSSS])
738
- */
739
- time: (type = "string", coercion) => {
740
- if (type === "string") {
741
- return "z.string().time()";
742
- }
743
- if (coercion) {
744
- return "z.coerce.date()";
745
- }
746
- return "z.date()";
747
- },
748
- uuid: () => ".uuid()",
749
- url: () => ".url()",
750
- strict: () => ".strict()",
751
- default: (value) => `.default(${value ?? ""})`,
752
- and: (items = []) => items?.map((item) => `.and(${item})`).join(""),
753
- describe: (value = "") => `.describe(${value})`,
754
- min: (value) => `.min(${value ?? ""})`,
755
- max: (value) => `.max(${value ?? ""})`,
756
- optional: () => ".optional()",
757
- matches: (value = "") => `.regex(${value})`,
758
- email: () => ".email()",
759
- firstName: void 0,
760
- lastName: void 0,
761
- password: void 0,
762
- phone: void 0,
763
- readOnly: void 0,
764
- ref: (value) => value ? `z.lazy(() => ${value})` : void 0,
765
- blob: () => "z.string()",
766
- deprecated: void 0,
767
- example: void 0,
768
- schema: void 0,
769
- catchall: (value) => value ? `.catchall(${value})` : void 0,
770
- name: void 0
771
- };
772
- function sort(items) {
773
- const order = [
774
- schemaKeywords3.string,
775
- schemaKeywords3.datetime,
776
- schemaKeywords3.date,
777
- schemaKeywords3.time,
778
- schemaKeywords3.tuple,
779
- schemaKeywords3.number,
780
- schemaKeywords3.object,
781
- schemaKeywords3.enum,
782
- schemaKeywords3.url,
783
- schemaKeywords3.email,
784
- schemaKeywords3.firstName,
785
- schemaKeywords3.lastName,
786
- schemaKeywords3.password,
787
- schemaKeywords3.matches,
788
- schemaKeywords3.uuid,
789
- schemaKeywords3.min,
790
- schemaKeywords3.max,
791
- schemaKeywords3.default,
792
- schemaKeywords3.describe,
793
- schemaKeywords3.optional,
794
- schemaKeywords3.nullable,
795
- schemaKeywords3.nullish,
796
- schemaKeywords3.null
797
- ];
798
- if (!items) {
799
- return [];
800
- }
801
- return transformers5.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
802
- }
803
- function parse2(parent, current, options) {
804
- const value = zodKeywordMapper[current.keyword];
805
- if (!value) {
806
- return void 0;
807
- }
808
- if (isKeyword2(current, schemaKeywords3.union)) {
809
- if (Array.isArray(current.args) && current.args.length === 1) {
810
- return parse2(parent, current.args[0], options);
811
- }
812
- if (Array.isArray(current.args) && !current.args.length) {
813
- return "";
814
- }
815
- return zodKeywordMapper.union(
816
- sort(current.args).map((schema) => parse2(current, schema, options)).filter(Boolean)
817
- );
818
- }
819
- if (isKeyword2(current, schemaKeywords3.and)) {
820
- const items = sort(current.args).filter((schema) => {
821
- return ![schemaKeywords3.optional, schemaKeywords3.describe].includes(schema.keyword);
822
- }).map((schema) => parse2(current, schema, options)).filter(Boolean);
823
- return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
824
- }
825
- if (isKeyword2(current, schemaKeywords3.array)) {
826
- return zodKeywordMapper.array(
827
- sort(current.args.items).map((schemas) => parse2(current, schemas, options)).filter(Boolean),
828
- current.args.min,
829
- current.args.max
830
- );
831
- }
832
- if (isKeyword2(current, schemaKeywords3.enum)) {
833
- if (current.args.asConst) {
834
- return zodKeywordMapper.union(
835
- current.args.items.map((schema) => {
836
- return parse2(
837
- current,
838
- {
839
- keyword: schemaKeywords3.const,
840
- args: schema
841
- },
842
- options
843
- );
844
- }).filter(Boolean)
845
- );
846
- }
847
- return zodKeywordMapper.enum(
848
- current.args.items.map((schema) => {
849
- if (schema.format === "number") {
850
- return transformers5.stringify(schema.value);
851
- }
852
- return transformers5.stringify(schema.value);
853
- })
854
- );
855
- }
856
- if (isKeyword2(current, schemaKeywords3.ref)) {
857
- return zodKeywordMapper.ref(current.args?.name);
858
- }
859
- if (isKeyword2(current, schemaKeywords3.object)) {
860
- const properties = Object.entries(current.args?.properties || {}).filter((item) => {
861
- const schema = item[1];
862
- return schema && typeof schema.map === "function";
863
- }).map(([name, schemas]) => {
864
- const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords3.name);
865
- const mappedName = nameSchema?.args || name;
866
- if (options.mapper?.[mappedName]) {
867
- return `"${name}": ${options.mapper?.[mappedName]}`;
868
- }
869
- return `"${name}": ${sort(schemas).map((schema, array) => {
870
- return parse2(current, schema, options);
871
- }).filter(Boolean).join("")}`;
872
- }).join(",");
873
- const additionalProperties = current.args?.additionalProperties?.length ? current.args.additionalProperties.map((schema) => parse2(current, schema, options)).filter(Boolean).at(0) : void 0;
874
- const text = [
875
- zodKeywordMapper.object(properties),
876
- current.args?.strict ? zodKeywordMapper.strict() : void 0,
877
- additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0
878
- ].filter(Boolean);
879
- return text.join("");
880
- }
881
- if (isKeyword2(current, schemaKeywords3.tuple)) {
882
- return zodKeywordMapper.tuple(
883
- sort(current.args.items).map((schema) => parse2(current, schema, options)).filter(Boolean)
884
- );
885
- }
886
- if (isKeyword2(current, schemaKeywords3.const)) {
887
- if (current.args.format === "number" && current.args.value !== void 0) {
888
- return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
889
- }
890
- return zodKeywordMapper.const(transformers5.stringify(current.args.value));
891
- }
892
- if (isKeyword2(current, schemaKeywords3.matches)) {
893
- if (current.args) {
894
- return zodKeywordMapper.matches(transformers5.toRegExpString(current.args));
895
- }
896
- }
897
- if (isKeyword2(current, schemaKeywords3.default)) {
898
- if (current.args) {
899
- return zodKeywordMapper.default(current.args);
900
- }
901
- }
902
- if (isKeyword2(current, schemaKeywords3.describe)) {
903
- if (current.args) {
904
- return zodKeywordMapper.describe(transformers5.stringify(current.args.toString()));
905
- }
906
- }
907
- if (isKeyword2(current, schemaKeywords3.string)) {
908
- return zodKeywordMapper.string(options.coercion);
909
- }
910
- if (isKeyword2(current, schemaKeywords3.number) || isKeyword2(current, schemaKeywords3.integer)) {
911
- return zodKeywordMapper.number(options.coercion);
912
- }
913
- if (isKeyword2(current, schemaKeywords3.min)) {
914
- return zodKeywordMapper.min(current.args);
915
- }
916
- if (isKeyword2(current, schemaKeywords3.max)) {
917
- return zodKeywordMapper.max(current.args);
918
- }
919
- if (isKeyword2(current, schemaKeywords3.datetime)) {
920
- return zodKeywordMapper.datetime(current.args.offset, current.args.local);
921
- }
922
- if (isKeyword2(current, schemaKeywords3.date)) {
923
- return zodKeywordMapper.date(current.args.type, options.coercion);
924
- }
925
- if (isKeyword2(current, schemaKeywords3.time)) {
926
- return zodKeywordMapper.time(current.args.type, options.coercion);
927
- }
928
- if (current.keyword in zodKeywordMapper && "args" in current) {
929
- const value2 = zodKeywordMapper[current.keyword];
930
- return value2(current.args);
931
- }
932
- if (current.keyword in zodKeywordMapper) {
933
- return value();
934
- }
935
- return void 0;
936
- }
937
-
938
- // src/plugin.ts
939
- import path2 from "path";
940
- import { FileManager as FileManager2, PluginManager as PluginManager2, createPlugin as createPlugin2 } from "@kubb/core";
941
- import { camelCase as camelCase2, pascalCase as pascalCase2 } from "@kubb/core/transformers";
942
- import { renderTemplate as renderTemplate2 } from "@kubb/core/utils";
943
- import { OperationGenerator as OperationGenerator2, pluginOasName as pluginOasName2, SchemaGenerator as SchemaGenerator4 } from "@kubb/plugin-oas";
944
- import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
945
-
946
- // src/SchemaGenerator.tsx
947
- import { createReactParser } from "@kubb/plugin-oas";
948
-
949
- // src/components/OperationSchema.tsx
950
- import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
951
- import { Oas as Oas5 } from "@kubb/plugin-oas/components";
952
- import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager3 } from "@kubb/plugin-oas/hooks";
953
- import { File as File5, Parser as Parser4, useApp as useApp5 } from "@kubb/react";
954
- import { jsx as jsx7, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
955
- function OperationSchema2({ description, keysToOmit }) {
956
- return /* @__PURE__ */ jsx7(Schema2, { keysToOmit, withTypeAnnotation: false, description });
957
- }
958
- OperationSchema2.File = function({}) {
959
- const { pluginManager, plugin, mode } = useApp5();
960
- const { getSchemas, getFile } = useOperationManager3();
961
- const oas = useOas3();
962
- const operation = useOperation2();
963
- const file = getFile(operation);
964
- const schemas = getSchemas(operation);
965
- const generator = new SchemaGenerator3(plugin.options, {
966
- oas,
967
- plugin,
968
- pluginManager,
969
- mode,
970
- override: plugin.options.override
971
- });
972
- const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
973
- const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
974
- const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
975
- const optional = !required && !!name.includes("Params");
976
- const tree = generator.parse({ schema, name });
977
- return /* @__PURE__ */ jsxs4(Oas5.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
978
- mode === "split" && /* @__PURE__ */ jsx7(Oas5.Schema.Imports, { extName: plugin.options.extName }),
979
- /* @__PURE__ */ jsx7(File5.Source, { children: /* @__PURE__ */ jsx7(OperationSchema2, { description, keysToOmit }) })
980
- ] }, i);
981
- };
982
- return /* @__PURE__ */ jsx7(Parser4, { language: "typescript", children: /* @__PURE__ */ jsxs4(File5, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
983
- /* @__PURE__ */ jsx7(File5.Import, { name: ["z"], path: plugin.options.importPath }),
984
- items.map(mapItem)
985
- ] }) });
986
- };
987
-
988
- // src/SchemaGenerator.tsx
989
- import { jsx as jsx8 } from "@kubb/react/jsx-runtime";
990
- var zodParser = createReactParser({
991
- name: "plugin-zod",
992
- Operations({ options }) {
993
- if (!options.templates.operations) {
994
- return null;
995
- }
996
- return /* @__PURE__ */ jsx8(Operations.File, { templates: options.templates.operations });
997
- },
998
- Operation() {
999
- return /* @__PURE__ */ jsx8(OperationSchema2.File, {});
1000
- },
1001
- Schema({ schema, name }) {
1002
- return /* @__PURE__ */ jsx8(Schema2.File, {});
1003
- }
1004
- });
1005
-
1006
- // src/plugin.ts
1007
- var pluginZodName = "plugin-zod";
1008
- var pluginZod = createPlugin2((options) => {
1009
- const {
1010
- output = { path: "zod" },
1011
- group,
1012
- exclude = [],
1013
- include,
1014
- override = [],
1015
- transformers: transformers7 = {},
1016
- dateType = "string",
1017
- unknownType = "any",
1018
- typed = false,
1019
- typedSchema = false,
1020
- mapper = {},
1021
- templates,
1022
- importPath = "zod",
1023
- coercion = false
1024
- } = options;
1025
- const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
1026
- return {
1027
- name: pluginZodName,
1028
- options: {
1029
- extName: output.extName,
1030
- transformers: transformers7,
1031
- include,
1032
- exclude,
1033
- override,
1034
- typed,
1035
- typedSchema,
1036
- dateType,
1037
- unknownType,
1038
- mapper,
1039
- importPath,
1040
- coercion,
1041
- templates: {
1042
- operations: Operations.templates,
1043
- ...templates
1044
- }
1045
- },
1046
- pre: [pluginOasName2, typed ? pluginTsName : void 0].filter(Boolean),
1047
- resolvePath(baseName, pathMode, options2) {
1048
- const root = path2.resolve(this.config.root, this.config.output.path);
1049
- const mode = pathMode ?? FileManager2.getMode(path2.resolve(root, output.path));
1050
- if (mode === "single") {
1051
- return path2.resolve(root, output.path);
1052
- }
1053
- if (options2?.tag && group?.type === "tag") {
1054
- const tag = camelCase2(options2.tag);
1055
- return path2.resolve(root, renderTemplate2(template, { tag }), baseName);
1056
- }
1057
- return path2.resolve(root, output.path, baseName);
1058
- },
1059
- resolveName(name, type) {
1060
- let resolvedName = camelCase2(name, {
1061
- suffix: type ? "schema" : void 0,
1062
- isFile: type === "file"
1063
- });
1064
- if (type === "type") {
1065
- resolvedName = pascalCase2(resolvedName);
1066
- }
1067
- if (type) {
1068
- return transformers7?.name?.(resolvedName, type) || resolvedName;
1069
- }
1070
- return resolvedName;
1071
- },
1072
- async buildStart() {
1073
- const [swaggerPlugin] = PluginManager2.getDependedPlugins(this.plugins, [pluginOasName2]);
1074
- const oas = await swaggerPlugin.context.getOas();
1075
- const root = path2.resolve(this.config.root, this.config.output.path);
1076
- const mode = FileManager2.getMode(path2.resolve(root, output.path));
1077
- const schemaGenerator = new SchemaGenerator4(this.plugin.options, {
1078
- oas,
1079
- pluginManager: this.pluginManager,
1080
- plugin: this.plugin,
1081
- contentType: swaggerPlugin.context.contentType,
1082
- include: void 0,
1083
- override,
1084
- mode,
1085
- output: output.path
1086
- });
1087
- const schemaFiles = await schemaGenerator.build(zodParser);
1088
- await this.addFile(...schemaFiles);
1089
- const operationGenerator = new OperationGenerator2(this.plugin.options, {
1090
- oas,
1091
- pluginManager: this.pluginManager,
1092
- plugin: this.plugin,
1093
- contentType: swaggerPlugin.context.contentType,
1094
- exclude,
1095
- include,
1096
- override,
1097
- mode
1098
- });
1099
- const operationFiles = await operationGenerator.build(zodParser);
1100
- await this.addFile(...operationFiles);
1101
- if (this.config.output.write && group?.type === "tag") {
1102
- const rootFiles = await getGroupedByTagFiles({
1103
- logger: this.logger,
1104
- files: this.fileManager.files,
1105
- plugin: this.plugin,
1106
- template,
1107
- exportAs: group.exportAs || "{{tag}}Schemas",
1108
- root,
1109
- output
1110
- });
1111
- await this.addFile(...rootFiles);
1112
- }
1113
- },
1114
- async buildEnd() {
1115
- if (this.config.output.write === false) {
1116
- return;
1117
- }
1118
- const root = path2.resolve(this.config.root, this.config.output.path);
1119
- const files = await this.fileManager.getIndexFiles({
1120
- root,
1121
- output,
1122
- plugin: this.plugin,
1123
- logger: this.logger
1124
- });
1125
- await this.fileManager.processFiles({
1126
- logger: this.logger,
1127
- files
1128
- });
1129
- }
1130
- };
1131
- });
1132
-
1133
- // src/components/Schema.tsx
1134
- import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
1135
- function Schema2(props) {
1136
- const { keysToOmit, withTypeAnnotation, description } = props;
1137
- const { tree, name } = useSchema2();
1138
- const {
1139
- pluginManager,
1140
- plugin: {
1141
- options: { mapper, typedSchema, coercion }
1142
- }
1143
- } = useApp6();
1144
- const resolvedName = pluginManager.resolveName({
1145
- name,
1146
- pluginKey: [pluginZodName],
1147
- type: "function"
1148
- });
1149
- const resolvedTypeName = pluginManager.resolveName({
1150
- name,
1151
- pluginKey: [pluginZodName],
1152
- type: "type"
1153
- });
1154
- const typeName = pluginManager.resolveName({
1155
- name,
1156
- pluginKey: [pluginTsName],
1157
- type: "type"
1158
- });
1159
- if (!tree.length) {
1160
- return /* @__PURE__ */ jsx9(
1161
- Const2,
1162
- {
1163
- name: resolvedName,
1164
- export: true,
1165
- JSDoc: {
1166
- comments: [description ? `@description ${transformers6.jsStringEscape(description)}` : void 0].filter(Boolean)
1167
- },
1168
- children: "undefined"
1169
- }
1170
- );
1171
- }
1172
- const hasTuple = tree.some((item) => isKeyword3(item, schemaKeywords5.tuple));
1173
- const output = sort(tree).filter((item) => {
1174
- if (hasTuple && (isKeyword3(item, schemaKeywords5.min) || isKeyword3(item, schemaKeywords5.max))) {
1175
- return false;
1176
- }
1177
- return true;
1178
- }).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
1179
- const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
1180
- return /* @__PURE__ */ jsxs5(Fragment3, { children: [
1181
- /* @__PURE__ */ jsx9(
1182
- Const2,
1183
- {
1184
- export: true,
1185
- name: resolvedName,
1186
- JSDoc: {
1187
- comments: [description ? `@description ${transformers6.jsStringEscape(description)}` : void 0].filter(Boolean)
1188
- },
1189
- children: [
1190
- output,
1191
- keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(",")} }))` : void 0,
1192
- withTypeAnnotation && typeName ? ` as z.ZodType<${typeName}>` : ""
1193
- ].filter(Boolean).join("") || ""
1194
- }
1195
- ),
1196
- typedSchema && /* @__PURE__ */ jsx9(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` })
1197
- ] });
1198
- }
1199
- Schema2.File = function({}) {
1200
- const {
1201
- pluginManager,
1202
- plugin: {
1203
- options: { typed }
1204
- }
1205
- } = useApp6();
1206
- const { schema } = useSchema2();
1207
- const withTypeAnnotation = !!typed;
1208
- return /* @__PURE__ */ jsxs5(Oas6.Schema.File, { output: pluginManager.config.output.path, children: [
1209
- /* @__PURE__ */ jsx9(Schema2.Imports, {}),
1210
- /* @__PURE__ */ jsx9(File6.Source, { children: /* @__PURE__ */ jsx9(Schema2, { withTypeAnnotation, description: schema?.description }) })
1211
- ] });
1212
- };
1213
- Schema2.Imports = () => {
1214
- const {
1215
- pluginManager,
1216
- plugin: {
1217
- options: { typed, importPath }
1218
- }
1219
- } = useApp6();
1220
- const { path: root } = useFile();
1221
- const { name, tree, schema } = useSchema2();
1222
- const typeName = pluginManager.resolveName({
1223
- name,
1224
- pluginKey: [pluginTsName],
1225
- type: "type"
1226
- });
1227
- const typeFileName = pluginManager.resolveName({
1228
- name,
1229
- pluginKey: [pluginTsName],
1230
- type: "file"
1231
- });
1232
- const typePath = pluginManager.resolvePath({
1233
- baseName: typeFileName,
1234
- pluginKey: [pluginTsName]
1235
- });
1236
- const withTypeAnnotation = !!typed;
1237
- return /* @__PURE__ */ jsxs5(Fragment3, { children: [
1238
- /* @__PURE__ */ jsx9(File6.Import, { name: ["z"], path: importPath }),
1239
- withTypeAnnotation && typeName && typePath && /* @__PURE__ */ jsx9(File6.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
1240
- ] });
1241
- };
1242
-
1243
- export {
1244
- Operations,
1245
- Schema2 as Schema,
1246
- OperationSchema2 as OperationSchema,
1247
- pluginZodName,
1248
- pluginZod
1249
- };
1250
- //# sourceMappingURL=chunk-MGSFBU7O.js.map