@kubb/plugin-zod 3.16.2 → 3.16.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.
- package/dist/components-CJ6RN1R2.js +414 -0
- package/dist/components-CJ6RN1R2.js.map +1 -0
- package/dist/components-GvkeO2ig.cjs +454 -0
- package/dist/components-GvkeO2ig.cjs.map +1 -0
- package/dist/components.cjs +3 -15
- package/dist/components.d.cts +56 -26
- package/dist/components.d.ts +56 -26
- package/dist/components.js +3 -3
- package/dist/generators-B13NknOz.cjs +265 -0
- package/dist/generators-B13NknOz.cjs.map +1 -0
- package/dist/generators-DcUZYcq0.js +254 -0
- package/dist/generators-DcUZYcq0.js.map +1 -0
- package/dist/generators.cjs +4 -16
- package/dist/generators.d.cts +8 -8
- package/dist/generators.d.ts +8 -8
- package/dist/generators.js +4 -4
- package/dist/index.cjs +103 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +103 -131
- package/dist/index.js.map +1 -1
- package/dist/types-B0UqdcbG.d.cts +1237 -0
- package/dist/types-YpNWeJUW.d.ts +1237 -0
- package/dist/utils.cjs +0 -4
- package/dist/utils.d.cts +18 -24
- package/dist/utils.d.ts +18 -24
- package/dist/utils.js +1 -3
- package/package.json +24 -30
- package/dist/chunk-4QMHDKCS.js +0 -453
- package/dist/chunk-4QMHDKCS.js.map +0 -1
- package/dist/chunk-6LDDO2JJ.cjs +0 -184
- package/dist/chunk-6LDDO2JJ.cjs.map +0 -1
- package/dist/chunk-FYI4GRXP.cjs +0 -460
- package/dist/chunk-FYI4GRXP.cjs.map +0 -1
- package/dist/chunk-I74P26CO.js +0 -181
- package/dist/chunk-I74P26CO.js.map +0 -1
- package/dist/components.cjs.map +0 -1
- package/dist/components.js.map +0 -1
- package/dist/generators.cjs.map +0 -1
- package/dist/generators.js.map +0 -1
- package/dist/types-BOF1ntMm.d.cts +0 -130
- package/dist/types-BOF1ntMm.d.ts +0 -130
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.js.map +0 -1
package/dist/components.d.ts
CHANGED
|
@@ -1,32 +1,62 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Operation, SchemaObject } from '@kubb/oas';
|
|
3
|
-
import { Schema } from '@kubb/plugin-oas';
|
|
4
|
-
import { P as PluginZod } from './types-BOF1ntMm.js';
|
|
5
|
-
import '@kubb/core';
|
|
1
|
+
import { Operation, PluginZod, Schema, SchemaObject } from "./types-YpNWeJUW.js";
|
|
6
2
|
|
|
3
|
+
//#region ../plugin-oas/src/hooks/useOperationManager.d.ts
|
|
4
|
+
|
|
5
|
+
type SchemaNames = {
|
|
6
|
+
request: string | undefined;
|
|
7
|
+
parameters: {
|
|
8
|
+
path: string | undefined;
|
|
9
|
+
query: string | undefined;
|
|
10
|
+
header: string | undefined;
|
|
11
|
+
};
|
|
12
|
+
responses: {
|
|
13
|
+
default?: string;
|
|
14
|
+
} & Record<number | string, string>;
|
|
15
|
+
errors: Record<number | string, string>;
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/components/Operations.d.ts
|
|
7
19
|
type Props$1 = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
name: string;
|
|
21
|
+
operations: Array<{
|
|
22
|
+
operation: Operation;
|
|
23
|
+
data: SchemaNames;
|
|
24
|
+
}>;
|
|
13
25
|
};
|
|
14
|
-
declare function Operations({
|
|
15
|
-
|
|
26
|
+
declare function Operations({
|
|
27
|
+
name,
|
|
28
|
+
operations
|
|
29
|
+
}: Props$1): any;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/components/Zod.d.ts
|
|
16
32
|
type Props = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
name: string;
|
|
34
|
+
typeName?: string;
|
|
35
|
+
inferTypeName?: string;
|
|
36
|
+
tree: Array<Schema>;
|
|
37
|
+
rawSchema: SchemaObject;
|
|
38
|
+
description?: string;
|
|
39
|
+
coercion: PluginZod['resolvedOptions']['coercion'];
|
|
40
|
+
mapper: PluginZod['resolvedOptions']['mapper'];
|
|
41
|
+
keysToOmit?: string[];
|
|
42
|
+
wrapOutput?: PluginZod['resolvedOptions']['wrapOutput'];
|
|
43
|
+
version: '3' | '4';
|
|
44
|
+
emptySchemaType: PluginZod['resolvedOptions']['emptySchemaType'];
|
|
29
45
|
};
|
|
30
|
-
declare function Zod({
|
|
31
|
-
|
|
46
|
+
declare function Zod({
|
|
47
|
+
name,
|
|
48
|
+
typeName,
|
|
49
|
+
tree,
|
|
50
|
+
rawSchema,
|
|
51
|
+
inferTypeName,
|
|
52
|
+
mapper,
|
|
53
|
+
coercion,
|
|
54
|
+
keysToOmit,
|
|
55
|
+
description,
|
|
56
|
+
wrapOutput,
|
|
57
|
+
version,
|
|
58
|
+
emptySchemaType
|
|
59
|
+
}: Props): any;
|
|
60
|
+
//#endregion
|
|
32
61
|
export { Operations, Zod };
|
|
62
|
+
//# sourceMappingURL=components.d.ts.map
|
package/dist/components.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Operations, Zod } from "./components-CJ6RN1R2.js";
|
|
2
|
+
|
|
3
|
+
export { Operations, Zod };
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
const require_components = require('./components-GvkeO2ig.cjs');
|
|
2
|
+
const __kubb_plugin_oas = require_components.__toESM(require("@kubb/plugin-oas"));
|
|
3
|
+
const __kubb_plugin_ts = require_components.__toESM(require("@kubb/plugin-ts"));
|
|
4
|
+
const __kubb_plugin_oas_components = require_components.__toESM(require("@kubb/plugin-oas/components"));
|
|
5
|
+
const __kubb_plugin_oas_hooks = require_components.__toESM(require("@kubb/plugin-oas/hooks"));
|
|
6
|
+
const __kubb_plugin_oas_utils = require_components.__toESM(require("@kubb/plugin-oas/utils"));
|
|
7
|
+
const __kubb_react = require_components.__toESM(require("@kubb/react"));
|
|
8
|
+
const __kubb_react_jsx_runtime = require_components.__toESM(require("@kubb/react/jsx-runtime"));
|
|
9
|
+
|
|
10
|
+
//#region src/generators/zodGenerator.tsx
|
|
11
|
+
const zodGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
12
|
+
name: "zod",
|
|
13
|
+
Operation({ operation, options }) {
|
|
14
|
+
const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options;
|
|
15
|
+
const { plugin, pluginManager, mode } = (0, __kubb_react.useApp)();
|
|
16
|
+
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
17
|
+
const { getSchemas, getFile, getGroup } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
18
|
+
const schemaManager = (0, __kubb_plugin_oas_hooks.useSchemaManager)();
|
|
19
|
+
const file = getFile(operation);
|
|
20
|
+
const schemas = getSchemas(operation);
|
|
21
|
+
const schemaGenerator = new __kubb_plugin_oas.SchemaGenerator(options, {
|
|
22
|
+
oas,
|
|
23
|
+
plugin,
|
|
24
|
+
pluginManager,
|
|
25
|
+
mode,
|
|
26
|
+
override: options.override
|
|
27
|
+
});
|
|
28
|
+
const operationSchemas = [
|
|
29
|
+
schemas.pathParams,
|
|
30
|
+
schemas.queryParams,
|
|
31
|
+
schemas.headerParams,
|
|
32
|
+
schemas.statusCodes,
|
|
33
|
+
schemas.request,
|
|
34
|
+
schemas.response
|
|
35
|
+
].flat().filter(Boolean);
|
|
36
|
+
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }, i) => {
|
|
37
|
+
const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
|
|
38
|
+
const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, "default") && property.default !== void 0);
|
|
39
|
+
const optional = !required && !someDefaults && name.includes("Params");
|
|
40
|
+
const tree = [...schemaGenerator.parse({
|
|
41
|
+
schemaObject,
|
|
42
|
+
name
|
|
43
|
+
}), optional ? { keyword: __kubb_plugin_oas.schemaKeywords.optional } : void 0].filter(Boolean);
|
|
44
|
+
const imports = schemaManager.getImports(tree);
|
|
45
|
+
const group = options$1.operation ? getGroup(options$1.operation) : void 0;
|
|
46
|
+
const coercion = name.includes("Params") ? {
|
|
47
|
+
numbers: true,
|
|
48
|
+
strings: false,
|
|
49
|
+
dates: true
|
|
50
|
+
} : globalCoercion;
|
|
51
|
+
const zod = {
|
|
52
|
+
name: schemaManager.getName(name, { type: "function" }),
|
|
53
|
+
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
54
|
+
file: schemaManager.getFile(name)
|
|
55
|
+
};
|
|
56
|
+
const type = {
|
|
57
|
+
name: schemaManager.getName(name, {
|
|
58
|
+
type: "type",
|
|
59
|
+
pluginKey: [__kubb_plugin_ts.pluginTsName]
|
|
60
|
+
}),
|
|
61
|
+
file: schemaManager.getFile(options$1.operationName || name, {
|
|
62
|
+
pluginKey: [__kubb_plugin_ts.pluginTsName],
|
|
63
|
+
group
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_plugin_oas_components.Oas.Schema, {
|
|
67
|
+
name,
|
|
68
|
+
schemaObject,
|
|
69
|
+
tree,
|
|
70
|
+
children: [
|
|
71
|
+
typed && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
72
|
+
isTypeOnly: true,
|
|
73
|
+
root: file.path,
|
|
74
|
+
path: type.file.path,
|
|
75
|
+
name: [type.name]
|
|
76
|
+
}),
|
|
77
|
+
typed && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
78
|
+
isTypeOnly: true,
|
|
79
|
+
path: "@kubb/plugin-zod/utils",
|
|
80
|
+
name: ["ToZod"]
|
|
81
|
+
}),
|
|
82
|
+
imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
83
|
+
root: file.path,
|
|
84
|
+
path: imp.path,
|
|
85
|
+
name: imp.name
|
|
86
|
+
}, [
|
|
87
|
+
imp.path,
|
|
88
|
+
imp.name,
|
|
89
|
+
imp.isTypeOnly
|
|
90
|
+
].join("-"))),
|
|
91
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Zod, {
|
|
92
|
+
name: zod.name,
|
|
93
|
+
typeName: typed ? type.name : void 0,
|
|
94
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
95
|
+
description,
|
|
96
|
+
tree,
|
|
97
|
+
rawSchema: schemaObject,
|
|
98
|
+
mapper,
|
|
99
|
+
coercion,
|
|
100
|
+
keysToOmit,
|
|
101
|
+
wrapOutput,
|
|
102
|
+
version: plugin.options.version,
|
|
103
|
+
emptySchemaType: plugin.options.emptySchemaType
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
}, i);
|
|
107
|
+
};
|
|
108
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
109
|
+
baseName: file.baseName,
|
|
110
|
+
path: file.path,
|
|
111
|
+
meta: file.meta,
|
|
112
|
+
banner: (0, __kubb_plugin_oas_utils.getBanner)({
|
|
113
|
+
oas,
|
|
114
|
+
output: plugin.options.output,
|
|
115
|
+
config: pluginManager.config
|
|
116
|
+
}),
|
|
117
|
+
footer: (0, __kubb_plugin_oas_utils.getFooter)({
|
|
118
|
+
oas,
|
|
119
|
+
output: plugin.options.output
|
|
120
|
+
}),
|
|
121
|
+
children: [/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
122
|
+
name: ["z"],
|
|
123
|
+
path: plugin.options.importPath
|
|
124
|
+
}), operationSchemas.map(mapOperationSchema)]
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
Schema({ schema, options }) {
|
|
128
|
+
const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options;
|
|
129
|
+
const { getName, getFile, getImports } = (0, __kubb_plugin_oas_hooks.useSchemaManager)();
|
|
130
|
+
const { pluginManager, plugin: { options: { output, emptySchemaType } } } = (0, __kubb_react.useApp)();
|
|
131
|
+
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
132
|
+
const imports = getImports(schema.tree);
|
|
133
|
+
const zod = {
|
|
134
|
+
name: getName(schema.name, { type: "function" }),
|
|
135
|
+
inferTypeName: getName(schema.name, { type: "type" }),
|
|
136
|
+
file: getFile(schema.name)
|
|
137
|
+
};
|
|
138
|
+
const type = {
|
|
139
|
+
name: getName(schema.name, {
|
|
140
|
+
type: "type",
|
|
141
|
+
pluginKey: [__kubb_plugin_ts.pluginTsName]
|
|
142
|
+
}),
|
|
143
|
+
file: getFile(schema.name, { pluginKey: [__kubb_plugin_ts.pluginTsName] })
|
|
144
|
+
};
|
|
145
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
146
|
+
baseName: zod.file.baseName,
|
|
147
|
+
path: zod.file.path,
|
|
148
|
+
meta: zod.file.meta,
|
|
149
|
+
banner: (0, __kubb_plugin_oas_utils.getBanner)({
|
|
150
|
+
oas,
|
|
151
|
+
output,
|
|
152
|
+
config: pluginManager.config
|
|
153
|
+
}),
|
|
154
|
+
footer: (0, __kubb_plugin_oas_utils.getFooter)({
|
|
155
|
+
oas,
|
|
156
|
+
output
|
|
157
|
+
}),
|
|
158
|
+
children: [
|
|
159
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
160
|
+
name: ["z"],
|
|
161
|
+
path: importPath
|
|
162
|
+
}),
|
|
163
|
+
typed && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
164
|
+
isTypeOnly: true,
|
|
165
|
+
root: zod.file.path,
|
|
166
|
+
path: type.file.path,
|
|
167
|
+
name: [type.name]
|
|
168
|
+
}),
|
|
169
|
+
typed && /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
170
|
+
isTypeOnly: true,
|
|
171
|
+
path: "@kubb/plugin-zod/utils",
|
|
172
|
+
name: ["ToZod"]
|
|
173
|
+
}),
|
|
174
|
+
imports.map((imp) => /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
175
|
+
root: zod.file.path,
|
|
176
|
+
path: imp.path,
|
|
177
|
+
name: imp.name
|
|
178
|
+
}, [
|
|
179
|
+
imp.path,
|
|
180
|
+
imp.name,
|
|
181
|
+
imp.isTypeOnly
|
|
182
|
+
].join("-"))),
|
|
183
|
+
/* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Zod, {
|
|
184
|
+
name: zod.name,
|
|
185
|
+
typeName: typed ? type.name : void 0,
|
|
186
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
187
|
+
description: schema.value.description,
|
|
188
|
+
tree: schema.tree,
|
|
189
|
+
rawSchema: schema.value,
|
|
190
|
+
mapper,
|
|
191
|
+
coercion,
|
|
192
|
+
wrapOutput,
|
|
193
|
+
version,
|
|
194
|
+
emptySchemaType
|
|
195
|
+
})
|
|
196
|
+
]
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/generators/operationsGenerator.tsx
|
|
203
|
+
const operationsGenerator = (0, __kubb_plugin_oas.createReactGenerator)({
|
|
204
|
+
name: "operations",
|
|
205
|
+
Operations({ operations }) {
|
|
206
|
+
const { pluginManager, plugin: { key: pluginKey, options: { output } } } = (0, __kubb_react.useApp)();
|
|
207
|
+
const oas = (0, __kubb_plugin_oas_hooks.useOas)();
|
|
208
|
+
const { getFile, groupSchemasByName } = (0, __kubb_plugin_oas_hooks.useOperationManager)();
|
|
209
|
+
const name = "operations";
|
|
210
|
+
const file = pluginManager.getFile({
|
|
211
|
+
name,
|
|
212
|
+
extname: ".ts",
|
|
213
|
+
pluginKey
|
|
214
|
+
});
|
|
215
|
+
const transformedOperations = operations.map((operation) => ({
|
|
216
|
+
operation,
|
|
217
|
+
data: groupSchemasByName(operation, { type: "function" })
|
|
218
|
+
}));
|
|
219
|
+
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
220
|
+
const names = [
|
|
221
|
+
data.request,
|
|
222
|
+
...Object.values(data.responses),
|
|
223
|
+
...Object.values(data.parameters)
|
|
224
|
+
].filter(Boolean);
|
|
225
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.File.Import, {
|
|
226
|
+
name: names,
|
|
227
|
+
root: file.path,
|
|
228
|
+
path: getFile(operation).path
|
|
229
|
+
}, key);
|
|
230
|
+
}).filter(Boolean);
|
|
231
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsxs)(__kubb_react.File, {
|
|
232
|
+
baseName: file.baseName,
|
|
233
|
+
path: file.path,
|
|
234
|
+
meta: file.meta,
|
|
235
|
+
banner: (0, __kubb_plugin_oas_utils.getBanner)({
|
|
236
|
+
oas,
|
|
237
|
+
output,
|
|
238
|
+
config: pluginManager.config
|
|
239
|
+
}),
|
|
240
|
+
footer: (0, __kubb_plugin_oas_utils.getFooter)({
|
|
241
|
+
oas,
|
|
242
|
+
output
|
|
243
|
+
}),
|
|
244
|
+
children: [imports, /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_components.Operations, {
|
|
245
|
+
name,
|
|
246
|
+
operations: transformedOperations
|
|
247
|
+
})]
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
Object.defineProperty(exports, 'operationsGenerator', {
|
|
254
|
+
enumerable: true,
|
|
255
|
+
get: function () {
|
|
256
|
+
return operationsGenerator;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
Object.defineProperty(exports, 'zodGenerator', {
|
|
260
|
+
enumerable: true,
|
|
261
|
+
get: function () {
|
|
262
|
+
return zodGenerator;
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
//# sourceMappingURL=generators-B13NknOz.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-B13NknOz.cjs","names":["SchemaGenerator","options","i: number","schemaKeywords","pluginTsName","Oas","File","Zod","File","Operations"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\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, 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: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = 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: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\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 <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={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 </Oas.Schema>\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({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\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 && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\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 {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AASA,MAAa,2DAA+C;CAC1D,MAAM;CACN,UAAU,EAAE,WAAW,SAAS,EAAE;EAChC,MAAM,EAAE,UAAU,gBAAgB,UAAU,OAAO,QAAQ,YAAY,GAAG;EAE1E,MAAM,EAAE,QAAQ,eAAe,MAAM,6BAAsB;EAC3D,MAAM,2CAAc;EACpB,MAAM,EAAE,YAAY,SAAS,UAAU,qDAAwB;EAC/D,MAAM,+DAAkC;EAExC,MAAM,OAAO,QAAQ,UAAU;EAC/B,MAAM,UAAU,WAAW,UAAU;EACrC,MAAM,kBAAkB,IAAIA,kCAAgB,SAAS;GACnD;GACA;GACA;GACA;GACA,UAAU,QAAQ;EACnB;EAED,MAAM,mBAAmB;GAAC,QAAQ;GAAY,QAAQ;GAAa,QAAQ;GAAc,QAAQ;GAAa,QAAQ;GAAS,QAAQ;EAAS,EAC7I,MAAM,CACN,OAAO,QAAQ;EAElB,MAAM,qBAAqB,CAAC,EAAE,MAAM,QAAQ,cAAc,aAAa,WAAY,GAAGC,WAA8B,EAAEC,MAAc;GAElI,MAAM,WAAW,MAAM,QAAQ,cAAc,SAAS,GAAG,CAAC,CAAC,aAAa,SAAS,SAAS,CAAC,CAAC,cAAc;GAC1G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AAI,CAAC,CAAC,KAAK,EAAE,MAAM,WAAW,CAAC,KAAK;GACnC,MAAM,QAAQ;IAAC,KAAK;IAAS,GAAG,OAAO,OAAO,KAAK,UAAU;IAAE,GAAG,OAAO,OAAO,KAAK,WAAW;GAAC,EAAC,OAAO,QAAQ;AAEjH,4DAAQC,kBAAK;IAAiB,MAAM;IAAO,MAAM,KAAK;IAAM,MAAM,QAAQ,UAAU,CAAC;MAA5D,IAAoE;EAC9F,EAAC,CACD,OAAO,QAAQ;AAElB,4DACGA;GACC,UAAU,KAAK;GACf,MAAM,KAAK;GACX,MAAM,KAAK;GACX,+CAAkB;IAAE;IAAK;IAAQ,QAAQ,cAAc;GAAQ,EAAC;GAChE,+CAAkB;IAAE;IAAK;GAAQ,EAAC;cAEjC,2DACAC;IAAiB;IAAM,YAAY;KAAyB;IACxD;CAEV;AACF,EAAC"}
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { Operations, Zod } from "./components-CJ6RN1R2.js";
|
|
2
|
+
import { SchemaGenerator, createReactGenerator, schemaKeywords } from "@kubb/plugin-oas";
|
|
3
|
+
import { pluginTsName } from "@kubb/plugin-ts";
|
|
4
|
+
import { Oas } from "@kubb/plugin-oas/components";
|
|
5
|
+
import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
|
|
6
|
+
import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
|
|
7
|
+
import { File, useApp } from "@kubb/react";
|
|
8
|
+
import { jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
//#region src/generators/zodGenerator.tsx
|
|
11
|
+
const zodGenerator = createReactGenerator({
|
|
12
|
+
name: "zod",
|
|
13
|
+
Operation({ operation, options }) {
|
|
14
|
+
const { coercion: globalCoercion, inferred, typed, mapper, wrapOutput } = options;
|
|
15
|
+
const { plugin, pluginManager, mode } = useApp();
|
|
16
|
+
const oas = useOas();
|
|
17
|
+
const { getSchemas, getFile, getGroup } = useOperationManager();
|
|
18
|
+
const schemaManager = useSchemaManager();
|
|
19
|
+
const file = getFile(operation);
|
|
20
|
+
const schemas = getSchemas(operation);
|
|
21
|
+
const schemaGenerator = new SchemaGenerator(options, {
|
|
22
|
+
oas,
|
|
23
|
+
plugin,
|
|
24
|
+
pluginManager,
|
|
25
|
+
mode,
|
|
26
|
+
override: options.override
|
|
27
|
+
});
|
|
28
|
+
const operationSchemas = [
|
|
29
|
+
schemas.pathParams,
|
|
30
|
+
schemas.queryParams,
|
|
31
|
+
schemas.headerParams,
|
|
32
|
+
schemas.statusCodes,
|
|
33
|
+
schemas.request,
|
|
34
|
+
schemas.response
|
|
35
|
+
].flat().filter(Boolean);
|
|
36
|
+
const mapOperationSchema = ({ name, schema: schemaObject, description, keysToOmit,...options$1 }, i) => {
|
|
37
|
+
const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required;
|
|
38
|
+
const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, "default") && property.default !== void 0);
|
|
39
|
+
const optional = !required && !someDefaults && name.includes("Params");
|
|
40
|
+
const tree = [...schemaGenerator.parse({
|
|
41
|
+
schemaObject,
|
|
42
|
+
name
|
|
43
|
+
}), optional ? { keyword: schemaKeywords.optional } : void 0].filter(Boolean);
|
|
44
|
+
const imports = schemaManager.getImports(tree);
|
|
45
|
+
const group = options$1.operation ? getGroup(options$1.operation) : void 0;
|
|
46
|
+
const coercion = name.includes("Params") ? {
|
|
47
|
+
numbers: true,
|
|
48
|
+
strings: false,
|
|
49
|
+
dates: true
|
|
50
|
+
} : globalCoercion;
|
|
51
|
+
const zod = {
|
|
52
|
+
name: schemaManager.getName(name, { type: "function" }),
|
|
53
|
+
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
54
|
+
file: schemaManager.getFile(name)
|
|
55
|
+
};
|
|
56
|
+
const type = {
|
|
57
|
+
name: schemaManager.getName(name, {
|
|
58
|
+
type: "type",
|
|
59
|
+
pluginKey: [pluginTsName]
|
|
60
|
+
}),
|
|
61
|
+
file: schemaManager.getFile(options$1.operationName || name, {
|
|
62
|
+
pluginKey: [pluginTsName],
|
|
63
|
+
group
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
return /* @__PURE__ */ jsxs(Oas.Schema, {
|
|
67
|
+
name,
|
|
68
|
+
schemaObject,
|
|
69
|
+
tree,
|
|
70
|
+
children: [
|
|
71
|
+
typed && /* @__PURE__ */ jsx(File.Import, {
|
|
72
|
+
isTypeOnly: true,
|
|
73
|
+
root: file.path,
|
|
74
|
+
path: type.file.path,
|
|
75
|
+
name: [type.name]
|
|
76
|
+
}),
|
|
77
|
+
typed && /* @__PURE__ */ jsx(File.Import, {
|
|
78
|
+
isTypeOnly: true,
|
|
79
|
+
path: "@kubb/plugin-zod/utils",
|
|
80
|
+
name: ["ToZod"]
|
|
81
|
+
}),
|
|
82
|
+
imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
83
|
+
root: file.path,
|
|
84
|
+
path: imp.path,
|
|
85
|
+
name: imp.name
|
|
86
|
+
}, [
|
|
87
|
+
imp.path,
|
|
88
|
+
imp.name,
|
|
89
|
+
imp.isTypeOnly
|
|
90
|
+
].join("-"))),
|
|
91
|
+
/* @__PURE__ */ jsx(Zod, {
|
|
92
|
+
name: zod.name,
|
|
93
|
+
typeName: typed ? type.name : void 0,
|
|
94
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
95
|
+
description,
|
|
96
|
+
tree,
|
|
97
|
+
rawSchema: schemaObject,
|
|
98
|
+
mapper,
|
|
99
|
+
coercion,
|
|
100
|
+
keysToOmit,
|
|
101
|
+
wrapOutput,
|
|
102
|
+
version: plugin.options.version,
|
|
103
|
+
emptySchemaType: plugin.options.emptySchemaType
|
|
104
|
+
})
|
|
105
|
+
]
|
|
106
|
+
}, i);
|
|
107
|
+
};
|
|
108
|
+
return /* @__PURE__ */ jsxs(File, {
|
|
109
|
+
baseName: file.baseName,
|
|
110
|
+
path: file.path,
|
|
111
|
+
meta: file.meta,
|
|
112
|
+
banner: getBanner({
|
|
113
|
+
oas,
|
|
114
|
+
output: plugin.options.output,
|
|
115
|
+
config: pluginManager.config
|
|
116
|
+
}),
|
|
117
|
+
footer: getFooter({
|
|
118
|
+
oas,
|
|
119
|
+
output: plugin.options.output
|
|
120
|
+
}),
|
|
121
|
+
children: [/* @__PURE__ */ jsx(File.Import, {
|
|
122
|
+
name: ["z"],
|
|
123
|
+
path: plugin.options.importPath
|
|
124
|
+
}), operationSchemas.map(mapOperationSchema)]
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
Schema({ schema, options }) {
|
|
128
|
+
const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options;
|
|
129
|
+
const { getName, getFile, getImports } = useSchemaManager();
|
|
130
|
+
const { pluginManager, plugin: { options: { output, emptySchemaType } } } = useApp();
|
|
131
|
+
const oas = useOas();
|
|
132
|
+
const imports = getImports(schema.tree);
|
|
133
|
+
const zod = {
|
|
134
|
+
name: getName(schema.name, { type: "function" }),
|
|
135
|
+
inferTypeName: getName(schema.name, { type: "type" }),
|
|
136
|
+
file: getFile(schema.name)
|
|
137
|
+
};
|
|
138
|
+
const type = {
|
|
139
|
+
name: getName(schema.name, {
|
|
140
|
+
type: "type",
|
|
141
|
+
pluginKey: [pluginTsName]
|
|
142
|
+
}),
|
|
143
|
+
file: getFile(schema.name, { pluginKey: [pluginTsName] })
|
|
144
|
+
};
|
|
145
|
+
return /* @__PURE__ */ jsxs(File, {
|
|
146
|
+
baseName: zod.file.baseName,
|
|
147
|
+
path: zod.file.path,
|
|
148
|
+
meta: zod.file.meta,
|
|
149
|
+
banner: getBanner({
|
|
150
|
+
oas,
|
|
151
|
+
output,
|
|
152
|
+
config: pluginManager.config
|
|
153
|
+
}),
|
|
154
|
+
footer: getFooter({
|
|
155
|
+
oas,
|
|
156
|
+
output
|
|
157
|
+
}),
|
|
158
|
+
children: [
|
|
159
|
+
/* @__PURE__ */ jsx(File.Import, {
|
|
160
|
+
name: ["z"],
|
|
161
|
+
path: importPath
|
|
162
|
+
}),
|
|
163
|
+
typed && /* @__PURE__ */ jsx(File.Import, {
|
|
164
|
+
isTypeOnly: true,
|
|
165
|
+
root: zod.file.path,
|
|
166
|
+
path: type.file.path,
|
|
167
|
+
name: [type.name]
|
|
168
|
+
}),
|
|
169
|
+
typed && /* @__PURE__ */ jsx(File.Import, {
|
|
170
|
+
isTypeOnly: true,
|
|
171
|
+
path: "@kubb/plugin-zod/utils",
|
|
172
|
+
name: ["ToZod"]
|
|
173
|
+
}),
|
|
174
|
+
imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
175
|
+
root: zod.file.path,
|
|
176
|
+
path: imp.path,
|
|
177
|
+
name: imp.name
|
|
178
|
+
}, [
|
|
179
|
+
imp.path,
|
|
180
|
+
imp.name,
|
|
181
|
+
imp.isTypeOnly
|
|
182
|
+
].join("-"))),
|
|
183
|
+
/* @__PURE__ */ jsx(Zod, {
|
|
184
|
+
name: zod.name,
|
|
185
|
+
typeName: typed ? type.name : void 0,
|
|
186
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
187
|
+
description: schema.value.description,
|
|
188
|
+
tree: schema.tree,
|
|
189
|
+
rawSchema: schema.value,
|
|
190
|
+
mapper,
|
|
191
|
+
coercion,
|
|
192
|
+
wrapOutput,
|
|
193
|
+
version,
|
|
194
|
+
emptySchemaType
|
|
195
|
+
})
|
|
196
|
+
]
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/generators/operationsGenerator.tsx
|
|
203
|
+
const operationsGenerator = createReactGenerator({
|
|
204
|
+
name: "operations",
|
|
205
|
+
Operations({ operations }) {
|
|
206
|
+
const { pluginManager, plugin: { key: pluginKey, options: { output } } } = useApp();
|
|
207
|
+
const oas = useOas();
|
|
208
|
+
const { getFile, groupSchemasByName } = useOperationManager();
|
|
209
|
+
const name = "operations";
|
|
210
|
+
const file = pluginManager.getFile({
|
|
211
|
+
name,
|
|
212
|
+
extname: ".ts",
|
|
213
|
+
pluginKey
|
|
214
|
+
});
|
|
215
|
+
const transformedOperations = operations.map((operation) => ({
|
|
216
|
+
operation,
|
|
217
|
+
data: groupSchemasByName(operation, { type: "function" })
|
|
218
|
+
}));
|
|
219
|
+
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
220
|
+
const names = [
|
|
221
|
+
data.request,
|
|
222
|
+
...Object.values(data.responses),
|
|
223
|
+
...Object.values(data.parameters)
|
|
224
|
+
].filter(Boolean);
|
|
225
|
+
return /* @__PURE__ */ jsx(File.Import, {
|
|
226
|
+
name: names,
|
|
227
|
+
root: file.path,
|
|
228
|
+
path: getFile(operation).path
|
|
229
|
+
}, key);
|
|
230
|
+
}).filter(Boolean);
|
|
231
|
+
return /* @__PURE__ */ jsxs(File, {
|
|
232
|
+
baseName: file.baseName,
|
|
233
|
+
path: file.path,
|
|
234
|
+
meta: file.meta,
|
|
235
|
+
banner: getBanner({
|
|
236
|
+
oas,
|
|
237
|
+
output,
|
|
238
|
+
config: pluginManager.config
|
|
239
|
+
}),
|
|
240
|
+
footer: getFooter({
|
|
241
|
+
oas,
|
|
242
|
+
output
|
|
243
|
+
}),
|
|
244
|
+
children: [imports, /* @__PURE__ */ jsx(Operations, {
|
|
245
|
+
name,
|
|
246
|
+
operations: transformedOperations
|
|
247
|
+
})]
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
//#endregion
|
|
253
|
+
export { operationsGenerator, zodGenerator };
|
|
254
|
+
//# sourceMappingURL=generators-DcUZYcq0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-DcUZYcq0.js","names":["options","i: number"],"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"sourcesContent":["import { createReactGenerator, type OperationSchema as OperationSchemaType, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\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, 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: globalCoercion, inferred, typed, mapper, wrapOutput } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, getGroup } = 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: schemaObject, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schemaObject?.required) ? !!schemaObject.required.length : !!schemaObject?.required\n const someDefaults = Object.values(schemaObject.properties || {}).some((property) => Object.hasOwn(property, 'default') && property.default !== undefined)\n const optional = !required && !someDefaults && name.includes('Params')\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 <Oas.Schema key={i} name={name} schemaObject={schemaObject} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={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 </Oas.Schema>\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({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath, wrapOutput, version } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n pluginManager,\n plugin: {\n options: { output, emptySchemaType },\n },\n } = useApp<PluginZod>()\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 && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 rawSchema={schema.value}\n mapper={mapper}\n coercion={coercion}\n wrapOutput={wrapOutput}\n version={version}\n emptySchemaType={emptySchemaType}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginZod>()\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager()\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 {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;AASA,MAAa,eAA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