@kubb/plugin-zod 4.4.1 → 4.5.1

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 (54) hide show
  1. package/dist/{components-DUJ6Xkpc.js → components-BtBB23cQ.js} +85 -75
  2. package/dist/components-BtBB23cQ.js.map +1 -0
  3. package/dist/{components-BiOh-7_I.cjs → components-DIUzzW4k.cjs} +82 -72
  4. package/dist/components-DIUzzW4k.cjs.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.cts +3 -3
  7. package/dist/components.d.ts +3 -3
  8. package/dist/components.js +1 -1
  9. package/dist/{generators-B2hD7k6l.cjs → generators-BOldMlBb.cjs} +119 -123
  10. package/dist/generators-BOldMlBb.cjs.map +1 -0
  11. package/dist/{generators-CwEOtNXG.js → generators-DpdxKqO8.js} +120 -125
  12. package/dist/generators-DpdxKqO8.js.map +1 -0
  13. package/dist/generators.cjs +2 -2
  14. package/dist/generators.d.cts +4 -4
  15. package/dist/generators.d.ts +4 -4
  16. package/dist/generators.js +2 -2
  17. package/dist/index.cjs +12 -2
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +11 -2
  22. package/dist/index.js.map +1 -1
  23. package/dist/{types-CS916VXJ.d.ts → types-CQSK_Scm.d.cts} +133 -139
  24. package/dist/{types-Cd7g28dR.d.cts → types-DcQBOr_-.d.ts} +133 -139
  25. package/package.json +10 -18
  26. package/src/components/Zod.tsx +7 -13
  27. package/src/generators/__snapshots__/createPet.ts +2 -2
  28. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +2 -2
  29. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput.ts +7 -9
  30. package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown_wrapOutput_entire_.ts +7 -10
  31. package/src/generators/__snapshots__/createPet_wrapOutput.ts +7 -9
  32. package/src/generators/__snapshots__/discriminator.ts +20 -28
  33. package/src/generators/__snapshots__/getPets.ts +4 -4
  34. package/src/generators/__snapshots__/getPets_wrapOutput.ts +8 -10
  35. package/src/generators/__snapshots__/petArray.ts +1 -5
  36. package/src/generators/__snapshots__/queryAllDefaulted.ts +3 -3
  37. package/src/generators/__snapshots__/queryAllDefaulted_wrapOutput.ts +2 -2
  38. package/src/generators/__snapshots__/showPetById.ts +3 -3
  39. package/src/generators/__snapshots__/showPetById_wrapOutput.ts +8 -10
  40. package/src/generators/index.ts +1 -1
  41. package/src/generators/operationsGenerator.tsx +5 -5
  42. package/src/generators/zodGenerator.tsx +35 -25
  43. package/src/parser.ts +37 -36
  44. package/src/plugin.ts +15 -0
  45. package/dist/components-BiOh-7_I.cjs.map +0 -1
  46. package/dist/components-DUJ6Xkpc.js.map +0 -1
  47. package/dist/generators-B2hD7k6l.cjs.map +0 -1
  48. package/dist/generators-CwEOtNXG.js.map +0 -1
  49. package/dist/utils.cjs +0 -0
  50. package/dist/utils.d.cts +0 -28
  51. package/dist/utils.d.ts +0 -28
  52. package/dist/utils.js +0 -1
  53. package/src/utils/index.ts +0 -1
  54. /package/{src/utils → templates}/ToZod.ts +0 -0
@@ -1,12 +1,14 @@
1
- const require_components = require('./components-BiOh-7_I.cjs');
1
+ const require_components = require('./components-DIUzzW4k.cjs');
2
+ let node_path = require("node:path");
3
+ node_path = require_components.__toESM(node_path);
2
4
  let __kubb_plugin_oas = require("@kubb/plugin-oas");
3
5
  __kubb_plugin_oas = require_components.__toESM(__kubb_plugin_oas);
4
6
  let __kubb_plugin_ts = require("@kubb/plugin-ts");
5
7
  __kubb_plugin_ts = require_components.__toESM(__kubb_plugin_ts);
6
8
  let __kubb_core_hooks = require("@kubb/core/hooks");
7
9
  __kubb_core_hooks = require_components.__toESM(__kubb_core_hooks);
8
- let __kubb_plugin_oas_components = require("@kubb/plugin-oas/components");
9
- __kubb_plugin_oas_components = require_components.__toESM(__kubb_plugin_oas_components);
10
+ let __kubb_plugin_oas_generators = require("@kubb/plugin-oas/generators");
11
+ __kubb_plugin_oas_generators = require_components.__toESM(__kubb_plugin_oas_generators);
10
12
  let __kubb_plugin_oas_hooks = require("@kubb/plugin-oas/hooks");
11
13
  __kubb_plugin_oas_hooks = require_components.__toESM(__kubb_plugin_oas_hooks);
12
14
  let __kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
@@ -16,21 +18,80 @@ __kubb_react_fabric = require_components.__toESM(__kubb_react_fabric);
16
18
  let __kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
17
19
  __kubb_react_fabric_jsx_runtime = require_components.__toESM(__kubb_react_fabric_jsx_runtime);
18
20
 
21
+ //#region src/generators/operationsGenerator.tsx
22
+ const operationsGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
23
+ name: "operations",
24
+ Operations({ operations, generator, plugin }) {
25
+ const { key: pluginKey, options: { output, importPath } } = plugin;
26
+ const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
27
+ const oas = (0, __kubb_plugin_oas_hooks.useOas)();
28
+ const { getFile, groupSchemasByName } = (0, __kubb_plugin_oas_hooks.useOperationManager)(generator);
29
+ const name = "operations";
30
+ const file = pluginManager.getFile({
31
+ name,
32
+ extname: ".ts",
33
+ pluginKey
34
+ });
35
+ const transformedOperations = operations.map((operation) => ({
36
+ operation,
37
+ data: groupSchemasByName(operation, { type: "function" })
38
+ }));
39
+ const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
40
+ const names = [
41
+ data.request,
42
+ ...Object.values(data.responses),
43
+ ...Object.values(data.parameters)
44
+ ].filter(Boolean);
45
+ return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
46
+ name: names,
47
+ root: file.path,
48
+ path: getFile(operation).path
49
+ }, key);
50
+ }).filter(Boolean);
51
+ return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.File, {
52
+ baseName: file.baseName,
53
+ path: file.path,
54
+ meta: file.meta,
55
+ banner: (0, __kubb_plugin_oas_utils.getBanner)({
56
+ oas,
57
+ output,
58
+ config: pluginManager.config
59
+ }),
60
+ footer: (0, __kubb_plugin_oas_utils.getFooter)({
61
+ oas,
62
+ output
63
+ }),
64
+ children: [
65
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
66
+ isTypeOnly: true,
67
+ name: ["z"],
68
+ path: importPath
69
+ }),
70
+ imports,
71
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Operations, {
72
+ name,
73
+ operations: transformedOperations
74
+ })
75
+ ]
76
+ });
77
+ }
78
+ });
79
+
80
+ //#endregion
19
81
  //#region src/generators/zodGenerator.tsx
20
- const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
82
+ const zodGenerator = (0, __kubb_plugin_oas_generators.createReactGenerator)({
21
83
  name: "zod",
22
- Operation({ operation, options, instance }) {
23
- const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options;
24
- const plugin = (0, __kubb_core_hooks.usePlugin)();
84
+ Operation({ config, operation, generator, plugin }) {
85
+ const { options, options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version } } = plugin;
25
86
  const mode = (0, __kubb_core_hooks.useMode)();
26
87
  const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
27
88
  const oas = (0, __kubb_plugin_oas_hooks.useOas)();
28
- const { getSchemas, getFile, getGroup } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
89
+ const { getSchemas, getFile, getGroup } = (0, __kubb_plugin_oas_hooks.useOperationManager)(generator);
29
90
  const schemaManager = (0, __kubb_plugin_oas_hooks.useSchemaManager)();
30
91
  const file = getFile(operation);
31
92
  const schemas = getSchemas(operation);
32
93
  const schemaGenerator = new __kubb_plugin_oas.SchemaGenerator(options, {
33
- fabric: instance.context.fabric,
94
+ fabric: generator.context.fabric,
34
95
  oas,
35
96
  plugin,
36
97
  pluginManager,
@@ -45,10 +106,11 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
45
106
  schemas.request,
46
107
  schemas.response
47
108
  ].flat().filter(Boolean);
48
- const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }, i) => {
49
- const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
50
- const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, "default") && property.default !== void 0);
51
- const optional = !required && !someDefaults && name.includes("Params");
109
+ const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }) => {
110
+ const hasProperties = Object.keys(schemaObject || {}).length > 0;
111
+ const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, "default"));
112
+ const optional = !(Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required) && !hasDefaults && hasProperties && name.includes("Params");
113
+ if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) schemaObject.required = Object.entries(schemaObject.properties || {}).filter(([_key, value]) => value && Object.hasOwn(value, "default")).map(([key]) => key);
52
114
  const tree = [...schemaGenerator.parse({
53
115
  schemaObject,
54
116
  name
@@ -75,47 +137,42 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
75
137
  group
76
138
  })
77
139
  };
78
- return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_plugin_oas_components.Oas.Schema, {
79
- name,
80
- schemaObject,
81
- tree,
82
- children: [
83
- typed && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
84
- isTypeOnly: true,
85
- root: file.path,
86
- path: type.file.path,
87
- name: [type.name]
88
- }),
89
- typed && plugin.options.version === "3" && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
90
- isTypeOnly: true,
91
- path: "@kubb/plugin-zod/utils",
92
- name: ["ToZod"]
93
- }),
94
- imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
95
- root: file.path,
96
- path: imp.path,
97
- name: imp.name
98
- }, [
99
- imp.path,
100
- imp.name,
101
- imp.isTypeOnly
102
- ].join("-"))),
103
- /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Zod, {
104
- name: zod.name,
105
- typeName: typed ? type.name : void 0,
106
- inferTypeName: inferred ? zod.inferTypeName : void 0,
107
- description,
108
- tree,
109
- rawSchema: schemaObject,
110
- mapper,
111
- coercion,
112
- keysToOmit,
113
- wrapOutput,
114
- version: plugin.options.version,
115
- emptySchemaType: plugin.options.emptySchemaType
116
- })
117
- ]
118
- }, i);
140
+ return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.Fragment, { children: [
141
+ typed && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
142
+ isTypeOnly: true,
143
+ root: file.path,
144
+ path: type.file.path,
145
+ name: [type.name]
146
+ }),
147
+ typed && version === "3" && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
148
+ name: ["ToZod"],
149
+ root: file.path,
150
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/ToZod.ts")
151
+ }),
152
+ imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
153
+ root: file.path,
154
+ path: imp.path,
155
+ name: imp.name
156
+ }, [
157
+ imp.path,
158
+ imp.name,
159
+ imp.isTypeOnly
160
+ ].join("-"))),
161
+ /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Zod, {
162
+ name: zod.name,
163
+ typeName: typed ? type.name : void 0,
164
+ inferTypeName: inferred ? zod.inferTypeName : void 0,
165
+ description,
166
+ tree,
167
+ schema: schemaObject,
168
+ mapper,
169
+ coercion,
170
+ keysToOmit,
171
+ wrapOutput,
172
+ version: plugin.options.version,
173
+ emptySchemaType: plugin.options.emptySchemaType
174
+ })
175
+ ] });
119
176
  };
120
177
  return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.File, {
121
178
  baseName: file.baseName,
@@ -136,10 +193,9 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
136
193
  }), operationSchemas.map(mapOperationSchema)]
137
194
  });
138
195
  },
139
- Schema({ schema, options }) {
140
- const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options;
196
+ Schema({ config, schema, plugin }) {
141
197
  const { getName, getFile, getImports } = (0, __kubb_plugin_oas_hooks.useSchemaManager)();
142
- const { options: { output, emptySchemaType } } = (0, __kubb_core_hooks.usePlugin)();
198
+ const { options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version } } = plugin;
143
199
  const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
144
200
  const oas = (0, __kubb_plugin_oas_hooks.useOas)();
145
201
  const imports = getImports(schema.tree);
@@ -179,10 +235,10 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
179
235
  path: type.file.path,
180
236
  name: [type.name]
181
237
  }),
182
- typed && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
183
- isTypeOnly: true,
184
- path: options.version === "4" ? "@kubb/plugin-zod/utils/v4" : "@kubb/plugin-zod/utils",
185
- name: ["ToZod"]
238
+ typed && version === "3" && /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
239
+ name: ["ToZod"],
240
+ root: zod.file.path,
241
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/ToZod.ts")
186
242
  }),
187
243
  imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
188
244
  root: zod.file.path,
@@ -199,7 +255,7 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
199
255
  inferTypeName: inferred ? zod.inferTypeName : void 0,
200
256
  description: schema.value.description,
201
257
  tree: schema.tree,
202
- rawSchema: schema.value,
258
+ schema: schema.value,
203
259
  mapper,
204
260
  coercion,
205
261
  wrapOutput,
@@ -211,66 +267,6 @@ const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
211
267
  }
212
268
  });
213
269
 
214
- //#endregion
215
- //#region src/generators/operationsGenerator.tsx
216
- const operationsGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
217
- name: "operations",
218
- Operations({ operations }) {
219
- const { key: pluginKey, options: { output, importPath } } = (0, __kubb_core_hooks.usePlugin)();
220
- const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
221
- const oas = (0, __kubb_plugin_oas_hooks.useOas)();
222
- const { getFile, groupSchemasByName } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
223
- const name = "operations";
224
- const file = pluginManager.getFile({
225
- name,
226
- extname: ".ts",
227
- pluginKey
228
- });
229
- const transformedOperations = operations.map((operation) => ({
230
- operation,
231
- data: groupSchemasByName(operation, { type: "function" })
232
- }));
233
- const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
234
- const names = [
235
- data.request,
236
- ...Object.values(data.responses),
237
- ...Object.values(data.parameters)
238
- ].filter(Boolean);
239
- return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
240
- name: names,
241
- root: file.path,
242
- path: getFile(operation).path
243
- }, key);
244
- }).filter(Boolean);
245
- return /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsxs)(__kubb_react_fabric.File, {
246
- baseName: file.baseName,
247
- path: file.path,
248
- meta: file.meta,
249
- banner: (0, __kubb_plugin_oas_utils.getBanner)({
250
- oas,
251
- output,
252
- config: pluginManager.config
253
- }),
254
- footer: (0, __kubb_plugin_oas_utils.getFooter)({
255
- oas,
256
- output
257
- }),
258
- children: [
259
- /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(__kubb_react_fabric.File.Import, {
260
- isTypeOnly: true,
261
- name: ["z"],
262
- path: importPath
263
- }),
264
- imports,
265
- /* @__PURE__ */ (0, __kubb_react_fabric_jsx_runtime.jsx)(require_components.Operations, {
266
- name,
267
- operations: transformedOperations
268
- })
269
- ]
270
- });
271
- }
272
- });
273
-
274
270
  //#endregion
275
271
  Object.defineProperty(exports, 'operationsGenerator', {
276
272
  enumerable: true,
@@ -284,4 +280,4 @@ Object.defineProperty(exports, 'zodGenerator', {
284
280
  return zodGenerator;
285
281
  }
286
282
  });
287
- //# sourceMappingURL=generators-B2hD7k6l.cjs.map
283
+ //# sourceMappingURL=generators-BOldMlBb.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators-BOldMlBb.cjs","names":["File","Operations","SchemaGenerator","options","schemaKeywords","pluginTsName","Fragment","File","path","Zod"],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File } from '@kubb/react-fabric'\nimport { Operations } from '../components/Operations.tsx'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations, generator, plugin }) {\n const {\n key: pluginKey,\n options: { output, importPath },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\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\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={['z']} path={importPath} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useMode, usePluginManager } from '@kubb/core/hooks'\nimport { type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, Fragment } from '@kubb/react-fabric'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ config, operation, generator, plugin }) {\n const {\n options,\n options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version },\n } = plugin\n\n const mode = useMode()\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = useOperationManager(generator)\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n fabric: generator.context.fabric,\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: schemaObject, description, keysToOmit, ...options }: OperationSchemaType) => {\n const hasProperties = Object.keys(schemaObject || {}).length > 0\n const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, 'default'))\n\n const required = Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required\n const optional = !required && !hasDefaults && hasProperties && name.includes('Params')\n\n if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) {\n schemaObject.required = Object.entries(schemaObject.properties || {})\n .filter(([_key, value]) => value && Object.hasOwn(value, 'default'))\n .map(([key]) => key)\n }\n\n const tree = [...schemaGenerator.parse({ schemaObject, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n const group = options.operation ? getGroup(options.operation) : undefined\n\n const coercion = name.includes('Params') ? { numbers: true, strings: false, dates: true } : globalCoercion\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, {\n type: 'type',\n pluginKey: [pluginTsName],\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginKey: [pluginTsName],\n group,\n }),\n }\n\n return (\n <Fragment>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} root={file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} 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 schema={schemaObject}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n wrapOutput={wrapOutput}\n version={plugin.options.version}\n emptySchemaType={plugin.options.emptySchemaType}\n />\n </Fragment>\n )\n }\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output, config: pluginManager.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version },\n } = plugin\n const pluginManager = usePluginManager()\n const oas = useOas()\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\n baseName={zod.file.baseName}\n path={zod.file.path}\n meta={zod.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && (\n <File.Import name={['ToZod']} root={zod.file.path} path={path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')} />\n )}\n {imports.map((imp) => (\n <File.Import key={[imp.path, imp.name, imp.isTypeOnly].join('-')} 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 schema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAQA,MAAa,6EAAsD;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,KAAK,WACL,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,yDAAkC;EAExC,MAAM,2CA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K;KAA4D,MAAM,IAAI,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;OAA/F;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAAyD,CACzH;IAEF,yDAACE;KACC,MAAM,IAAI;KACV,UAAU,QAAQ,KAAK,OAAO;KAC9B,eAAe,WAAW,IAAI,gBAAgB;KAC9C,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACQ;MACjB;;IACG;;CAGZ,CAAC"}
@@ -1,28 +1,88 @@
1
- import { n as Operations, t as Zod } from "./components-DUJ6Xkpc.js";
2
- import { SchemaGenerator, createReactGenerator, schemaKeywords } from "@kubb/plugin-oas";
1
+ import { n as Operations, t as Zod } from "./components-BtBB23cQ.js";
2
+ import path from "node:path";
3
+ import { SchemaGenerator, schemaKeywords } from "@kubb/plugin-oas";
3
4
  import { pluginTsName } from "@kubb/plugin-ts";
4
- import { useMode, usePlugin, usePluginManager } from "@kubb/core/hooks";
5
- import { Oas } from "@kubb/plugin-oas/components";
5
+ import { useMode, usePluginManager } from "@kubb/core/hooks";
6
+ import { createReactGenerator } from "@kubb/plugin-oas/generators";
6
7
  import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
7
8
  import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
8
- import { File } from "@kubb/react-fabric";
9
+ import { File, Fragment } from "@kubb/react-fabric";
9
10
  import { jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
10
11
 
12
+ //#region src/generators/operationsGenerator.tsx
13
+ const operationsGenerator = createReactGenerator({
14
+ name: "operations",
15
+ Operations({ operations, generator, plugin }) {
16
+ const { key: pluginKey, options: { output, importPath } } = plugin;
17
+ const pluginManager = usePluginManager();
18
+ const oas = useOas();
19
+ const { getFile, groupSchemasByName } = useOperationManager(generator);
20
+ const name = "operations";
21
+ const file = pluginManager.getFile({
22
+ name,
23
+ extname: ".ts",
24
+ pluginKey
25
+ });
26
+ const transformedOperations = operations.map((operation) => ({
27
+ operation,
28
+ data: groupSchemasByName(operation, { type: "function" })
29
+ }));
30
+ const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
31
+ const names = [
32
+ data.request,
33
+ ...Object.values(data.responses),
34
+ ...Object.values(data.parameters)
35
+ ].filter(Boolean);
36
+ return /* @__PURE__ */ jsx(File.Import, {
37
+ name: names,
38
+ root: file.path,
39
+ path: getFile(operation).path
40
+ }, key);
41
+ }).filter(Boolean);
42
+ return /* @__PURE__ */ jsxs(File, {
43
+ baseName: file.baseName,
44
+ path: file.path,
45
+ meta: file.meta,
46
+ banner: getBanner({
47
+ oas,
48
+ output,
49
+ config: pluginManager.config
50
+ }),
51
+ footer: getFooter({
52
+ oas,
53
+ output
54
+ }),
55
+ children: [
56
+ /* @__PURE__ */ jsx(File.Import, {
57
+ isTypeOnly: true,
58
+ name: ["z"],
59
+ path: importPath
60
+ }),
61
+ imports,
62
+ /* @__PURE__ */ jsx(Operations, {
63
+ name,
64
+ operations: transformedOperations
65
+ })
66
+ ]
67
+ });
68
+ }
69
+ });
70
+
71
+ //#endregion
11
72
  //#region src/generators/zodGenerator.tsx
12
73
  const zodGenerator = createReactGenerator({
13
74
  name: "zod",
14
- Operation({ operation, options, instance }) {
15
- const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options;
16
- const plugin = usePlugin();
75
+ Operation({ config, operation, generator, plugin }) {
76
+ const { options, options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version } } = plugin;
17
77
  const mode = useMode();
18
78
  const pluginManager = usePluginManager();
19
79
  const oas = useOas();
20
- const { getSchemas, getFile, getGroup } = useOperationManager();
80
+ const { getSchemas, getFile, getGroup } = useOperationManager(generator);
21
81
  const schemaManager = useSchemaManager();
22
82
  const file = getFile(operation);
23
83
  const schemas = getSchemas(operation);
24
84
  const schemaGenerator = new SchemaGenerator(options, {
25
- fabric: instance.context.fabric,
85
+ fabric: generator.context.fabric,
26
86
  oas,
27
87
  plugin,
28
88
  pluginManager,
@@ -37,10 +97,11 @@ const zodGenerator = createReactGenerator({
37
97
  schemas.request,
38
98
  schemas.response
39
99
  ].flat().filter(Boolean);
40
- const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }, i) => {
41
- const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
42
- const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, "default") && property.default !== void 0);
43
- const optional = !required && !someDefaults && name.includes("Params");
100
+ const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }) => {
101
+ const hasProperties = Object.keys(schemaObject || {}).length > 0;
102
+ const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, "default"));
103
+ const optional = !(Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required) && !hasDefaults && hasProperties && name.includes("Params");
104
+ if (!optional && Array.isArray(schemaObject.required) && !schemaObject.required.length) schemaObject.required = Object.entries(schemaObject.properties || {}).filter(([_key, value]) => value && Object.hasOwn(value, "default")).map(([key]) => key);
44
105
  const tree = [...schemaGenerator.parse({
45
106
  schemaObject,
46
107
  name
@@ -67,47 +128,42 @@ const zodGenerator = createReactGenerator({
67
128
  group
68
129
  })
69
130
  };
70
- return /* @__PURE__ */ jsxs(Oas.Schema, {
71
- name,
72
- schemaObject,
73
- tree,
74
- children: [
75
- typed && /* @__PURE__ */ jsx(File.Import, {
76
- isTypeOnly: true,
77
- root: file.path,
78
- path: type.file.path,
79
- name: [type.name]
80
- }),
81
- typed && plugin.options.version === "3" && /* @__PURE__ */ jsx(File.Import, {
82
- isTypeOnly: true,
83
- path: "@kubb/plugin-zod/utils",
84
- name: ["ToZod"]
85
- }),
86
- imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
87
- root: file.path,
88
- path: imp.path,
89
- name: imp.name
90
- }, [
91
- imp.path,
92
- imp.name,
93
- imp.isTypeOnly
94
- ].join("-"))),
95
- /* @__PURE__ */ jsx(Zod, {
96
- name: zod.name,
97
- typeName: typed ? type.name : void 0,
98
- inferTypeName: inferred ? zod.inferTypeName : void 0,
99
- description,
100
- tree,
101
- rawSchema: schemaObject,
102
- mapper,
103
- coercion,
104
- keysToOmit,
105
- wrapOutput,
106
- version: plugin.options.version,
107
- emptySchemaType: plugin.options.emptySchemaType
108
- })
109
- ]
110
- }, i);
131
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
132
+ typed && /* @__PURE__ */ jsx(File.Import, {
133
+ isTypeOnly: true,
134
+ root: file.path,
135
+ path: type.file.path,
136
+ name: [type.name]
137
+ }),
138
+ typed && version === "3" && /* @__PURE__ */ jsx(File.Import, {
139
+ name: ["ToZod"],
140
+ root: file.path,
141
+ path: path.resolve(config.root, config.output.path, ".kubb/ToZod.ts")
142
+ }),
143
+ imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
144
+ root: file.path,
145
+ path: imp.path,
146
+ name: imp.name
147
+ }, [
148
+ imp.path,
149
+ imp.name,
150
+ imp.isTypeOnly
151
+ ].join("-"))),
152
+ /* @__PURE__ */ jsx(Zod, {
153
+ name: zod.name,
154
+ typeName: typed ? type.name : void 0,
155
+ inferTypeName: inferred ? zod.inferTypeName : void 0,
156
+ description,
157
+ tree,
158
+ schema: schemaObject,
159
+ mapper,
160
+ coercion,
161
+ keysToOmit,
162
+ wrapOutput,
163
+ version: plugin.options.version,
164
+ emptySchemaType: plugin.options.emptySchemaType
165
+ })
166
+ ] });
111
167
  };
112
168
  return /* @__PURE__ */ jsxs(File, {
113
169
  baseName: file.baseName,
@@ -128,10 +184,9 @@ const zodGenerator = createReactGenerator({
128
184
  }), operationSchemas.map(mapOperationSchema)]
129
185
  });
130
186
  },
131
- Schema({ schema, options }) {
132
- const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options;
187
+ Schema({ config, schema, plugin }) {
133
188
  const { getName, getFile, getImports } = useSchemaManager();
134
- const { options: { output, emptySchemaType } } = usePlugin();
189
+ const { options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version } } = plugin;
135
190
  const pluginManager = usePluginManager();
136
191
  const oas = useOas();
137
192
  const imports = getImports(schema.tree);
@@ -171,10 +226,10 @@ const zodGenerator = createReactGenerator({
171
226
  path: type.file.path,
172
227
  name: [type.name]
173
228
  }),
174
- typed && /* @__PURE__ */ jsx(File.Import, {
175
- isTypeOnly: true,
176
- path: options.version === "4" ? "@kubb/plugin-zod/utils/v4" : "@kubb/plugin-zod/utils",
177
- name: ["ToZod"]
229
+ typed && version === "3" && /* @__PURE__ */ jsx(File.Import, {
230
+ name: ["ToZod"],
231
+ root: zod.file.path,
232
+ path: path.resolve(config.root, config.output.path, ".kubb/ToZod.ts")
178
233
  }),
179
234
  imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
180
235
  root: zod.file.path,
@@ -191,7 +246,7 @@ const zodGenerator = createReactGenerator({
191
246
  inferTypeName: inferred ? zod.inferTypeName : void 0,
192
247
  description: schema.value.description,
193
248
  tree: schema.tree,
194
- rawSchema: schema.value,
249
+ schema: schema.value,
195
250
  mapper,
196
251
  coercion,
197
252
  wrapOutput,
@@ -204,65 +259,5 @@ const zodGenerator = createReactGenerator({
204
259
  });
205
260
 
206
261
  //#endregion
207
- //#region src/generators/operationsGenerator.tsx
208
- const operationsGenerator = createReactGenerator({
209
- name: "operations",
210
- Operations({ operations }) {
211
- const { key: pluginKey, options: { output, importPath } } = usePlugin();
212
- const pluginManager = usePluginManager();
213
- const oas = useOas();
214
- const { getFile, groupSchemasByName } = useOperationManager();
215
- const name = "operations";
216
- const file = pluginManager.getFile({
217
- name,
218
- extname: ".ts",
219
- pluginKey
220
- });
221
- const transformedOperations = operations.map((operation) => ({
222
- operation,
223
- data: groupSchemasByName(operation, { type: "function" })
224
- }));
225
- const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
226
- const names = [
227
- data.request,
228
- ...Object.values(data.responses),
229
- ...Object.values(data.parameters)
230
- ].filter(Boolean);
231
- return /* @__PURE__ */ jsx(File.Import, {
232
- name: names,
233
- root: file.path,
234
- path: getFile(operation).path
235
- }, key);
236
- }).filter(Boolean);
237
- return /* @__PURE__ */ jsxs(File, {
238
- baseName: file.baseName,
239
- path: file.path,
240
- meta: file.meta,
241
- banner: getBanner({
242
- oas,
243
- output,
244
- config: pluginManager.config
245
- }),
246
- footer: getFooter({
247
- oas,
248
- output
249
- }),
250
- children: [
251
- /* @__PURE__ */ jsx(File.Import, {
252
- isTypeOnly: true,
253
- name: ["z"],
254
- path: importPath
255
- }),
256
- imports,
257
- /* @__PURE__ */ jsx(Operations, {
258
- name,
259
- operations: transformedOperations
260
- })
261
- ]
262
- });
263
- }
264
- });
265
-
266
- //#endregion
267
- export { zodGenerator as n, operationsGenerator as t };
268
- //# sourceMappingURL=generators-CwEOtNXG.js.map
262
+ export { operationsGenerator as n, zodGenerator as t };
263
+ //# sourceMappingURL=generators-DpdxKqO8.js.map