@kubb/plugin-zod 3.0.0-alpha.2 → 3.0.0-alpha.3

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
  }
@@ -608,7 +674,7 @@ import { isKeyword as isKeyword3, schemaKeywords as schemaKeywords5 } from "@kub
608
674
  import { useSchema as useSchema2 } from "@kubb/plugin-oas/hooks";
609
675
 
610
676
  // src/parser/index.ts
611
- import transformers4 from "@kubb/core/transformers";
677
+ import transformers5 from "@kubb/core/transformers";
612
678
  import { isKeyword as isKeyword2, schemaKeywords as schemaKeywords3 } from "@kubb/plugin-oas";
613
679
  var zodKeywordMapper = {
614
680
  any: () => "z.any()",
@@ -728,7 +794,7 @@ function sort(items) {
728
794
  if (!items) {
729
795
  return [];
730
796
  }
731
- return transformers4.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
797
+ return transformers5.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
732
798
  }
733
799
  function parse2(parent, current, options) {
734
800
  const value = zodKeywordMapper[current.keyword];
@@ -777,9 +843,9 @@ function parse2(parent, current, options) {
777
843
  return zodKeywordMapper.enum(
778
844
  current.args.items.map((schema) => {
779
845
  if (schema.format === "number") {
780
- return transformers4.stringify(schema.value);
846
+ return transformers5.stringify(schema.value);
781
847
  }
782
- return transformers4.stringify(schema.value);
848
+ return transformers5.stringify(schema.value);
783
849
  })
784
850
  );
785
851
  }
@@ -817,11 +883,11 @@ function parse2(parent, current, options) {
817
883
  if (current.args.format === "number" && current.args.value !== void 0) {
818
884
  return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
819
885
  }
820
- return zodKeywordMapper.const(transformers4.stringify(current.args.value));
886
+ return zodKeywordMapper.const(transformers5.stringify(current.args.value));
821
887
  }
822
888
  if (isKeyword2(current, schemaKeywords3.matches)) {
823
889
  if (current.args) {
824
- return zodKeywordMapper.matches(transformers4.toRegExpString(current.args));
890
+ return zodKeywordMapper.matches(transformers5.toRegExpString(current.args));
825
891
  }
826
892
  }
827
893
  if (isKeyword2(current, schemaKeywords3.default)) {
@@ -831,7 +897,7 @@ function parse2(parent, current, options) {
831
897
  }
832
898
  if (isKeyword2(current, schemaKeywords3.describe)) {
833
899
  if (current.args) {
834
- return zodKeywordMapper.describe(transformers4.stringify(current.args.toString()));
900
+ return zodKeywordMapper.describe(transformers5.stringify(current.args.toString()));
835
901
  }
836
902
  }
837
903
  if (isKeyword2(current, schemaKeywords3.string)) {
@@ -870,47 +936,24 @@ import path2 from "path";
870
936
  import { FileManager as FileManager2, PluginManager as PluginManager2, createPlugin as createPlugin2 } from "@kubb/core";
871
937
  import { camelCase as camelCase2, pascalCase as pascalCase2 } from "@kubb/core/transformers";
872
938
  import { renderTemplate as renderTemplate2 } from "@kubb/core/utils";
873
- import { pluginOasName as pluginOasName2 } from "@kubb/plugin-oas";
939
+ import { OperationGenerator as OperationGenerator2, pluginOasName as pluginOasName2, SchemaGenerator as SchemaGenerator4 } from "@kubb/plugin-oas";
874
940
  import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
875
941
 
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
942
  // 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
- };
943
+ import { createReactParser } from "@kubb/plugin-oas";
905
944
 
906
945
  // src/components/OperationSchema.tsx
907
- import { jsx as jsx7, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
946
+ import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
947
+ import { Oas as Oas5 } from "@kubb/plugin-oas/components";
948
+ import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager3 } from "@kubb/plugin-oas/hooks";
949
+ import { File as File5, Parser as Parser4, useApp as useApp5 } from "@kubb/react";
950
+ import { jsx as jsx7, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
908
951
  function OperationSchema2({ description, keysToOmit }) {
909
952
  return /* @__PURE__ */ jsx7(Schema2, { keysToOmit, withTypeAnnotation: false, description });
910
953
  }
911
954
  OperationSchema2.File = function({}) {
912
- const { pluginManager, plugin, mode } = useApp4();
913
- const { getSchemas, getFile } = useOperationManager2();
955
+ const { pluginManager, plugin, mode } = useApp5();
956
+ const { getSchemas, getFile } = useOperationManager3();
914
957
  const oas = useOas3();
915
958
  const operation = useOperation2();
916
959
  const file = getFile(operation);
@@ -927,111 +970,34 @@ OperationSchema2.File = function({}) {
927
970
  const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
928
971
  const optional = !required && !!name.includes("Params");
929
972
  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 }) })
973
+ return /* @__PURE__ */ jsxs4(Oas5.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
974
+ mode === "split" && /* @__PURE__ */ jsx7(Oas5.Schema.Imports, { extName: plugin.options.extName }),
975
+ /* @__PURE__ */ jsx7(File5.Source, { children: /* @__PURE__ */ jsx7(OperationSchema2, { description, keysToOmit }) })
933
976
  ] }, i);
934
977
  };
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 }),
978
+ return /* @__PURE__ */ jsx7(Parser4, { language: "typescript", children: /* @__PURE__ */ jsxs4(File5, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
979
+ /* @__PURE__ */ jsx7(File5.Import, { name: ["z"], path: plugin.options.importPath }),
937
980
  items.map(mapItem)
938
981
  ] }) });
939
982
  };
940
983
 
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 }
984
+ // src/SchemaGenerator.tsx
985
+ import { jsx as jsx8 } from "@kubb/react/jsx-runtime";
986
+ var zodParser = createReactParser({
987
+ name: "plugin-zod",
988
+ Operations({ options }) {
989
+ if (!options.templates.operations) {
990
+ return null;
978
991
  }
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;
992
+ return /* @__PURE__ */ jsx8(Operations.File, { templates: options.templates.operations });
993
+ },
994
+ Operation() {
995
+ return /* @__PURE__ */ jsx8(OperationSchema2.File, {});
996
+ },
997
+ Schema({ schema, name }) {
998
+ return /* @__PURE__ */ jsx8(Schema2.File, {});
1033
999
  }
1034
- };
1000
+ });
1035
1001
 
1036
1002
  // src/plugin.ts
1037
1003
  var pluginZodName = "plugin-zod";
@@ -1104,7 +1070,7 @@ var pluginZod = createPlugin2((options) => {
1104
1070
  const oas = await swaggerPlugin.context.getOas();
1105
1071
  const root = path2.resolve(this.config.root, this.config.output.path);
1106
1072
  const mode = FileManager2.getMode(path2.resolve(root, output.path));
1107
- const schemaGenerator = new SchemaGenerator3(this.plugin.options, {
1073
+ const schemaGenerator = new SchemaGenerator4(this.plugin.options, {
1108
1074
  oas,
1109
1075
  pluginManager: this.pluginManager,
1110
1076
  plugin: this.plugin,
@@ -1114,7 +1080,7 @@ var pluginZod = createPlugin2((options) => {
1114
1080
  mode,
1115
1081
  output: output.path
1116
1082
  });
1117
- const schemaFiles = await schemaGenerator.build();
1083
+ const schemaFiles = await schemaGenerator.build(zodParser);
1118
1084
  await this.addFile(...schemaFiles);
1119
1085
  const operationGenerator = new OperationGenerator2(this.plugin.options, {
1120
1086
  oas,
@@ -1126,7 +1092,7 @@ var pluginZod = createPlugin2((options) => {
1126
1092
  override,
1127
1093
  mode
1128
1094
  });
1129
- const operationFiles = await operationGenerator.build();
1095
+ const operationFiles = await operationGenerator.build(zodParser);
1130
1096
  await this.addFile(...operationFiles);
1131
1097
  },
1132
1098
  async buildEnd() {
@@ -1157,7 +1123,7 @@ var pluginZod = createPlugin2((options) => {
1157
1123
  });
1158
1124
 
1159
1125
  // src/components/Schema.tsx
1160
- import { Fragment as Fragment3, jsx as jsx10, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
1126
+ import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
1161
1127
  function Schema2(props) {
1162
1128
  const { keysToOmit, withTypeAnnotation, description } = props;
1163
1129
  const { tree, name } = useSchema2();
@@ -1183,7 +1149,7 @@ function Schema2(props) {
1183
1149
  type: "type"
1184
1150
  });
1185
1151
  if (!tree.length) {
1186
- return /* @__PURE__ */ jsx10(
1152
+ return /* @__PURE__ */ jsx9(
1187
1153
  Const2,
1188
1154
  {
1189
1155
  name: resolvedName,
@@ -1204,7 +1170,7 @@ function Schema2(props) {
1204
1170
  }).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
1205
1171
  const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
1206
1172
  return /* @__PURE__ */ jsxs5(Fragment3, { children: [
1207
- /* @__PURE__ */ jsx10(
1173
+ /* @__PURE__ */ jsx9(
1208
1174
  Const2,
1209
1175
  {
1210
1176
  export: true,
@@ -1219,7 +1185,7 @@ function Schema2(props) {
1219
1185
  ].filter(Boolean).join("") || ""
1220
1186
  }
1221
1187
  ),
1222
- typedSchema && /* @__PURE__ */ jsx10(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` })
1188
+ typedSchema && /* @__PURE__ */ jsx9(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` })
1223
1189
  ] });
1224
1190
  }
1225
1191
  Schema2.File = function({}) {
@@ -1229,14 +1195,11 @@ Schema2.File = function({}) {
1229
1195
  options: { typed }
1230
1196
  }
1231
1197
  } = 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
- );
1198
+ const { schema } = useSchema2();
1236
1199
  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 }) })
1200
+ return /* @__PURE__ */ jsxs5(Oas6.Schema.File, { output: pluginManager.config.output.path, children: [
1201
+ /* @__PURE__ */ jsx9(Schema2.Imports, {}),
1202
+ /* @__PURE__ */ jsx9(File6.Source, { children: /* @__PURE__ */ jsx9(Schema2, { withTypeAnnotation, description: schema?.description }) })
1240
1203
  ] });
1241
1204
  };
1242
1205
  Schema2.Imports = () => {
@@ -1264,16 +1227,16 @@ Schema2.Imports = () => {
1264
1227
  });
1265
1228
  const withTypeAnnotation = !!typed;
1266
1229
  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] })
1230
+ /* @__PURE__ */ jsx9(File6.Import, { name: ["z"], path: importPath }),
1231
+ withTypeAnnotation && typeName && typePath && /* @__PURE__ */ jsx9(File6.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
1269
1232
  ] });
1270
1233
  };
1271
1234
 
1272
1235
  export {
1236
+ Operations,
1273
1237
  Schema2 as Schema,
1274
1238
  OperationSchema2 as OperationSchema,
1275
- Operations,
1276
1239
  pluginZodName,
1277
1240
  pluginZod
1278
1241
  };
1279
- //# sourceMappingURL=chunk-ORHAR2XI.js.map
1242
+ //# sourceMappingURL=chunk-XCGVHLYD.js.map