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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +13 -4
  2. package/dist/chunk-FLFW72FT.cjs +344 -0
  3. package/dist/chunk-FLFW72FT.cjs.map +1 -0
  4. package/dist/chunk-G6GLWNC4.cjs +245 -0
  5. package/dist/chunk-G6GLWNC4.cjs.map +1 -0
  6. package/dist/chunk-KMSM5GLX.js +236 -0
  7. package/dist/chunk-KMSM5GLX.js.map +1 -0
  8. package/dist/chunk-UONLSRDV.js +337 -0
  9. package/dist/chunk-UONLSRDV.js.map +1 -0
  10. package/dist/components.cjs +11 -6
  11. package/dist/components.cjs.map +1 -1
  12. package/dist/components.d.cts +20 -19
  13. package/dist/components.d.ts +20 -19
  14. package/dist/components.js +2 -10
  15. package/dist/components.js.map +1 -1
  16. package/dist/generators.cjs +17 -0
  17. package/dist/generators.cjs.map +1 -0
  18. package/dist/generators.d.cts +10 -0
  19. package/dist/generators.d.ts +10 -0
  20. package/dist/generators.js +4 -0
  21. package/dist/generators.js.map +1 -0
  22. package/dist/index.cjs +12 -4
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +4 -137
  25. package/dist/index.d.ts +4 -137
  26. package/dist/index.js +3 -8
  27. package/dist/index.js.map +1 -1
  28. package/dist/types-ryu2n1NA.d.cts +95 -0
  29. package/dist/types-ryu2n1NA.d.ts +95 -0
  30. package/package.json +19 -21
  31. package/src/components/Operations.tsx +19 -103
  32. package/src/components/Zod.tsx +66 -0
  33. package/src/components/index.ts +1 -2
  34. package/src/generators/__snapshots__/anyof.ts +3 -0
  35. package/src/generators/__snapshots__/createPet.ts +15 -0
  36. package/src/generators/__snapshots__/createPetWithUnknownTypeAny.ts +13 -0
  37. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +15 -0
  38. package/src/generators/__snapshots__/deletePet.ts +3 -0
  39. package/src/generators/__snapshots__/discriminator.ts +3 -0
  40. package/src/generators/__snapshots__/enumBooleanLiteral.ts +3 -0
  41. package/src/generators/__snapshots__/enumNamesType.ts +3 -0
  42. package/src/generators/__snapshots__/enumNullable.ts +3 -0
  43. package/src/generators/__snapshots__/enumSingleLiteral.ts +3 -0
  44. package/src/generators/__snapshots__/enumVarNamesType.ts +3 -0
  45. package/src/generators/__snapshots__/example.ts +3 -0
  46. package/src/generators/__snapshots__/getPets.ts +18 -0
  47. package/src/generators/__snapshots__/mixedValueTypeConst.ts +6 -0
  48. package/src/generators/__snapshots__/nullableString.ts +3 -0
  49. package/src/generators/__snapshots__/nullableStringUuid.ts +3 -0
  50. package/src/generators/__snapshots__/nullableStringWithAnyOf.ts +3 -0
  51. package/src/generators/__snapshots__/numberValueConst.ts +6 -0
  52. package/src/generators/__snapshots__/oneof.ts +3 -0
  53. package/src/generators/__snapshots__/operations.ts +46 -0
  54. package/src/generators/__snapshots__/optionalPetInfer.ts +5 -0
  55. package/src/generators/__snapshots__/optionalPetTyped.ts +3 -0
  56. package/src/generators/__snapshots__/order.ts +3 -0
  57. package/src/generators/__snapshots__/orderDateTyeString.ts +10 -0
  58. package/src/generators/__snapshots__/orderDateTypeFalse.ts +3 -0
  59. package/src/generators/__snapshots__/orderDateTypeString.ts +3 -0
  60. package/src/generators/__snapshots__/pet.ts +3 -0
  61. package/src/generators/__snapshots__/petArray.ts +6 -0
  62. package/src/generators/__snapshots__/petCoercion.ts +3 -0
  63. package/src/generators/__snapshots__/petTupleObject.ts +6 -0
  64. package/src/generators/__snapshots__/petWithMapper.ts +3 -0
  65. package/src/generators/__snapshots__/pets.ts +3 -0
  66. package/src/generators/__snapshots__/recursive.ts +3 -0
  67. package/src/generators/__snapshots__/showPetById.ts +18 -0
  68. package/src/generators/__snapshots__/stringValueConst.ts +6 -0
  69. package/src/generators/__snapshots__/uuidSchema.ts +3 -0
  70. package/src/generators/index.ts +2 -0
  71. package/src/generators/operationsGenerator.tsx +39 -0
  72. package/src/generators/zodGenerator.tsx +121 -0
  73. package/src/parser/index.ts +34 -10
  74. package/src/plugin.ts +28 -46
  75. package/src/types.ts +42 -88
  76. package/dist/Operations-BlQtRP31.d.cts +0 -47
  77. package/dist/Operations-BlQtRP31.d.ts +0 -47
  78. package/dist/chunk-7X3NWYUN.cjs +0 -1242
  79. package/dist/chunk-7X3NWYUN.cjs.map +0 -1
  80. package/dist/chunk-XCGVHLYD.js +0 -1242
  81. package/dist/chunk-XCGVHLYD.js.map +0 -1
  82. package/src/SchemaGenerator.tsx +0 -22
  83. package/src/components/OperationSchema.tsx +0 -64
  84. package/src/components/Schema.tsx +0 -162
  85. package/src/components/__snapshots__/operations.ts +0 -50
@@ -0,0 +1,245 @@
1
+ 'use strict';
2
+
3
+ var chunkFLFW72FT_cjs = require('./chunk-FLFW72FT.cjs');
4
+ var pluginOas = require('@kubb/plugin-oas');
5
+ var components = require('@kubb/plugin-oas/components');
6
+ var hooks = require('@kubb/plugin-oas/hooks');
7
+ var pluginTs = require('@kubb/plugin-ts');
8
+ var react = require('@kubb/react');
9
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
10
+ var path = require('path');
11
+ var core = require('@kubb/core');
12
+ var transformers = require('@kubb/core/transformers');
13
+ require('@kubb/core/utils');
14
+
15
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
16
+
17
+ var path__default = /*#__PURE__*/_interopDefault(path);
18
+
19
+ var zodGenerator = pluginOas.createReactGenerator({
20
+ name: "zod",
21
+ Operation({ operation, options }) {
22
+ const { coercion, inferred, typed, mapper } = options;
23
+ const { plugin, pluginManager, mode } = react.useApp();
24
+ const oas = hooks.useOas();
25
+ const { getSchemas, getFile } = hooks.useOperationManager();
26
+ const schemaManager = hooks.useSchemaManager();
27
+ const file = getFile(operation);
28
+ const schemas = getSchemas(operation);
29
+ const schemaGenerator = new pluginOas.SchemaGenerator(options, {
30
+ oas,
31
+ plugin,
32
+ pluginManager,
33
+ mode,
34
+ override: options.override
35
+ });
36
+ const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
37
+ const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options2 }, i) => {
38
+ const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
39
+ const optional = !required && !!name.includes("Params");
40
+ const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: pluginOas.schemaKeywords.optional } : void 0].filter(Boolean);
41
+ const imports = schemaManager.getImports(tree);
42
+ const zod = {
43
+ name: schemaManager.getName(name, { type: "function" }),
44
+ inferTypeName: schemaManager.getName(name, { type: "type" }),
45
+ file: schemaManager.getFile(name)
46
+ };
47
+ const type = {
48
+ name: schemaManager.getName(name, { type: "type", pluginKey: [pluginTs.pluginTsName] }),
49
+ file: schemaManager.getFile(options2.operationName || name, { pluginKey: [pluginTs.pluginTsName], tag: options2.operation?.getTags()[0]?.name })
50
+ };
51
+ return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
52
+ typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: file.path, path: type.file.path, name: [type.name] }),
53
+ imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: file.path, path: imp.path, name: imp.name }, index)),
54
+ /* @__PURE__ */ jsxRuntime.jsx(
55
+ chunkFLFW72FT_cjs.Zod,
56
+ {
57
+ name: zod.name,
58
+ typeName: typed ? type.name : void 0,
59
+ inferTypeName: inferred ? zod.inferTypeName : void 0,
60
+ description,
61
+ tree,
62
+ mapper,
63
+ coercion,
64
+ keysToOmit
65
+ }
66
+ )
67
+ ] }, i);
68
+ };
69
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
70
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: plugin.options.importPath }),
71
+ operationSchemas.map(mapOperationSchema)
72
+ ] });
73
+ },
74
+ Schema({ schema, options }) {
75
+ const { coercion, inferred, typed, mapper, importPath } = options;
76
+ const { getName, getFile, getImports } = hooks.useSchemaManager();
77
+ const {
78
+ plugin: {
79
+ options: { output }
80
+ }
81
+ } = react.useApp();
82
+ const imports = getImports(schema.tree);
83
+ const zod = {
84
+ name: getName(schema.name, { type: "function" }),
85
+ inferTypeName: getName(schema.name, { type: "type" }),
86
+ file: getFile(schema.name)
87
+ };
88
+ const type = {
89
+ name: getName(schema.name, { type: "type", pluginKey: [pluginTs.pluginTsName] }),
90
+ file: getFile(schema.name, { pluginKey: [pluginTs.pluginTsName] })
91
+ };
92
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: output?.banner, footer: output?.footer, children: [
93
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: importPath }),
94
+ typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
95
+ imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: zod.file.path, path: imp.path, name: imp.name }, index)),
96
+ /* @__PURE__ */ jsxRuntime.jsx(
97
+ chunkFLFW72FT_cjs.Zod,
98
+ {
99
+ name: zod.name,
100
+ typeName: typed ? type.name : void 0,
101
+ inferTypeName: inferred ? zod.inferTypeName : void 0,
102
+ description: schema.value.description,
103
+ tree: schema.tree,
104
+ mapper,
105
+ coercion
106
+ }
107
+ )
108
+ ] });
109
+ }
110
+ });
111
+ var pluginZodName = "plugin-zod";
112
+ var pluginZod = core.createPlugin((options) => {
113
+ const {
114
+ output = { path: "zod", barrelType: "named" },
115
+ group,
116
+ exclude = [],
117
+ include,
118
+ override = [],
119
+ transformers: transformers$1 = {},
120
+ dateType = "string",
121
+ unknownType = "any",
122
+ typed = false,
123
+ mapper = {},
124
+ operations = false,
125
+ importPath = "zod",
126
+ coercion = false,
127
+ inferred = false,
128
+ generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean)
129
+ } = options;
130
+ return {
131
+ name: pluginZodName,
132
+ options: {
133
+ output,
134
+ transformers: transformers$1,
135
+ include,
136
+ exclude,
137
+ override,
138
+ typed,
139
+ dateType,
140
+ unknownType,
141
+ mapper,
142
+ importPath,
143
+ coercion,
144
+ operations,
145
+ inferred
146
+ },
147
+ pre: [pluginOas.pluginOasName, typed ? pluginTs.pluginTsName : void 0].filter(Boolean),
148
+ resolvePath(baseName, pathMode, options2) {
149
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
150
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
151
+ if (options2?.tag && group?.type === "tag") {
152
+ const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
153
+ return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
154
+ }
155
+ if (mode === "single") {
156
+ return path__default.default.resolve(root, output.path);
157
+ }
158
+ return path__default.default.resolve(root, output.path, baseName);
159
+ },
160
+ resolveName(name, type) {
161
+ let resolvedName = transformers.camelCase(name, {
162
+ suffix: type ? "schema" : void 0,
163
+ isFile: type === "file"
164
+ });
165
+ if (type === "type") {
166
+ resolvedName = transformers.pascalCase(resolvedName);
167
+ }
168
+ if (type) {
169
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
170
+ }
171
+ return resolvedName;
172
+ },
173
+ async buildStart() {
174
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
175
+ const oas = await swaggerPlugin.context.getOas();
176
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
177
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
178
+ const schemaGenerator = new pluginOas.SchemaGenerator(this.plugin.options, {
179
+ oas,
180
+ pluginManager: this.pluginManager,
181
+ plugin: this.plugin,
182
+ contentType: swaggerPlugin.context.contentType,
183
+ include: void 0,
184
+ override,
185
+ mode,
186
+ output: output.path
187
+ });
188
+ const schemaFiles = await schemaGenerator.build(...generators);
189
+ await this.addFile(...schemaFiles);
190
+ const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
191
+ oas,
192
+ pluginManager: this.pluginManager,
193
+ plugin: this.plugin,
194
+ contentType: swaggerPlugin.context.contentType,
195
+ exclude,
196
+ include,
197
+ override,
198
+ mode
199
+ });
200
+ const operationFiles = await operationGenerator.build(...generators);
201
+ await this.addFile(...operationFiles);
202
+ const barrelFiles = await this.fileManager.getBarrelFiles({
203
+ type: output.barrelType ?? "named",
204
+ root,
205
+ output,
206
+ files: this.fileManager.files,
207
+ meta: {
208
+ pluginKey: this.plugin.key
209
+ },
210
+ logger: this.logger
211
+ });
212
+ await this.addFile(...barrelFiles);
213
+ }
214
+ };
215
+ });
216
+ var operationsGenerator = pluginOas.createReactGenerator({
217
+ name: "operations",
218
+ Operations({ operations }) {
219
+ const {
220
+ pluginManager,
221
+ plugin: {
222
+ options: { output }
223
+ }
224
+ } = react.useApp();
225
+ const { getFile, groupSchemasByName } = hooks.useOperationManager();
226
+ const name = "operations";
227
+ const file = pluginManager.getFile({ name, extname: ".ts", pluginKey: [pluginZodName] });
228
+ const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
229
+ const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
230
+ const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
231
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
232
+ }).filter(Boolean);
233
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: [
234
+ imports,
235
+ /* @__PURE__ */ jsxRuntime.jsx(chunkFLFW72FT_cjs.Operations, { name, operations: transformedOperations })
236
+ ] });
237
+ }
238
+ });
239
+
240
+ exports.operationsGenerator = operationsGenerator;
241
+ exports.pluginZod = pluginZod;
242
+ exports.pluginZodName = pluginZodName;
243
+ exports.zodGenerator = zodGenerator;
244
+ //# sourceMappingURL=chunk-G6GLWNC4.cjs.map
245
+ //# sourceMappingURL=chunk-G6GLWNC4.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/plugin.ts","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","useSchemaManager","SchemaGenerator","options","schemaKeywords","pluginTsName","Oas","File","jsx","Zod","jsxs","createPlugin","transformers","pluginOasName","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator","Operations"],"mappings":";;;;;;;;;;;;;;;;;;AAQO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,KAAA,EAAO,QAAW,GAAA,OAAA,CAAA;AAE9C,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAASC,YAAkB,EAAA,CAAA;AAC1D,IAAA,MAAM,MAAMC,YAAO,EAAA,CAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAQ,EAAA,GAAIC,yBAAoB,EAAA,CAAA;AACpD,IAAA,MAAM,gBAAgBC,sBAAiB,EAAA,CAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAIC,yBAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OA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Q,QAAQ,MAAQ,EAAA,MAAA,EAAQ,QAAQ,MACtG,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDC,cAAAA,CAACY,4BAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA,CAAA;AAAA,KAC7D,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-G6GLWNC4.cjs","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion, inferred, typed, mapper } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required\n const optional = !required && !!name.includes('Params')\n const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, { type: 'type', pluginKey: [pluginTsName] }),\n file: schemaManager.getFile(options.operationName || name, { pluginKey: [pluginTsName], tag: options.operation?.getTags()[0]?.name }),\n }\n\n return (\n <Oas.Schema key={i} name={name} value={schema} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n mapper={mapper}\n coercion={coercion}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n },\n pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport { pluginZodName } from '../plugin.ts'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: [pluginZodName] })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
@@ -0,0 +1,236 @@
1
+ import { Zod, Operations } from './chunk-UONLSRDV.js';
2
+ import { createReactGenerator, SchemaGenerator, pluginOasName, OperationGenerator, schemaKeywords } from '@kubb/plugin-oas';
3
+ import { Oas } from '@kubb/plugin-oas/components';
4
+ import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks';
5
+ import { pluginTsName } from '@kubb/plugin-ts';
6
+ import { useApp, File } from '@kubb/react';
7
+ import { jsxs, jsx } from '@kubb/react/jsx-runtime';
8
+ import path from 'node:path';
9
+ import { createPlugin, FileManager, PluginManager } from '@kubb/core';
10
+ import { camelCase, pascalCase } from '@kubb/core/transformers';
11
+ import '@kubb/core/utils';
12
+
13
+ var zodGenerator = createReactGenerator({
14
+ name: "zod",
15
+ Operation({ operation, options }) {
16
+ const { coercion, inferred, typed, mapper } = options;
17
+ const { plugin, pluginManager, mode } = useApp();
18
+ const oas = useOas();
19
+ const { getSchemas, getFile } = useOperationManager();
20
+ const schemaManager = useSchemaManager();
21
+ const file = getFile(operation);
22
+ const schemas = getSchemas(operation);
23
+ const schemaGenerator = new SchemaGenerator(options, {
24
+ oas,
25
+ plugin,
26
+ pluginManager,
27
+ mode,
28
+ override: options.override
29
+ });
30
+ const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
31
+ const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options2 }, i) => {
32
+ const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
33
+ const optional = !required && !!name.includes("Params");
34
+ const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: schemaKeywords.optional } : void 0].filter(Boolean);
35
+ const imports = schemaManager.getImports(tree);
36
+ const zod = {
37
+ name: schemaManager.getName(name, { type: "function" }),
38
+ inferTypeName: schemaManager.getName(name, { type: "type" }),
39
+ file: schemaManager.getFile(name)
40
+ };
41
+ const type = {
42
+ name: schemaManager.getName(name, { type: "type", pluginKey: [pluginTsName] }),
43
+ file: schemaManager.getFile(options2.operationName || name, { pluginKey: [pluginTsName], tag: options2.operation?.getTags()[0]?.name })
44
+ };
45
+ return /* @__PURE__ */ jsxs(Oas.Schema, { name, value: schema, tree, children: [
46
+ typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root: file.path, path: type.file.path, name: [type.name] }),
47
+ imports.map((imp, index) => /* @__PURE__ */ jsx(File.Import, { root: file.path, path: imp.path, name: imp.name }, index)),
48
+ /* @__PURE__ */ jsx(
49
+ Zod,
50
+ {
51
+ name: zod.name,
52
+ typeName: typed ? type.name : void 0,
53
+ inferTypeName: inferred ? zod.inferTypeName : void 0,
54
+ description,
55
+ tree,
56
+ mapper,
57
+ coercion,
58
+ keysToOmit
59
+ }
60
+ )
61
+ ] }, i);
62
+ };
63
+ return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
64
+ /* @__PURE__ */ jsx(File.Import, { name: ["z"], path: plugin.options.importPath }),
65
+ operationSchemas.map(mapOperationSchema)
66
+ ] });
67
+ },
68
+ Schema({ schema, options }) {
69
+ const { coercion, inferred, typed, mapper, importPath } = options;
70
+ const { getName, getFile, getImports } = useSchemaManager();
71
+ const {
72
+ plugin: {
73
+ options: { output }
74
+ }
75
+ } = useApp();
76
+ const imports = getImports(schema.tree);
77
+ const zod = {
78
+ name: getName(schema.name, { type: "function" }),
79
+ inferTypeName: getName(schema.name, { type: "type" }),
80
+ file: getFile(schema.name)
81
+ };
82
+ const type = {
83
+ name: getName(schema.name, { type: "type", pluginKey: [pluginTsName] }),
84
+ file: getFile(schema.name, { pluginKey: [pluginTsName] })
85
+ };
86
+ return /* @__PURE__ */ jsxs(File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: output?.banner, footer: output?.footer, children: [
87
+ /* @__PURE__ */ jsx(File.Import, { name: ["z"], path: importPath }),
88
+ typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
89
+ imports.map((imp, index) => /* @__PURE__ */ jsx(File.Import, { root: zod.file.path, path: imp.path, name: imp.name }, index)),
90
+ /* @__PURE__ */ jsx(
91
+ Zod,
92
+ {
93
+ name: zod.name,
94
+ typeName: typed ? type.name : void 0,
95
+ inferTypeName: inferred ? zod.inferTypeName : void 0,
96
+ description: schema.value.description,
97
+ tree: schema.tree,
98
+ mapper,
99
+ coercion
100
+ }
101
+ )
102
+ ] });
103
+ }
104
+ });
105
+ var pluginZodName = "plugin-zod";
106
+ var pluginZod = createPlugin((options) => {
107
+ const {
108
+ output = { path: "zod", barrelType: "named" },
109
+ group,
110
+ exclude = [],
111
+ include,
112
+ override = [],
113
+ transformers = {},
114
+ dateType = "string",
115
+ unknownType = "any",
116
+ typed = false,
117
+ mapper = {},
118
+ operations = false,
119
+ importPath = "zod",
120
+ coercion = false,
121
+ inferred = false,
122
+ generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean)
123
+ } = options;
124
+ return {
125
+ name: pluginZodName,
126
+ options: {
127
+ output,
128
+ transformers,
129
+ include,
130
+ exclude,
131
+ override,
132
+ typed,
133
+ dateType,
134
+ unknownType,
135
+ mapper,
136
+ importPath,
137
+ coercion,
138
+ operations,
139
+ inferred
140
+ },
141
+ pre: [pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
142
+ resolvePath(baseName, pathMode, options2) {
143
+ const root = path.resolve(this.config.root, this.config.output.path);
144
+ const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
145
+ if (options2?.tag && group?.type === "tag") {
146
+ const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
147
+ return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
148
+ }
149
+ if (mode === "single") {
150
+ return path.resolve(root, output.path);
151
+ }
152
+ return path.resolve(root, output.path, baseName);
153
+ },
154
+ resolveName(name, type) {
155
+ let resolvedName = camelCase(name, {
156
+ suffix: type ? "schema" : void 0,
157
+ isFile: type === "file"
158
+ });
159
+ if (type === "type") {
160
+ resolvedName = pascalCase(resolvedName);
161
+ }
162
+ if (type) {
163
+ return transformers?.name?.(resolvedName, type) || resolvedName;
164
+ }
165
+ return resolvedName;
166
+ },
167
+ async buildStart() {
168
+ const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
169
+ const oas = await swaggerPlugin.context.getOas();
170
+ const root = path.resolve(this.config.root, this.config.output.path);
171
+ const mode = FileManager.getMode(path.resolve(root, output.path));
172
+ const schemaGenerator = new SchemaGenerator(this.plugin.options, {
173
+ oas,
174
+ pluginManager: this.pluginManager,
175
+ plugin: this.plugin,
176
+ contentType: swaggerPlugin.context.contentType,
177
+ include: void 0,
178
+ override,
179
+ mode,
180
+ output: output.path
181
+ });
182
+ const schemaFiles = await schemaGenerator.build(...generators);
183
+ await this.addFile(...schemaFiles);
184
+ const operationGenerator = new OperationGenerator(this.plugin.options, {
185
+ oas,
186
+ pluginManager: this.pluginManager,
187
+ plugin: this.plugin,
188
+ contentType: swaggerPlugin.context.contentType,
189
+ exclude,
190
+ include,
191
+ override,
192
+ mode
193
+ });
194
+ const operationFiles = await operationGenerator.build(...generators);
195
+ await this.addFile(...operationFiles);
196
+ const barrelFiles = await this.fileManager.getBarrelFiles({
197
+ type: output.barrelType ?? "named",
198
+ root,
199
+ output,
200
+ files: this.fileManager.files,
201
+ meta: {
202
+ pluginKey: this.plugin.key
203
+ },
204
+ logger: this.logger
205
+ });
206
+ await this.addFile(...barrelFiles);
207
+ }
208
+ };
209
+ });
210
+ var operationsGenerator = createReactGenerator({
211
+ name: "operations",
212
+ Operations({ operations }) {
213
+ const {
214
+ pluginManager,
215
+ plugin: {
216
+ options: { output }
217
+ }
218
+ } = useApp();
219
+ const { getFile, groupSchemasByName } = useOperationManager();
220
+ const name = "operations";
221
+ const file = pluginManager.getFile({ name, extname: ".ts", pluginKey: [pluginZodName] });
222
+ const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
223
+ const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
224
+ const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
225
+ return /* @__PURE__ */ jsx(File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
226
+ }).filter(Boolean);
227
+ return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: [
228
+ imports,
229
+ /* @__PURE__ */ jsx(Operations, { name, operations: transformedOperations })
230
+ ] });
231
+ }
232
+ });
233
+
234
+ export { operationsGenerator, pluginZod, pluginZodName, zodGenerator };
235
+ //# sourceMappingURL=chunk-KMSM5GLX.js.map
236
+ //# sourceMappingURL=chunk-KMSM5GLX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/plugin.ts","../src/generators/operationsGenerator.tsx"],"names":["options","pluginTsName","SchemaGenerator","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;;;;;;;;AAQO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,KAA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A,IAAA,CAAK,UAAU,CAAC,CAAA,CAAE,OAAO,OAAO,CAAA,CAAA;AAEhH,MAAA,uBAAOC,GAAAA,CAACC,IAAK,CAAA,MAAA,EAAL,EAAsB,IAAM,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,CAAK,MAAM,IAAM,EAAA,OAAA,CAAQ,SAAS,CAAA,CAAE,QAA5D,GAAkE,CAAA,CAAA;AAAA,KAC5F,CACA,CAAA,MAAA,CAAO,OAAO,CAAA,CAAA;AAEjB,IAAA,uBACEC,IAACD,CAAAA,IAAAA,EAAA,EAAK,QAAU,EAAA,IAAA,CAAK,UAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,EAAQ,QAAQ,MACtG,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDD,GAAAA,CAAC,UAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA,CAAA;AAAA,KAC7D,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-KMSM5GLX.js","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion, inferred, typed, mapper } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required\n const optional = !required && !!name.includes('Params')\n const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, { type: 'type', pluginKey: [pluginTsName] }),\n file: schemaManager.getFile(options.operationName || name, { pluginKey: [pluginTsName], tag: options.operation?.getTags()[0]?.name }),\n }\n\n return (\n <Oas.Schema key={i} name={name} value={schema} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n mapper={mapper}\n coercion={coercion}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n },\n pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport { pluginZodName } from '../plugin.ts'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey: [pluginZodName] })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}