@kubb/plugin-zod 5.0.0-alpha.24 → 5.0.0-alpha.25
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/index.cjs +1673 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +317 -2
- package/dist/index.js +1646 -88
- package/dist/index.js.map +1 -1
- package/package.json +5 -33
- package/src/components/Operations.tsx +22 -15
- package/src/components/Zod.tsx +18 -118
- package/src/components/ZodMini.tsx +41 -0
- package/src/constants.ts +5 -0
- package/src/generators/zodGenerator.tsx +165 -158
- package/src/generators/zodGeneratorLegacy.tsx +401 -0
- package/src/index.ts +11 -1
- package/src/plugin.ts +105 -129
- package/src/presets.ts +25 -0
- package/src/printers/printerZod.ts +271 -0
- package/src/printers/printerZodMini.ts +246 -0
- package/src/resolvers/resolverZod.ts +71 -0
- package/src/resolvers/resolverZodLegacy.ts +60 -0
- package/src/types.ts +121 -92
- package/src/utils.ts +248 -0
- package/dist/components-DW4Q2yVq.js +0 -868
- package/dist/components-DW4Q2yVq.js.map +0 -1
- package/dist/components-qFUGs0vU.cjs +0 -916
- package/dist/components-qFUGs0vU.cjs.map +0 -1
- package/dist/components.cjs +0 -4
- package/dist/components.d.ts +0 -56
- package/dist/components.js +0 -2
- package/dist/generators-C9BCTLXg.cjs +0 -301
- package/dist/generators-C9BCTLXg.cjs.map +0 -1
- package/dist/generators-maqx12yN.js +0 -290
- package/dist/generators-maqx12yN.js.map +0 -1
- package/dist/generators.cjs +0 -4
- package/dist/generators.d.ts +0 -12
- package/dist/generators.js +0 -2
- package/dist/templates/ToZod.source.cjs +0 -7
- package/dist/templates/ToZod.source.cjs.map +0 -1
- package/dist/templates/ToZod.source.d.ts +0 -7
- package/dist/templates/ToZod.source.js +0 -6
- package/dist/templates/ToZod.source.js.map +0 -1
- package/dist/types-CClg-ikj.d.ts +0 -172
- package/src/components/index.ts +0 -2
- package/src/generators/index.ts +0 -2
- package/src/generators/operationsGenerator.tsx +0 -50
- package/src/parser.ts +0 -952
- package/src/templates/ToZod.source.ts +0 -4
- package/templates/ToZod.ts +0 -61
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as Operations, t as Zod } from "./components-DW4Q2yVq.js";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { SchemaGenerator, schemaKeywords } from "@kubb/plugin-oas";
|
|
5
|
-
import { pluginTsName } from "@kubb/plugin-ts";
|
|
6
|
-
import { useDriver, useMode } from "@kubb/core/hooks";
|
|
7
|
-
import { createReactGenerator } from "@kubb/plugin-oas/generators";
|
|
8
|
-
import { useOas, useOperationManager, useSchemaManager } from "@kubb/plugin-oas/hooks";
|
|
9
|
-
import { getBanner, getFooter, getImports } from "@kubb/plugin-oas/utils";
|
|
10
|
-
import { File } from "@kubb/react-fabric";
|
|
11
|
-
import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
|
|
12
|
-
//#region src/generators/operationsGenerator.tsx
|
|
13
|
-
const operationsGenerator = createReactGenerator({
|
|
14
|
-
name: "operations",
|
|
15
|
-
Operations({ operations, generator, plugin }) {
|
|
16
|
-
const { name: pluginName, options: { output, importPath } } = plugin;
|
|
17
|
-
const driver = useDriver();
|
|
18
|
-
const oas = useOas();
|
|
19
|
-
const { getFile, groupSchemasByName } = useOperationManager(generator);
|
|
20
|
-
const name = "operations";
|
|
21
|
-
const file = driver.getFile({
|
|
22
|
-
name,
|
|
23
|
-
extname: ".ts",
|
|
24
|
-
pluginName
|
|
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
|
-
const isZodImport = importPath === "zod" || importPath === "zod/mini";
|
|
43
|
-
return /* @__PURE__ */ jsxs(File, {
|
|
44
|
-
baseName: file.baseName,
|
|
45
|
-
path: file.path,
|
|
46
|
-
meta: file.meta,
|
|
47
|
-
banner: getBanner({
|
|
48
|
-
oas,
|
|
49
|
-
output,
|
|
50
|
-
config: driver.config
|
|
51
|
-
}),
|
|
52
|
-
footer: getFooter({
|
|
53
|
-
oas,
|
|
54
|
-
output
|
|
55
|
-
}),
|
|
56
|
-
children: [
|
|
57
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
58
|
-
isTypeOnly: true,
|
|
59
|
-
name: isZodImport ? "z" : ["z"],
|
|
60
|
-
path: importPath,
|
|
61
|
-
isNameSpace: isZodImport
|
|
62
|
-
}),
|
|
63
|
-
imports,
|
|
64
|
-
/* @__PURE__ */ jsx(Operations, {
|
|
65
|
-
name,
|
|
66
|
-
operations: transformedOperations
|
|
67
|
-
})
|
|
68
|
-
]
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
//#endregion
|
|
73
|
-
//#region src/generators/zodGenerator.tsx
|
|
74
|
-
const zodGenerator = createReactGenerator({
|
|
75
|
-
name: "zod",
|
|
76
|
-
Operation({ config, operation, generator, plugin }) {
|
|
77
|
-
const { options, options: { coercion: globalCoercion, inferred, typed, mapper, wrapOutput, version, guidType, mini } } = plugin;
|
|
78
|
-
const mode = useMode();
|
|
79
|
-
const driver = useDriver();
|
|
80
|
-
const oas = useOas();
|
|
81
|
-
const { getSchemas, getFile, getGroup } = useOperationManager(generator);
|
|
82
|
-
const schemaManager = useSchemaManager();
|
|
83
|
-
const file = getFile(operation);
|
|
84
|
-
const schemas = getSchemas(operation);
|
|
85
|
-
const schemaGenerator = new SchemaGenerator(options, {
|
|
86
|
-
fabric: generator.context.fabric,
|
|
87
|
-
oas,
|
|
88
|
-
plugin,
|
|
89
|
-
driver,
|
|
90
|
-
events: generator.context.events,
|
|
91
|
-
mode,
|
|
92
|
-
override: options.override
|
|
93
|
-
});
|
|
94
|
-
const operationSchemas = [
|
|
95
|
-
schemas.pathParams,
|
|
96
|
-
schemas.queryParams,
|
|
97
|
-
schemas.headerParams,
|
|
98
|
-
schemas.statusCodes,
|
|
99
|
-
schemas.request,
|
|
100
|
-
schemas.response
|
|
101
|
-
].flat().filter(Boolean);
|
|
102
|
-
const toZodPath = path.resolve(config.root, config.output.path, ".kubb/ToZod.ts");
|
|
103
|
-
const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options }) => {
|
|
104
|
-
let schemaObject = schemaOriginal;
|
|
105
|
-
let keysToOmit = keysToOmitOriginal;
|
|
106
|
-
if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {
|
|
107
|
-
schemaObject = structuredClone(schemaOriginal);
|
|
108
|
-
delete schemaObject.$ref;
|
|
109
|
-
for (const key of keysToOmitOriginal) delete schemaObject.properties?.[key];
|
|
110
|
-
if (Array.isArray(schemaObject.required)) schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key));
|
|
111
|
-
keysToOmit = void 0;
|
|
112
|
-
}
|
|
113
|
-
const hasProperties = Object.keys(schemaObject || {}).length > 0;
|
|
114
|
-
const hasDefaults = Object.values(schemaObject.properties || {}).some((prop) => prop && Object.hasOwn(prop, "default"));
|
|
115
|
-
const optional = !(Array.isArray(schemaObject?.required) ? schemaObject.required.length > 0 : !!schemaObject?.required) && !hasDefaults && hasProperties && name.includes("Params");
|
|
116
|
-
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);
|
|
117
|
-
const tree = [...schemaGenerator.parse({
|
|
118
|
-
schema: schemaObject,
|
|
119
|
-
name,
|
|
120
|
-
parentName: null
|
|
121
|
-
}), optional ? { keyword: schemaKeywords.optional } : void 0].filter(Boolean);
|
|
122
|
-
const imports = getImports(tree);
|
|
123
|
-
const group = options.operation ? getGroup(options.operation) : void 0;
|
|
124
|
-
const coercion = name.includes("Params") ? {
|
|
125
|
-
numbers: true,
|
|
126
|
-
strings: false,
|
|
127
|
-
dates: true
|
|
128
|
-
} : globalCoercion;
|
|
129
|
-
const zod = {
|
|
130
|
-
name: schemaManager.getName(name, { type: "function" }),
|
|
131
|
-
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
132
|
-
file: schemaManager.getFile(name)
|
|
133
|
-
};
|
|
134
|
-
const type = {
|
|
135
|
-
name: schemaManager.getName(name, {
|
|
136
|
-
type: "type",
|
|
137
|
-
pluginName: pluginTsName
|
|
138
|
-
}),
|
|
139
|
-
file: schemaManager.getFile(options.operationName || name, {
|
|
140
|
-
pluginName: pluginTsName,
|
|
141
|
-
group
|
|
142
|
-
})
|
|
143
|
-
};
|
|
144
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
145
|
-
typed && /* @__PURE__ */ jsx(File.Import, {
|
|
146
|
-
isTypeOnly: true,
|
|
147
|
-
root: file.path,
|
|
148
|
-
path: type.file.path,
|
|
149
|
-
name: [type.name]
|
|
150
|
-
}),
|
|
151
|
-
imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
152
|
-
root: file.path,
|
|
153
|
-
path: imp.path,
|
|
154
|
-
name: imp.name
|
|
155
|
-
}, [
|
|
156
|
-
imp.path,
|
|
157
|
-
imp.name,
|
|
158
|
-
imp.isTypeOnly
|
|
159
|
-
].join("-"))),
|
|
160
|
-
/* @__PURE__ */ jsx(Zod, {
|
|
161
|
-
name: zod.name,
|
|
162
|
-
typeName: typed ? type.name : void 0,
|
|
163
|
-
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
164
|
-
description,
|
|
165
|
-
tree,
|
|
166
|
-
schema: schemaObject,
|
|
167
|
-
mapper,
|
|
168
|
-
coercion,
|
|
169
|
-
keysToOmit,
|
|
170
|
-
wrapOutput,
|
|
171
|
-
version: plugin.options.version,
|
|
172
|
-
guidType,
|
|
173
|
-
emptySchemaType: plugin.options.emptySchemaType,
|
|
174
|
-
mini
|
|
175
|
-
})
|
|
176
|
-
] });
|
|
177
|
-
};
|
|
178
|
-
const isZodImport = plugin.options.importPath === "zod" || plugin.options.importPath === "zod/mini";
|
|
179
|
-
return /* @__PURE__ */ jsxs(File, {
|
|
180
|
-
baseName: file.baseName,
|
|
181
|
-
path: file.path,
|
|
182
|
-
meta: file.meta,
|
|
183
|
-
banner: getBanner({
|
|
184
|
-
oas,
|
|
185
|
-
output: plugin.options.output,
|
|
186
|
-
config: driver.config
|
|
187
|
-
}),
|
|
188
|
-
footer: getFooter({
|
|
189
|
-
oas,
|
|
190
|
-
output: plugin.options.output
|
|
191
|
-
}),
|
|
192
|
-
children: [
|
|
193
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
194
|
-
name: isZodImport ? "z" : ["z"],
|
|
195
|
-
path: plugin.options.importPath,
|
|
196
|
-
isNameSpace: isZodImport
|
|
197
|
-
}),
|
|
198
|
-
typed && version === "3" && /* @__PURE__ */ jsx(File.Import, {
|
|
199
|
-
name: ["ToZod"],
|
|
200
|
-
isTypeOnly: true,
|
|
201
|
-
root: file.path,
|
|
202
|
-
path: toZodPath
|
|
203
|
-
}),
|
|
204
|
-
operationSchemas.map(mapOperationSchema)
|
|
205
|
-
]
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
Schema({ config, schema, plugin }) {
|
|
209
|
-
const { getName, getFile } = useSchemaManager();
|
|
210
|
-
const { options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, mini } } = plugin;
|
|
211
|
-
const driver = useDriver();
|
|
212
|
-
const oas = useOas();
|
|
213
|
-
const imports = getImports(schema.tree);
|
|
214
|
-
const zod = {
|
|
215
|
-
name: getName(schema.name, { type: "function" }),
|
|
216
|
-
inferTypeName: getName(schema.name, { type: "type" }),
|
|
217
|
-
file: getFile(schema.name)
|
|
218
|
-
};
|
|
219
|
-
const type = {
|
|
220
|
-
name: getName(schema.name, {
|
|
221
|
-
type: "type",
|
|
222
|
-
pluginName: pluginTsName
|
|
223
|
-
}),
|
|
224
|
-
file: getFile(schema.name, { pluginName: pluginTsName })
|
|
225
|
-
};
|
|
226
|
-
const isZodImport = importPath === "zod" || importPath === "zod/mini";
|
|
227
|
-
const toZodPath = path.resolve(config.root, config.output.path, ".kubb/ToZod.ts");
|
|
228
|
-
return /* @__PURE__ */ jsxs(File, {
|
|
229
|
-
baseName: zod.file.baseName,
|
|
230
|
-
path: zod.file.path,
|
|
231
|
-
meta: zod.file.meta,
|
|
232
|
-
banner: getBanner({
|
|
233
|
-
oas,
|
|
234
|
-
output,
|
|
235
|
-
config: driver.config
|
|
236
|
-
}),
|
|
237
|
-
footer: getFooter({
|
|
238
|
-
oas,
|
|
239
|
-
output
|
|
240
|
-
}),
|
|
241
|
-
children: [
|
|
242
|
-
/* @__PURE__ */ jsx(File.Import, {
|
|
243
|
-
name: isZodImport ? "z" : ["z"],
|
|
244
|
-
path: importPath,
|
|
245
|
-
isNameSpace: isZodImport
|
|
246
|
-
}),
|
|
247
|
-
typed && /* @__PURE__ */ jsx(File.Import, {
|
|
248
|
-
isTypeOnly: true,
|
|
249
|
-
root: zod.file.path,
|
|
250
|
-
path: type.file.path,
|
|
251
|
-
name: [type.name]
|
|
252
|
-
}),
|
|
253
|
-
typed && version === "3" && /* @__PURE__ */ jsx(File.Import, {
|
|
254
|
-
name: ["ToZod"],
|
|
255
|
-
isTypeOnly: true,
|
|
256
|
-
root: zod.file.path,
|
|
257
|
-
path: toZodPath
|
|
258
|
-
}),
|
|
259
|
-
imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
260
|
-
root: zod.file.path,
|
|
261
|
-
path: imp.path,
|
|
262
|
-
name: imp.name
|
|
263
|
-
}, [
|
|
264
|
-
imp.path,
|
|
265
|
-
imp.name,
|
|
266
|
-
imp.isTypeOnly
|
|
267
|
-
].join("-"))),
|
|
268
|
-
/* @__PURE__ */ jsx(Zod, {
|
|
269
|
-
name: zod.name,
|
|
270
|
-
typeName: typed ? type.name : void 0,
|
|
271
|
-
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
272
|
-
description: schema.value.description,
|
|
273
|
-
tree: schema.tree,
|
|
274
|
-
schema: schema.value,
|
|
275
|
-
mapper,
|
|
276
|
-
coercion,
|
|
277
|
-
wrapOutput,
|
|
278
|
-
version,
|
|
279
|
-
guidType,
|
|
280
|
-
emptySchemaType,
|
|
281
|
-
mini
|
|
282
|
-
})
|
|
283
|
-
]
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
//#endregion
|
|
288
|
-
export { operationsGenerator as n, zodGenerator as t };
|
|
289
|
-
|
|
290
|
-
//# sourceMappingURL=generators-maqx12yN.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-maqx12yN.js","names":[],"sources":["../src/generators/operationsGenerator.tsx","../src/generators/zodGenerator.tsx"],"sourcesContent":["import { useDriver } 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 name: pluginName,\n options: { output, importPath },\n } = plugin\n const driver = useDriver()\n\n const oas = useOas()\n const { getFile, groupSchemasByName } = useOperationManager(generator)\n\n const name = 'operations'\n const file = driver.getFile({ name, extname: '.ts', pluginName })\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 const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\n\n return (\n <File\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output, config: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import isTypeOnly name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n","import path from 'node:path'\nimport { useDriver, useMode } 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, getImports } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } 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, guidType, mini },\n } = plugin\n\n const mode = useMode()\n const driver = useDriver()\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 driver,\n events: generator.context.events,\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 const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\n\n const mapOperationSchema = ({ name, schema: schemaOriginal, description, keysToOmit: keysToOmitOriginal, ...options }: OperationSchemaType) => {\n let schemaObject = schemaOriginal\n let keysToOmit = keysToOmitOriginal\n\n if ((schemaOriginal.anyOf || schemaOriginal.oneOf) && keysToOmitOriginal && keysToOmitOriginal.length > 0) {\n schemaObject = structuredClone(schemaOriginal)\n\n // Remove $ref so the schema parser generates inline schema instead of a reference\n delete schemaObject.$ref\n\n for (const key of keysToOmitOriginal) {\n delete schemaObject.properties?.[key]\n }\n\n if (Array.isArray(schemaObject.required)) {\n schemaObject.required = schemaObject.required.filter((key) => !keysToOmitOriginal.includes(key))\n }\n\n keysToOmit = undefined\n }\n\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 = [\n ...schemaGenerator.parse({ schema: schemaObject, name, parentName: null }),\n optional ? { keyword: schemaKeywords.optional } : undefined,\n ].filter(Boolean)\n const imports = 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 pluginName: pluginTsName,\n }),\n file: schemaManager.getFile(options.operationName || name, {\n pluginName: pluginTsName,\n group,\n }),\n }\n\n return (\n <>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\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 guidType={guidType}\n emptySchemaType={plugin.options.emptySchemaType}\n mini={mini}\n />\n </>\n )\n }\n\n const isZodImport = plugin.options.importPath === 'zod' || plugin.options.importPath === 'zod/mini'\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: driver.config })}\n footer={getFooter({ oas, output: plugin.options.output })}\n >\n <File.Import name={isZodImport ? 'z' : ['z']} path={plugin.options.importPath} isNameSpace={isZodImport} />\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={file.path} path={toZodPath} />}\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ config, schema, plugin }) {\n const { getName, getFile } = useSchemaManager()\n const {\n options: { output, emptySchemaType, coercion, inferred, typed, mapper, importPath, wrapOutput, version, guidType, mini },\n } = plugin\n const driver = useDriver()\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', pluginName: pluginTsName }),\n file: getFile(schema.name, { pluginName: pluginTsName }),\n }\n\n const isZodImport = importPath === 'zod' || importPath === 'zod/mini'\n const toZodPath = path.resolve(config.root, config.output.path, '.kubb/ToZod.ts')\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: driver.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {typed && version === '3' && <File.Import name={['ToZod']} isTypeOnly root={zod.file.path} path={toZodPath} />}\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 guidType={guidType}\n emptySchemaType={emptySchemaType}\n mini={mini}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;;AAQA,MAAa,sBAAsB,qBAAgC;CACjE,MAAM;CACN,WAAW,EAAE,YAAY,WAAW,UAAU;EAC5C,MAAM,EACJ,MAAM,YACN,SAAS,EAAE,QAAQ,iBACjB;EACJ,MAAM,SAAS,WAAW;EAE1B,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,SAAS,uBAAuB,oBAAoB,UAAU;EAEtE,MAAM,OAAO;EACb,MAAM,OAAO,OAAO,QAAQ;GAAE;GAAM,SAAS;GAAO;GAAY,CAAC;EAEjE,MAAM,wBAAwB,WAAW,KAAK,eAAe;GAAE;GAAW,MAAM,mBAAmB,WAAW,EAAE,MAAM,YAAY,CAAC;GAAE,EAAE;EAEvI,MAAM,UAAU,OAAO,QAAQ,sBAAsB,CAClD,KAAK,CAAC,KAAK,EAAE,MAAM,iBAAiB;GACnC,MAAM,QAAQ;IAAC,KAAK;IAAS,GAAG,OAAO,OAAO,KAAK,UAAU;IAAE,GAAG,OAAO,OAAO,KAAK,WA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QAAQ,UAAU;IAAE;IAAK;IAAQ,QAAQ,OAAO;IAAQ,CAAC;GACzD,QAAQ,UAAU;IAAE;IAAK;IAAQ,CAAC;aALpC;IAOE,oBAAC,KAAK,QAAN;KAAa,MAAM,cAAc,MAAM,CAAC,IAAI;KAAE,MAAM;KAAY,aAAa;KAAe,CAAA;IAC3F,SAAS,oBAAC,KAAK,QAAN;KAAa,YAAA;KAAW,MAAM,IAAI,KAAK;KAAM,MAAM,KAAK,KAAK;KAAM,MAAM,CAAC,KAAK,KAAK;KAAI,CAAA;IACjG,SAAS,YAAY,OAAO,oBAAC,KAAK,QAAN;KAAa,MAAM,CAAC,QAAQ;KAAE,YAAA;KAAW,MAAM,IAAI,KAAK;KAAM,MAAM;KAAa,CAAA;IAC7G,QAAQ,KAAK,QACZ,oBAAC,KAAK,QAAN;KAAkE,MAAM,IAAI,KAAK;KAAM,MAAM,IAAI;KAAM,MAAM,IAAI;KAAQ,EAAvG;KAAC,IAAI;KAAM,IAAI;KAAM,IAAI;KAAW,CAAC,KAAK,IAAI,CAAyD,CACzH;IAEF,oBAAC,KAAD;KACE,MAAM,IAAI;KACV,UAAU,QAAQ,KAAK,OAAO,KAAA;KAC9B,eAAe,WAAW,IAAI,gBAAgB,KAAA;KAC9C,aAAa,OAAO,MAAM;KAC1B,MAAM,OAAO;KACb,QAAQ,OAAO;KACP;KACE;KACE;KACH;KACC;KACO;KACX;KACN,CAAA;IACG;;;CAGZ,CAAC"}
|
package/dist/generators.cjs
DELETED
package/dist/generators.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { n as PluginZod } from "./types-CClg-ikj.js";
|
|
3
|
-
import * as _$_kubb_plugin_oas_generators0 from "@kubb/plugin-oas/generators";
|
|
4
|
-
|
|
5
|
-
//#region src/generators/operationsGenerator.d.ts
|
|
6
|
-
declare const operationsGenerator: _$_kubb_plugin_oas_generators0.ReactGenerator<PluginZod>;
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/generators/zodGenerator.d.ts
|
|
9
|
-
declare const zodGenerator: _$_kubb_plugin_oas_generators0.ReactGenerator<PluginZod>;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { operationsGenerator, zodGenerator };
|
|
12
|
-
//# sourceMappingURL=generators.d.ts.map
|
package/dist/generators.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
//#region src/templates/ToZod.source.ts
|
|
3
|
-
const source = "/**\n * See https://github.com/colinhacks/tozod/blob/master/src/index.ts\n * Adapted based on https://github.com/colinhacks/zod/issues/372\n */\n\nimport type * as z from 'zod'\n\ntype IsAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false\ntype NonOptional<T> = T extends undefined ? never : T\ntype NonNullable<T> = T extends null ? never : T\ntype Equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false\n\ntype ZodKey<T> =\n IsAny<T> extends true\n ? 'any'\n : Equals<T, boolean> extends true //[T] extends [booleanUtil.Type]\n ? 'boolean'\n : [undefined] extends [T]\n ? 'optional'\n : [null] extends [T]\n ? 'nullable'\n : T extends any[]\n ? 'array'\n : Equals<T, string> extends true\n ? 'string'\n : Equals<T, bigint> extends true //[T] extends [bigintUtil.Type]\n ? 'bigint'\n : Equals<T, number> extends true //[T] extends [numberUtil.Type]\n ? 'number'\n : Equals<T, Date> extends true //[T] extends [dateUtil.Type]\n ? 'date'\n : T extends { [k: string]: any } //[T] extends [structUtil.Type]\n ? 'object'\n : 'rest'\n\nexport type ToZod<T> = {\n any: z.ZodAny\n optional: z.ZodOptional<ToZod<NonOptional<T>>>\n nullable: z.ZodNullable<ToZod<NonNullable<T>>>\n array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never\n string: z.ZodString\n bigint: z.ZodBigInt\n number: z.ZodNumber\n boolean: z.ZodBoolean\n date: z.ZodDate\n object: z.ZodObject<\n // @ts-expect-error cannot convert without Extract but Extract removes the type\n {\n [K in keyof T]: T[K]\n },\n 'passthrough',\n unknown,\n T\n >\n rest: z.ZodType<T>\n}[ZodKey<T>]\n\nexport type ZodShape<T> = {\n // Require all the keys from T\n [key in keyof T]-?: ToZod<T[key]>\n}\n";
|
|
4
|
-
//#endregion
|
|
5
|
-
exports.source = source;
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=ToZod.source.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToZod.source.cjs","names":[],"sources":["../../src/templates/ToZod.source.ts"],"sourcesContent":["// @ts-expect-error - import attributes are handled at build time by importAttributeTextPlugin\nimport content from '../../templates/ToZod.ts' with { type: 'text' }\n\nexport const source = content as string\n"],"mappings":";;AAAA,MAAa,SAAS"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
//#region src/templates/ToZod.source.ts
|
|
2
|
-
const source = "/**\n * See https://github.com/colinhacks/tozod/blob/master/src/index.ts\n * Adapted based on https://github.com/colinhacks/zod/issues/372\n */\n\nimport type * as z from 'zod'\n\ntype IsAny<T> = [any extends T ? 'true' : 'false'] extends ['true'] ? true : false\ntype NonOptional<T> = T extends undefined ? never : T\ntype NonNullable<T> = T extends null ? never : T\ntype Equals<X, Y> = [X] extends [Y] ? ([Y] extends [X] ? true : false) : false\n\ntype ZodKey<T> =\n IsAny<T> extends true\n ? 'any'\n : Equals<T, boolean> extends true //[T] extends [booleanUtil.Type]\n ? 'boolean'\n : [undefined] extends [T]\n ? 'optional'\n : [null] extends [T]\n ? 'nullable'\n : T extends any[]\n ? 'array'\n : Equals<T, string> extends true\n ? 'string'\n : Equals<T, bigint> extends true //[T] extends [bigintUtil.Type]\n ? 'bigint'\n : Equals<T, number> extends true //[T] extends [numberUtil.Type]\n ? 'number'\n : Equals<T, Date> extends true //[T] extends [dateUtil.Type]\n ? 'date'\n : T extends { [k: string]: any } //[T] extends [structUtil.Type]\n ? 'object'\n : 'rest'\n\nexport type ToZod<T> = {\n any: z.ZodAny\n optional: z.ZodOptional<ToZod<NonOptional<T>>>\n nullable: z.ZodNullable<ToZod<NonNullable<T>>>\n array: T extends Array<infer U> ? z.ZodArray<ToZod<U>> : never\n string: z.ZodString\n bigint: z.ZodBigInt\n number: z.ZodNumber\n boolean: z.ZodBoolean\n date: z.ZodDate\n object: z.ZodObject<\n // @ts-expect-error cannot convert without Extract but Extract removes the type\n {\n [K in keyof T]: T[K]\n },\n 'passthrough',\n unknown,\n T\n >\n rest: z.ZodType<T>\n}[ZodKey<T>]\n\nexport type ZodShape<T> = {\n // Require all the keys from T\n [key in keyof T]-?: ToZod<T[key]>\n}\n";
|
|
3
|
-
//#endregion
|
|
4
|
-
export { source };
|
|
5
|
-
|
|
6
|
-
//# sourceMappingURL=ToZod.source.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ToZod.source.js","names":[],"sources":["../../src/templates/ToZod.source.ts"],"sourcesContent":["// @ts-expect-error - import attributes are handled at build time by importAttributeTextPlugin\nimport content from '../../templates/ToZod.ts' with { type: 'text' }\n\nexport const source = content as string\n"],"mappings":";AAAA,MAAa,SAAS"}
|
package/dist/types-CClg-ikj.d.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { Output, PluginFactoryOptions, ResolveNameParams, UserGroup } from "@kubb/core";
|
|
3
|
-
import { Exclude, Include, Override, ResolvePathOptions, Schema } from "@kubb/plugin-oas";
|
|
4
|
-
import { Generator } from "@kubb/plugin-oas/generators";
|
|
5
|
-
import { Oas, SchemaObject, contentType } from "@kubb/oas";
|
|
6
|
-
|
|
7
|
-
//#region src/types.d.ts
|
|
8
|
-
type Options = {
|
|
9
|
-
/**
|
|
10
|
-
* @default 'zod'
|
|
11
|
-
*/
|
|
12
|
-
output?: Output<Oas>;
|
|
13
|
-
/**
|
|
14
|
-
* Define which contentType should be used.
|
|
15
|
-
* By default, the first JSON valid mediaType is used
|
|
16
|
-
*/
|
|
17
|
-
contentType?: contentType;
|
|
18
|
-
/**
|
|
19
|
-
* Group the Zod schemas based on the provided name.
|
|
20
|
-
*/
|
|
21
|
-
group?: UserGroup;
|
|
22
|
-
/**
|
|
23
|
-
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
24
|
-
*/
|
|
25
|
-
exclude?: Array<Exclude>;
|
|
26
|
-
/**
|
|
27
|
-
* Array containing include parameters to include tags/operations/methods/paths.
|
|
28
|
-
*/
|
|
29
|
-
include?: Array<Include>;
|
|
30
|
-
/**
|
|
31
|
-
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
32
|
-
*/
|
|
33
|
-
override?: Array<Override<ResolvedOptions>>;
|
|
34
|
-
/**
|
|
35
|
-
* Path to Zod
|
|
36
|
-
* It used as `import { z } from '${importPath}'`.
|
|
37
|
-
* Accepts relative and absolute paths.
|
|
38
|
-
* Path is used as-is; relative paths are based on the generated file location.
|
|
39
|
-
* @default 'zod'
|
|
40
|
-
*/
|
|
41
|
-
importPath?: string;
|
|
42
|
-
/**
|
|
43
|
-
* Choose to use date or datetime as JavaScript Date instead of string.
|
|
44
|
-
* - false falls back to a simple z.string() format.
|
|
45
|
-
* - 'string' uses z.string().datetime() for datetime validation.
|
|
46
|
-
* - 'stringOffset' uses z.string().datetime({ offset: true }) for datetime with timezone offset validation.
|
|
47
|
-
* - 'stringLocal' uses z.string().datetime({ local: true }) for local datetime validation.
|
|
48
|
-
* - 'date' uses z.date() for JavaScript Date objects.
|
|
49
|
-
* @default 'string'
|
|
50
|
-
* @note 'stringOffset' will become the default in Kubb v3.
|
|
51
|
-
*/
|
|
52
|
-
dateType?: false | 'string' | 'stringOffset' | 'stringLocal' | 'date';
|
|
53
|
-
/**
|
|
54
|
-
* Choose to use `number` or `bigint` for integer fields with `int64` format.
|
|
55
|
-
* - 'number' uses the JavaScript `number` type (matches JSON.parse() runtime behavior).
|
|
56
|
-
* - 'bigint' uses the JavaScript `bigint` type (accurate for values exceeding Number.MAX_SAFE_INTEGER).
|
|
57
|
-
* @note in v5 of Kubb 'bigint' will become the default to better align with OpenAPI's int64 specification.
|
|
58
|
-
* @default 'number'
|
|
59
|
-
*/
|
|
60
|
-
integerType?: 'number' | 'bigint';
|
|
61
|
-
/**
|
|
62
|
-
* Which type to use when the Swagger/OpenAPI file is not providing more information.
|
|
63
|
-
* - 'any' allows any value.
|
|
64
|
-
* - 'unknown' requires type narrowing before use.
|
|
65
|
-
* - 'void' represents no value.
|
|
66
|
-
* @default 'any'
|
|
67
|
-
*/
|
|
68
|
-
unknownType?: 'any' | 'unknown' | 'void';
|
|
69
|
-
/**
|
|
70
|
-
* Which type to use for empty schema values.
|
|
71
|
-
* - 'any' allows any value.
|
|
72
|
-
* - 'unknown' requires type narrowing before use.
|
|
73
|
-
* - 'void' represents no value.
|
|
74
|
-
* @default `unknownType`
|
|
75
|
-
*/
|
|
76
|
-
emptySchemaType?: 'any' | 'unknown' | 'void';
|
|
77
|
-
/**
|
|
78
|
-
* Use TypeScript(`@kubb/plugin-ts`) to add type annotation.
|
|
79
|
-
*/
|
|
80
|
-
typed?: boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Return Zod generated schema as type with z.infer<TYPE>
|
|
83
|
-
*/
|
|
84
|
-
inferred?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Use of z.coerce.string() instead of z.string()
|
|
87
|
-
* can also be an object to enable coercion for dates, strings, and numbers
|
|
88
|
-
*/
|
|
89
|
-
coercion?: boolean | {
|
|
90
|
-
dates?: boolean;
|
|
91
|
-
strings?: boolean;
|
|
92
|
-
numbers?: boolean;
|
|
93
|
-
};
|
|
94
|
-
operations?: boolean;
|
|
95
|
-
mapper?: Record<string, string>;
|
|
96
|
-
transformers?: {
|
|
97
|
-
/**
|
|
98
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
99
|
-
*/
|
|
100
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
101
|
-
/**
|
|
102
|
-
* Receive schema and baseName(propertyName) and return FakerMeta array
|
|
103
|
-
* TODO TODO add docs
|
|
104
|
-
* @beta
|
|
105
|
-
*/
|
|
106
|
-
schema?: (props: {
|
|
107
|
-
schema: SchemaObject | null;
|
|
108
|
-
name: string | null;
|
|
109
|
-
parentName: string | null;
|
|
110
|
-
}, defaultSchemas: Schema[]) => Schema[] | undefined;
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Which version of Zod should be used.
|
|
114
|
-
* - '3' uses Zod v3.x syntax and features.
|
|
115
|
-
* - '4' uses Zod v4.x syntax and features.
|
|
116
|
-
* @default '3'
|
|
117
|
-
*/
|
|
118
|
-
version?: '3' | '4';
|
|
119
|
-
/**
|
|
120
|
-
* Which Zod GUID validator to use for OpenAPI `format: uuid`.
|
|
121
|
-
* - 'uuid' uses UUID validation.
|
|
122
|
-
* - 'guid' uses GUID validation (Zod v4 only).
|
|
123
|
-
* @default 'uuid'
|
|
124
|
-
*/
|
|
125
|
-
guidType?: 'uuid' | 'guid';
|
|
126
|
-
/**
|
|
127
|
-
* Use Zod Mini's functional API for better tree-shaking support.
|
|
128
|
-
* When enabled, generates functional syntax (e.g., `z.optional(z.string())`) instead of chainable methods (e.g., `z.string().optional()`).
|
|
129
|
-
* Requires Zod v4 or later. When `mini: true`, `version` is set to '4' and `importPath` will default to 'zod/mini'.
|
|
130
|
-
* @default false
|
|
131
|
-
*/
|
|
132
|
-
mini?: boolean;
|
|
133
|
-
/**
|
|
134
|
-
* Callback function to wrap the output of the generated zod schema
|
|
135
|
-
*
|
|
136
|
-
* This is useful for edge case scenarios where you might leverage something like `z.object({ ... }).openapi({ example: { some: "complex-example" }})`
|
|
137
|
-
* or `extendApi(z.object({ ... }), { example: { some: "complex-example", ...otherOpenApiProperties }})`
|
|
138
|
-
* while going from openapi -> zod -> openapi
|
|
139
|
-
*/
|
|
140
|
-
wrapOutput?: (arg: {
|
|
141
|
-
output: string;
|
|
142
|
-
schema: SchemaObject;
|
|
143
|
-
}) => string | undefined;
|
|
144
|
-
/**
|
|
145
|
-
* Define some generators next to the zod generators
|
|
146
|
-
*/
|
|
147
|
-
generators?: Array<Generator<PluginZod>>;
|
|
148
|
-
};
|
|
149
|
-
type ResolvedOptions = {
|
|
150
|
-
output: Output<Oas>;
|
|
151
|
-
group: Options['group'];
|
|
152
|
-
override: NonNullable<Options['override']>;
|
|
153
|
-
transformers: NonNullable<Options['transformers']>;
|
|
154
|
-
dateType: NonNullable<Options['dateType']>;
|
|
155
|
-
integerType: NonNullable<Options['integerType']>;
|
|
156
|
-
unknownType: NonNullable<Options['unknownType']>;
|
|
157
|
-
emptySchemaType: NonNullable<Options['emptySchemaType']>;
|
|
158
|
-
typed: NonNullable<Options['typed']>;
|
|
159
|
-
inferred: NonNullable<Options['inferred']>;
|
|
160
|
-
mapper: NonNullable<Options['mapper']>;
|
|
161
|
-
importPath: NonNullable<Options['importPath']>;
|
|
162
|
-
coercion: NonNullable<Options['coercion']>;
|
|
163
|
-
operations: NonNullable<Options['operations']>;
|
|
164
|
-
wrapOutput: Options['wrapOutput'];
|
|
165
|
-
version: NonNullable<Options['version']>;
|
|
166
|
-
guidType: NonNullable<Options['guidType']>;
|
|
167
|
-
mini: NonNullable<Options['mini']>;
|
|
168
|
-
};
|
|
169
|
-
type PluginZod = PluginFactoryOptions<'plugin-zod', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
170
|
-
//#endregion
|
|
171
|
-
export { PluginZod as n, Options as t };
|
|
172
|
-
//# sourceMappingURL=types-CClg-ikj.d.ts.map
|
package/src/components/index.ts
DELETED
package/src/generators/index.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useDriver } from '@kubb/core/hooks'
|
|
2
|
-
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
3
|
-
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
|
-
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
5
|
-
import { File } from '@kubb/react-fabric'
|
|
6
|
-
import { Operations } from '../components/Operations.tsx'
|
|
7
|
-
import type { PluginZod } from '../types'
|
|
8
|
-
|
|
9
|
-
export const operationsGenerator = createReactGenerator<PluginZod>({
|
|
10
|
-
name: 'operations',
|
|
11
|
-
Operations({ operations, generator, plugin }) {
|
|
12
|
-
const {
|
|
13
|
-
name: pluginName,
|
|
14
|
-
options: { output, importPath },
|
|
15
|
-
} = plugin
|
|
16
|
-
const driver = useDriver()
|
|
17
|
-
|
|
18
|
-
const oas = useOas()
|
|
19
|
-
const { getFile, groupSchemasByName } = useOperationManager(generator)
|
|
20
|
-
|
|
21
|
-
const name = 'operations'
|
|
22
|
-
const file = driver.getFile({ name, extname: '.ts', pluginName })
|
|
23
|
-
|
|
24
|
-
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))
|
|
25
|
-
|
|
26
|
-
const imports = Object.entries(transformedOperations)
|
|
27
|
-
.map(([key, { data, operation }]) => {
|
|
28
|
-
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)
|
|
29
|
-
|
|
30
|
-
return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />
|
|
31
|
-
})
|
|
32
|
-
.filter(Boolean)
|
|
33
|
-
|
|
34
|
-
const isZodImport = importPath === 'zod' || importPath === 'zod/mini'
|
|
35
|
-
|
|
36
|
-
return (
|
|
37
|
-
<File
|
|
38
|
-
baseName={file.baseName}
|
|
39
|
-
path={file.path}
|
|
40
|
-
meta={file.meta}
|
|
41
|
-
banner={getBanner({ oas, output, config: driver.config })}
|
|
42
|
-
footer={getFooter({ oas, output })}
|
|
43
|
-
>
|
|
44
|
-
<File.Import isTypeOnly name={isZodImport ? 'z' : ['z']} path={importPath} isNameSpace={isZodImport} />
|
|
45
|
-
{imports}
|
|
46
|
-
<Operations name={name} operations={transformedOperations} />
|
|
47
|
-
</File>
|
|
48
|
-
)
|
|
49
|
-
},
|
|
50
|
-
})
|