@kubb/plugin-zod 3.0.0-alpha.2 → 3.0.0-alpha.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.
@@ -1,5 +1,71 @@
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
+
1
67
  // src/components/Schema.tsx
2
- import { Oas as Oas8 } from "@kubb/plugin-oas/components";
68
+ import { Oas as Oas6 } from "@kubb/plugin-oas/components";
3
69
  import { Const as Const2, File as File6, Type as Type2, useApp as useApp6, useFile } from "@kubb/react";
4
70
 
5
71
  // ../plugin-ts/src/plugin.ts
@@ -15,42 +81,42 @@ import { Oas as Oas4 } from "@kubb/plugin-oas/components";
15
81
  import { App as App2, createRoot as createRoot2 } from "@kubb/react";
16
82
 
17
83
  // ../plugin-ts/src/components/OasType.tsx
18
- import { Parser, File, Type, useApp } from "@kubb/react";
84
+ import { Parser as Parser2, File as File2, Type, useApp as useApp2 } from "@kubb/react";
19
85
  import { useOas } from "@kubb/plugin-oas/hooks";
20
- import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
21
- function Template({ name, typeName, api }) {
22
- return /* @__PURE__ */ jsxs(Fragment, { children: [
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: [
23
89
  `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
24
- /* @__PURE__ */ jsx("br", {}),
25
- /* @__PURE__ */ jsx(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` })
90
+ /* @__PURE__ */ jsx2("br", {}),
91
+ /* @__PURE__ */ jsx2(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` })
26
92
  ] });
27
93
  }
28
- var defaultTemplates = { default: Template };
29
- function OasType({ name, typeName, Template: Template3 = defaultTemplates.default }) {
94
+ var defaultTemplates2 = { default: Template2 };
95
+ function OasType({ name, typeName, Template: Template3 = defaultTemplates2.default }) {
30
96
  const oas = useOas();
31
- return /* @__PURE__ */ jsx(Template3, { name, typeName, api: oas.api });
97
+ return /* @__PURE__ */ jsx2(Template3, { name, typeName, api: oas.api });
32
98
  }
33
- OasType.File = function({ name, typeName, templates = defaultTemplates }) {
99
+ OasType.File = function({ name, typeName, templates = defaultTemplates2 }) {
34
100
  const {
35
101
  pluginManager,
36
102
  plugin: { key: pluginKey }
37
- } = useApp();
103
+ } = useApp2();
38
104
  const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
39
105
  const Template3 = templates.default;
40
- return /* @__PURE__ */ jsx(Parser, { language: "typescript", children: /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
41
- /* @__PURE__ */ jsx(File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
42
- /* @__PURE__ */ jsx(File.Source, { children: /* @__PURE__ */ jsx(OasType, { Template: Template3, name, typeName }) })
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 }) })
43
109
  ] }) });
44
110
  };
45
- OasType.templates = defaultTemplates;
111
+ OasType.templates = defaultTemplates2;
46
112
 
47
113
  // ../plugin-ts/src/components/OperationSchema.tsx
48
- import transformers3 from "@kubb/core/transformers";
114
+ import transformers4 from "@kubb/core/transformers";
49
115
  import { print as print2 } from "@kubb/parser-ts";
50
116
  import * as factory3 from "@kubb/parser-ts/factory";
51
117
  import { Oas as Oas3 } from "@kubb/plugin-oas/components";
52
- import { useOas as useOas2, useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
53
- import { File as File3, Parser as Parser2, useApp as useApp3 } from "@kubb/react";
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";
54
120
 
55
121
  // ../plugin-ts/src/SchemaGenerator.tsx
56
122
  import { SchemaGenerator as Generator } from "@kubb/plugin-oas";
@@ -59,15 +125,15 @@ import { App, createRoot } from "@kubb/react";
59
125
 
60
126
  // ../plugin-ts/src/components/Schema.tsx
61
127
  import { Oas } from "@kubb/plugin-oas/components";
62
- import { File as File2, useApp as useApp2 } from "@kubb/react";
63
- import transformers2 from "@kubb/core/transformers";
128
+ import { File as File3, useApp as useApp3 } from "@kubb/react";
129
+ import transformers3 from "@kubb/core/transformers";
64
130
  import { print } from "@kubb/parser-ts";
65
131
  import * as factory2 from "@kubb/parser-ts/factory";
66
132
  import { SchemaGenerator, schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
67
133
  import { useSchema } from "@kubb/plugin-oas/hooks";
68
134
 
69
135
  // ../plugin-ts/src/parser/index.ts
70
- import transformers from "@kubb/core/transformers";
136
+ import transformers2 from "@kubb/core/transformers";
71
137
  import * as factory from "@kubb/parser-ts/factory";
72
138
  import { isKeyword, schemaKeywords } from "@kubb/plugin-oas";
73
139
  var typeKeywordMapper = {
@@ -236,7 +302,7 @@ function parse(parent, current, options) {
236
302
  return factory.appendJSDocToNode({
237
303
  node: propertySignature,
238
304
  comments: [
239
- describeSchema ? `@description ${transformers.jsStringEscape(describeSchema.args)}` : void 0,
305
+ describeSchema ? `@description ${transformers2.jsStringEscape(describeSchema.args)}` : void 0,
240
306
  deprecatedSchema ? "@deprecated" : void 0,
241
307
  defaultSchema ? `@default ${defaultSchema.args}` : void 0,
242
308
  exampleSchema ? `@example ${exampleSchema.args}` : void 0,
@@ -265,7 +331,7 @@ function parse(parent, current, options) {
265
331
  }
266
332
 
267
333
  // ../plugin-ts/src/components/Schema.tsx
268
- import { jsx as jsx2 } from "@kubb/react/jsx-runtime";
334
+ import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
269
335
  function Schema(props) {
270
336
  const { keysToOmit, description } = props;
271
337
  const { tree, name } = useSchema();
@@ -274,7 +340,7 @@ function Schema(props) {
274
340
  plugin: {
275
341
  options: { mapper, enumType, optionalType }
276
342
  }
277
- } = useApp2();
343
+ } = useApp3();
278
344
  const resolvedName = pluginManager.resolveName({
279
345
  name,
280
346
  pluginKey: [pluginTsName],
@@ -323,9 +389,9 @@ function Schema(props) {
323
389
  enumSchemas.forEach((enumSchema) => {
324
390
  extraNodes.push(
325
391
  ...factory2.createEnumDeclaration({
326
- name: transformers2.camelCase(enumSchema.args.name),
392
+ name: transformers3.camelCase(enumSchema.args.name),
327
393
  typeName: enumSchema.args.typeName,
328
- enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers2.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
394
+ enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers3.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
329
395
  type: enumType
330
396
  })
331
397
  );
@@ -334,7 +400,7 @@ function Schema(props) {
334
400
  nodes.push(
335
401
  factory2.appendJSDocToNode({
336
402
  node,
337
- comments: [description ? `@description ${transformers2.jsStringEscape(description)}` : void 0].filter(Boolean)
403
+ comments: [description ? `@description ${transformers3.jsStringEscape(description)}` : void 0].filter(Boolean)
338
404
  })
339
405
  );
340
406
  const filterdNodes = nodes.filter(
@@ -345,13 +411,13 @@ function Schema(props) {
345
411
  return print([...extraNodes, ...filterdNodes]);
346
412
  }
347
413
  Schema.File = function({}) {
348
- const { pluginManager } = useApp2();
414
+ const { pluginManager } = useApp3();
349
415
  const { schema } = useSchema();
350
- return /* @__PURE__ */ jsx2(Oas.Schema.File, { output: pluginManager.config.output.path, children: /* @__PURE__ */ jsx2(File2.Source, { children: /* @__PURE__ */ jsx2(Schema, { description: schema?.description }) }) });
416
+ return /* @__PURE__ */ jsx3(Oas.Schema.File, { output: pluginManager.config.output.path, children: /* @__PURE__ */ jsx3(File3.Source, { children: /* @__PURE__ */ jsx3(Schema, { description: schema?.description }) }) });
351
417
  };
352
418
 
353
419
  // ../plugin-ts/src/SchemaGenerator.tsx
354
- import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
420
+ import { jsx as jsx4 } from "@kubb/react/jsx-runtime";
355
421
  var SchemaGenerator2 = class extends Generator {
356
422
  async schema(name, schema, options) {
357
423
  const { oas, pluginManager, plugin, mode, output } = this.context;
@@ -360,14 +426,14 @@ var SchemaGenerator2 = class extends Generator {
360
426
  });
361
427
  const tree = this.parse({ schema, name });
362
428
  root.render(
363
- /* @__PURE__ */ jsx3(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx3(Oas2, { oas, children: /* @__PURE__ */ jsx3(Oas2.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx3(Schema.File, {}) }) }) })
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, {}) }) }) })
364
430
  );
365
431
  return root.files;
366
432
  }
367
433
  };
368
434
 
369
435
  // ../plugin-ts/src/components/OperationSchema.tsx
370
- import { jsx as jsx4, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
436
+ import { jsx as jsx5, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
371
437
  function printCombinedSchema({
372
438
  name,
373
439
  operation,
@@ -436,7 +502,7 @@ function printCombinedSchema({
436
502
  return void 0;
437
503
  }
438
504
  return factory3.createPropertySignature({
439
- name: transformers3.pascalCase(key),
505
+ name: transformers4.pascalCase(key),
440
506
  type
441
507
  });
442
508
  }).filter(Boolean)
@@ -446,12 +512,12 @@ function printCombinedSchema({
446
512
  return print2(namespaceNode);
447
513
  }
448
514
  function OperationSchema({ keysToOmit, description }) {
449
- return /* @__PURE__ */ jsx4(Schema, { keysToOmit, description });
515
+ return /* @__PURE__ */ jsx5(Schema, { keysToOmit, description });
450
516
  }
451
517
  OperationSchema.File = function({}) {
452
- const { pluginManager, plugin, mode, fileManager } = useApp3();
518
+ const { pluginManager, plugin, mode, fileManager } = useApp4();
453
519
  const oas = useOas2();
454
- const { getSchemas, getFile, getName } = useOperationManager();
520
+ const { getSchemas, getFile, getName } = useOperationManager2();
455
521
  const operation = useOperation();
456
522
  const file = getFile(operation);
457
523
  const schemas = getSchemas(operation);
@@ -466,19 +532,19 @@ OperationSchema.File = function({}) {
466
532
  const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
467
533
  const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
468
534
  const tree = generator.parse({ schema, name });
469
- return /* @__PURE__ */ jsxs2(Oas3.Schema, { name, value: schema, tree, children: [
470
- mode === "split" && /* @__PURE__ */ jsx4(Oas3.Schema.Imports, { extName: plugin.options.extName, isTypeOnly: true }),
471
- /* @__PURE__ */ jsx4(File3.Source, { children: /* @__PURE__ */ jsx4(OperationSchema, { description, keysToOmit }) })
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 }) })
472
538
  ] }, i);
473
539
  };
474
- return /* @__PURE__ */ jsx4(Parser2, { language: "typescript", children: /* @__PURE__ */ jsxs2(File3, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
540
+ return /* @__PURE__ */ jsx5(Parser3, { language: "typescript", children: /* @__PURE__ */ jsxs3(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
475
541
  items.map(mapItem),
476
- /* @__PURE__ */ jsx4(File3.Source, { children: printCombinedSchema({ name: factoryName, operation, schemas, pluginManager }) })
542
+ /* @__PURE__ */ jsx5(File4.Source, { children: printCombinedSchema({ name: factoryName, operation, schemas, pluginManager }) })
477
543
  ] }) });
478
544
  };
479
545
 
480
546
  // ../plugin-ts/src/OperationGenerator.tsx
481
- import { jsx as jsx5 } from "@kubb/react/jsx-runtime";
547
+ import { jsx as jsx6 } from "@kubb/react/jsx-runtime";
482
548
  var OperationGenerator = class extends Generator2 {
483
549
  async all(operations) {
484
550
  const { oas, pluginManager, plugin, mode } = this.context;
@@ -486,7 +552,7 @@ var OperationGenerator = class extends Generator2 {
486
552
  logger: pluginManager.logger
487
553
  });
488
554
  root.render(
489
- /* @__PURE__ */ jsx5(App2, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx5(Oas4, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsx5(OasType.File, { name: "oas", typeName: "Oas" }) }) })
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" }) }) })
490
556
  );
491
557
  return root.files;
492
558
  }
@@ -496,7 +562,7 @@ var OperationGenerator = class extends Generator2 {
496
562
  logger: pluginManager.logger
497
563
  });
498
564
  root.render(
499
- /* @__PURE__ */ jsx5(App2, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx5(Oas4, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx5(Oas4.Operation, { operation, children: /* @__PURE__ */ jsx5(OperationSchema.File, {}) }) }) })
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, {}) }) }) })
500
566
  );
501
567
  return root.files;
502
568
  }
@@ -592,12 +658,16 @@ var pluginTs = createPlugin((options) => {
592
658
  return;
593
659
  }
594
660
  const root = path.resolve(this.config.root, this.config.output.path);
595
- await this.fileManager.addIndexes({
661
+ const files = await this.fileManager.getIndexFiles({
596
662
  root,
597
663
  output,
598
664
  meta: { pluginKey: this.plugin.key },
599
665
  logger: this.logger
600
666
  });
667
+ await this.fileManager.processFiles({
668
+ logger: this.logger,
669
+ files
670
+ });
601
671
  }
602
672
  };
603
673
  });
@@ -608,7 +678,7 @@ import { isKeyword as isKeyword3, schemaKeywords as schemaKeywords5 } from "@kub
608
678
  import { useSchema as useSchema2 } from "@kubb/plugin-oas/hooks";
609
679
 
610
680
  // src/parser/index.ts
611
- import transformers4 from "@kubb/core/transformers";
681
+ import transformers5 from "@kubb/core/transformers";
612
682
  import { isKeyword as isKeyword2, schemaKeywords as schemaKeywords3 } from "@kubb/plugin-oas";
613
683
  var zodKeywordMapper = {
614
684
  any: () => "z.any()",
@@ -728,7 +798,7 @@ function sort(items) {
728
798
  if (!items) {
729
799
  return [];
730
800
  }
731
- return transformers4.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
801
+ return transformers5.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
732
802
  }
733
803
  function parse2(parent, current, options) {
734
804
  const value = zodKeywordMapper[current.keyword];
@@ -777,9 +847,9 @@ function parse2(parent, current, options) {
777
847
  return zodKeywordMapper.enum(
778
848
  current.args.items.map((schema) => {
779
849
  if (schema.format === "number") {
780
- return transformers4.stringify(schema.value);
850
+ return transformers5.stringify(schema.value);
781
851
  }
782
- return transformers4.stringify(schema.value);
852
+ return transformers5.stringify(schema.value);
783
853
  })
784
854
  );
785
855
  }
@@ -817,11 +887,11 @@ function parse2(parent, current, options) {
817
887
  if (current.args.format === "number" && current.args.value !== void 0) {
818
888
  return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
819
889
  }
820
- return zodKeywordMapper.const(transformers4.stringify(current.args.value));
890
+ return zodKeywordMapper.const(transformers5.stringify(current.args.value));
821
891
  }
822
892
  if (isKeyword2(current, schemaKeywords3.matches)) {
823
893
  if (current.args) {
824
- return zodKeywordMapper.matches(transformers4.toRegExpString(current.args));
894
+ return zodKeywordMapper.matches(transformers5.toRegExpString(current.args));
825
895
  }
826
896
  }
827
897
  if (isKeyword2(current, schemaKeywords3.default)) {
@@ -831,7 +901,7 @@ function parse2(parent, current, options) {
831
901
  }
832
902
  if (isKeyword2(current, schemaKeywords3.describe)) {
833
903
  if (current.args) {
834
- return zodKeywordMapper.describe(transformers4.stringify(current.args.toString()));
904
+ return zodKeywordMapper.describe(transformers5.stringify(current.args.toString()));
835
905
  }
836
906
  }
837
907
  if (isKeyword2(current, schemaKeywords3.string)) {
@@ -870,47 +940,24 @@ import path2 from "path";
870
940
  import { FileManager as FileManager2, PluginManager as PluginManager2, createPlugin as createPlugin2 } from "@kubb/core";
871
941
  import { camelCase as camelCase2, pascalCase as pascalCase2 } from "@kubb/core/transformers";
872
942
  import { renderTemplate as renderTemplate2 } from "@kubb/core/utils";
873
- import { pluginOasName as pluginOasName2 } from "@kubb/plugin-oas";
943
+ import { OperationGenerator as OperationGenerator2, pluginOasName as pluginOasName2, SchemaGenerator as SchemaGenerator4 } from "@kubb/plugin-oas";
874
944
  import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
875
945
 
876
- // src/OperationGenerator.tsx
877
- import { OperationGenerator as Generator4 } from "@kubb/plugin-oas";
878
- import { Oas as Oas7 } from "@kubb/plugin-oas/components";
879
- import { App as App4, createRoot as createRoot4 } from "@kubb/react";
880
-
881
- // src/components/OperationSchema.tsx
882
- import { schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
883
- import { Oas as Oas6 } from "@kubb/plugin-oas/components";
884
- import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager2 } from "@kubb/plugin-oas/hooks";
885
- import { File as File4, Parser as Parser3, useApp as useApp4 } from "@kubb/react";
886
-
887
946
  // src/SchemaGenerator.tsx
888
- import { SchemaGenerator as Generator3 } from "@kubb/plugin-oas";
889
- import { Oas as Oas5 } from "@kubb/plugin-oas/components";
890
- import { App as App3, createRoot as createRoot3 } from "@kubb/react";
891
- import { jsx as jsx6 } from "@kubb/react/jsx-runtime";
892
- var SchemaGenerator3 = class extends Generator3 {
893
- async schema(name, schema, options) {
894
- const { oas, pluginManager, plugin, mode, output } = this.context;
895
- const root = createRoot3({
896
- logger: pluginManager.logger
897
- });
898
- const tree = this.parse({ schema, name });
899
- root.render(
900
- /* @__PURE__ */ jsx6(App3, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx6(Oas5, { oas, children: /* @__PURE__ */ jsx6(Oas5.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx6(Schema2.File, {}) }) }) })
901
- );
902
- return root.files;
903
- }
904
- };
947
+ import { createReactParser } from "@kubb/plugin-oas";
905
948
 
906
949
  // src/components/OperationSchema.tsx
907
- import { jsx as jsx7, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
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";
908
955
  function OperationSchema2({ description, keysToOmit }) {
909
956
  return /* @__PURE__ */ jsx7(Schema2, { keysToOmit, withTypeAnnotation: false, description });
910
957
  }
911
958
  OperationSchema2.File = function({}) {
912
- const { pluginManager, plugin, mode } = useApp4();
913
- const { getSchemas, getFile } = useOperationManager2();
959
+ const { pluginManager, plugin, mode } = useApp5();
960
+ const { getSchemas, getFile } = useOperationManager3();
914
961
  const oas = useOas3();
915
962
  const operation = useOperation2();
916
963
  const file = getFile(operation);
@@ -927,111 +974,34 @@ OperationSchema2.File = function({}) {
927
974
  const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
928
975
  const optional = !required && !!name.includes("Params");
929
976
  const tree = generator.parse({ schema, name });
930
- return /* @__PURE__ */ jsxs3(Oas6.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
931
- mode === "split" && /* @__PURE__ */ jsx7(Oas6.Schema.Imports, { extName: plugin.options.extName }),
932
- /* @__PURE__ */ jsx7(File4.Source, { children: /* @__PURE__ */ jsx7(OperationSchema2, { description, keysToOmit }) })
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 }) })
933
980
  ] }, i);
934
981
  };
935
- return /* @__PURE__ */ jsx7(Parser3, { language: "typescript", children: /* @__PURE__ */ jsxs3(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
936
- /* @__PURE__ */ jsx7(File4.Import, { name: ["z"], path: plugin.options.importPath }),
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 }),
937
984
  items.map(mapItem)
938
985
  ] }) });
939
986
  };
940
987
 
941
- // src/components/Operations.tsx
942
- import { useOperationManager as useOperationManager3, useOperations } from "@kubb/plugin-oas/hooks";
943
- import { Const, File as File5, Parser as Parser4, useApp as useApp5 } from "@kubb/react";
944
- import transformers5 from "@kubb/core/transformers";
945
- import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
946
- function Template2({ operationsName, pathsName, operations }) {
947
- const { groupSchemasByName } = useOperationManager3();
948
- const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
949
- const operationsJSON = transformedOperations.reduce(
950
- (prev, acc) => {
951
- prev[`"${acc.operation.getOperationId()}"`] = acc.data;
952
- return prev;
953
- },
954
- {}
955
- );
956
- const pathsJSON = transformedOperations.reduce(
957
- (prev, acc) => {
958
- prev[`"${acc.operation.path}"`] = {
959
- ...prev[`"${acc.operation.path}"`] || {},
960
- [acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
961
- };
962
- return prev;
963
- },
964
- {}
965
- );
966
- return /* @__PURE__ */ jsxs4(Fragment2, { children: [
967
- /* @__PURE__ */ jsx8(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers5.stringifyObject(operationsJSON)}}` }),
968
- /* @__PURE__ */ jsx8(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers5.stringifyObject(pathsJSON)}}` })
969
- ] });
970
- }
971
- function RootTemplate({ children }) {
972
- const {
973
- mode,
974
- pluginManager,
975
- plugin: {
976
- key: pluginKey,
977
- options: { extName }
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;
978
995
  }
979
- } = useApp5();
980
- const { getFile } = useOperationManager3();
981
- const operations = useOperations();
982
- const { groupSchemasByName } = useOperationManager3();
983
- const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
984
- const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
985
- const imports = Object.entries(transformedOperations).map(([_key, { data, operation }], index) => {
986
- const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
987
- return /* @__PURE__ */ jsx8(File5.Import, { extName, name: names, root: file.path, path: getFile(operation).path }, index);
988
- }).filter(Boolean);
989
- return /* @__PURE__ */ jsx8(Parser4, { language: "typescript", children: /* @__PURE__ */ jsxs4(File5, { baseName: file.baseName, path: file.path, meta: file.meta, exportable: false, children: [
990
- mode === "split" && imports,
991
- /* @__PURE__ */ jsx8(File5.Source, { children })
992
- ] }) });
993
- }
994
- var defaultTemplates2 = { default: Template2, root: RootTemplate };
995
- function Operations({ Template: Template3 = defaultTemplates2.default }) {
996
- const operations = useOperations();
997
- return /* @__PURE__ */ jsx8(Template3, { operationsName: "operations", pathsName: "paths", operations });
998
- }
999
- Operations.File = function(props) {
1000
- const templates = { ...defaultTemplates2, ...props.templates };
1001
- const Template3 = templates.default;
1002
- const RootTemplate2 = templates.root;
1003
- return /* @__PURE__ */ jsx8(RootTemplate2, { children: /* @__PURE__ */ jsx8(Operations, { Template: Template3 }) });
1004
- };
1005
- Operations.templates = defaultTemplates2;
1006
-
1007
- // src/OperationGenerator.tsx
1008
- import { jsx as jsx9 } from "@kubb/react/jsx-runtime";
1009
- var OperationGenerator2 = class extends Generator4 {
1010
- async all(operations, _operationsByMethod) {
1011
- const { pluginManager, oas, plugin, mode } = this.context;
1012
- const root = createRoot4({
1013
- logger: pluginManager.logger
1014
- });
1015
- const templates = {
1016
- operations: Operations.templates,
1017
- ...this.options.templates
1018
- };
1019
- root.render(
1020
- /* @__PURE__ */ jsx9(App4, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx9(Oas7, { oas, operations, generator: this, children: templates.operations && /* @__PURE__ */ jsx9(Operations.File, { templates: templates.operations }) }) })
1021
- );
1022
- return root.files;
1023
- }
1024
- async operation(operation, options) {
1025
- const { oas, pluginManager, plugin, mode } = this.context;
1026
- const root = createRoot4({
1027
- logger: pluginManager.logger
1028
- });
1029
- root.render(
1030
- /* @__PURE__ */ jsx9(App4, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx9(Oas7, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx9(Oas7.Operation, { operation, children: /* @__PURE__ */ jsx9(OperationSchema2.File, {}) }) }) })
1031
- );
1032
- return root.files;
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, {});
1033
1003
  }
1034
- };
1004
+ });
1035
1005
 
1036
1006
  // src/plugin.ts
1037
1007
  var pluginZodName = "plugin-zod";
@@ -1104,7 +1074,7 @@ var pluginZod = createPlugin2((options) => {
1104
1074
  const oas = await swaggerPlugin.context.getOas();
1105
1075
  const root = path2.resolve(this.config.root, this.config.output.path);
1106
1076
  const mode = FileManager2.getMode(path2.resolve(root, output.path));
1107
- const schemaGenerator = new SchemaGenerator3(this.plugin.options, {
1077
+ const schemaGenerator = new SchemaGenerator4(this.plugin.options, {
1108
1078
  oas,
1109
1079
  pluginManager: this.pluginManager,
1110
1080
  plugin: this.plugin,
@@ -1114,7 +1084,7 @@ var pluginZod = createPlugin2((options) => {
1114
1084
  mode,
1115
1085
  output: output.path
1116
1086
  });
1117
- const schemaFiles = await schemaGenerator.build();
1087
+ const schemaFiles = await schemaGenerator.build(zodParser);
1118
1088
  await this.addFile(...schemaFiles);
1119
1089
  const operationGenerator = new OperationGenerator2(this.plugin.options, {
1120
1090
  oas,
@@ -1126,15 +1096,9 @@ var pluginZod = createPlugin2((options) => {
1126
1096
  override,
1127
1097
  mode
1128
1098
  });
1129
- const operationFiles = await operationGenerator.build();
1099
+ const operationFiles = await operationGenerator.build(zodParser);
1130
1100
  await this.addFile(...operationFiles);
1131
- },
1132
- async buildEnd() {
1133
- if (this.config.output.write === false) {
1134
- return;
1135
- }
1136
- const root = path2.resolve(this.config.root, this.config.output.path);
1137
- if (group?.type === "tag") {
1101
+ if (this.config.output.write && group?.type === "tag") {
1138
1102
  const rootFiles = await getGroupedByTagFiles({
1139
1103
  logger: this.logger,
1140
1104
  files: this.fileManager.files,
@@ -1146,18 +1110,28 @@ var pluginZod = createPlugin2((options) => {
1146
1110
  });
1147
1111
  await this.addFile(...rootFiles);
1148
1112
  }
1149
- await this.fileManager.addIndexes({
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({
1150
1120
  root,
1151
1121
  output,
1152
1122
  meta: { pluginKey: this.plugin.key },
1153
1123
  logger: this.logger
1154
1124
  });
1125
+ await this.fileManager.processFiles({
1126
+ logger: this.logger,
1127
+ files
1128
+ });
1155
1129
  }
1156
1130
  };
1157
1131
  });
1158
1132
 
1159
1133
  // src/components/Schema.tsx
1160
- import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
1134
+ import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
1161
1135
  function Schema2(props) {
1162
1136
  const { keysToOmit, withTypeAnnotation, description } = props;
1163
1137
  const { tree, name } = useSchema2();
@@ -1183,7 +1157,7 @@ function Schema2(props) {
1183
1157
  type: "type"
1184
1158
  });
1185
1159
  if (!tree.length) {
1186
- return /* @__PURE__ */ jsx10(
1160
+ return /* @__PURE__ */ jsx9(
1187
1161
  Const2,
1188
1162
  {
1189
1163
  name: resolvedName,
@@ -1204,7 +1178,7 @@ function Schema2(props) {
1204
1178
  }).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
1205
1179
  const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
1206
1180
  return /* @__PURE__ */ jsxs5(Fragment3, { children: [
1207
- /* @__PURE__ */ jsx10(
1181
+ /* @__PURE__ */ jsx9(
1208
1182
  Const2,
1209
1183
  {
1210
1184
  export: true,
@@ -1219,7 +1193,7 @@ function Schema2(props) {
1219
1193
  ].filter(Boolean).join("") || ""
1220
1194
  }
1221
1195
  ),
1222
- typedSchema && /* @__PURE__ */ jsx10(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` })
1196
+ typedSchema && /* @__PURE__ */ jsx9(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` })
1223
1197
  ] });
1224
1198
  }
1225
1199
  Schema2.File = function({}) {
@@ -1229,14 +1203,11 @@ Schema2.File = function({}) {
1229
1203
  options: { typed }
1230
1204
  }
1231
1205
  } = useApp6();
1232
- const { tree, schema } = useSchema2();
1233
- const withData = tree.some(
1234
- (schema2) => schema2.keyword === schemaKeywords5.array || schema2.keyword === schemaKeywords5.and || schema2.keyword === schemaKeywords5.object || schema2.keyword === schemaKeywords5.union || schema2.keyword === schemaKeywords5.tuple
1235
- );
1206
+ const { schema } = useSchema2();
1236
1207
  const withTypeAnnotation = !!typed;
1237
- return /* @__PURE__ */ jsxs5(Oas8.Schema.File, { output: pluginManager.config.output.path, children: [
1238
- /* @__PURE__ */ jsx10(Schema2.Imports, {}),
1239
- /* @__PURE__ */ jsx10(File6.Source, { children: /* @__PURE__ */ jsx10(Schema2, { withTypeAnnotation, description: schema?.description }) })
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 }) })
1240
1211
  ] });
1241
1212
  };
1242
1213
  Schema2.Imports = () => {
@@ -1264,16 +1235,16 @@ Schema2.Imports = () => {
1264
1235
  });
1265
1236
  const withTypeAnnotation = !!typed;
1266
1237
  return /* @__PURE__ */ jsxs5(Fragment3, { children: [
1267
- /* @__PURE__ */ jsx10(File6.Import, { name: ["z"], path: importPath }),
1268
- withTypeAnnotation && typeName && typePath && /* @__PURE__ */ jsx10(File6.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
1238
+ /* @__PURE__ */ jsx9(File6.Import, { name: ["z"], path: importPath }),
1239
+ withTypeAnnotation && typeName && typePath && /* @__PURE__ */ jsx9(File6.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
1269
1240
  ] });
1270
1241
  };
1271
1242
 
1272
1243
  export {
1244
+ Operations,
1273
1245
  Schema2 as Schema,
1274
1246
  OperationSchema2 as OperationSchema,
1275
- Operations,
1276
1247
  pluginZodName,
1277
1248
  pluginZod
1278
1249
  };
1279
- //# sourceMappingURL=chunk-ORHAR2XI.js.map
1250
+ //# sourceMappingURL=chunk-OJB3Q4CU.js.map