@kubb/plugin-zod 3.0.0-alpha.2 → 3.0.0-alpha.20
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/README.md +13 -4
- package/dist/chunk-GILKYHDS.cjs +250 -0
- package/dist/chunk-GILKYHDS.cjs.map +1 -0
- package/dist/chunk-KGKZCQKF.js +322 -0
- package/dist/chunk-KGKZCQKF.js.map +1 -0
- package/dist/chunk-RPZWETTK.cjs +329 -0
- package/dist/chunk-RPZWETTK.cjs.map +1 -0
- package/dist/chunk-WIOP5MTW.js +241 -0
- package/dist/chunk-WIOP5MTW.js.map +1 -0
- package/dist/components.cjs +11 -6
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +20 -19
- package/dist/components.d.ts +20 -19
- package/dist/components.js +2 -10
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -137
- package/dist/index.d.ts +4 -137
- package/dist/index.js +3 -8
- package/dist/index.js.map +1 -1
- package/dist/types-BRWHhUnI.d.cts +109 -0
- package/dist/types-BRWHhUnI.d.ts +109 -0
- package/package.json +18 -20
- package/src/components/Operations.tsx +19 -103
- package/src/components/Zod.tsx +66 -0
- package/src/components/index.ts +1 -2
- package/src/generators/__snapshots__/anyof.ts +3 -0
- package/src/generators/__snapshots__/createPet.ts +15 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeAny.ts +13 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +15 -0
- package/src/generators/__snapshots__/deletePet.ts +3 -0
- package/src/generators/__snapshots__/enumNamesType.ts +3 -0
- package/src/generators/__snapshots__/enumNullable.ts +3 -0
- package/src/generators/__snapshots__/enumVarNamesType.ts +3 -0
- package/src/generators/__snapshots__/example.ts +3 -0
- package/src/generators/__snapshots__/getPets.ts +18 -0
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +6 -0
- package/src/generators/__snapshots__/nullableString.ts +3 -0
- package/src/generators/__snapshots__/nullableStringUuid.ts +3 -0
- package/src/generators/__snapshots__/nullableStringWithAnyOf.ts +3 -0
- package/src/generators/__snapshots__/numberValueConst.ts +6 -0
- package/src/generators/__snapshots__/oneof.ts +3 -0
- package/src/generators/__snapshots__/operations.ts +46 -0
- package/src/generators/__snapshots__/optionalPetInfer.ts +5 -0
- package/src/generators/__snapshots__/optionalPetTyped.ts +3 -0
- package/src/generators/__snapshots__/order.ts +3 -0
- package/src/generators/__snapshots__/orderDateTyeString.ts +10 -0
- package/src/generators/__snapshots__/orderDateTypeFalse.ts +3 -0
- package/src/generators/__snapshots__/orderDateTypeString.ts +3 -0
- package/src/generators/__snapshots__/pet.ts +3 -0
- package/src/generators/__snapshots__/petArray.ts +6 -0
- package/src/generators/__snapshots__/petCoercion.ts +3 -0
- package/src/generators/__snapshots__/petTupleObject.ts +6 -0
- package/src/generators/__snapshots__/petWithMapper.ts +3 -0
- package/src/generators/__snapshots__/pets.ts +3 -0
- package/src/generators/__snapshots__/recursive.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +18 -0
- package/src/generators/__snapshots__/stringValueConst.ts +6 -0
- package/src/generators/__snapshots__/uuidSchema.ts +3 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/operationsGenerator.tsx +39 -0
- package/src/generators/zodGenerator.tsx +121 -0
- package/src/parser/index.ts +11 -3
- package/src/plugin.ts +22 -37
- package/src/types.ts +38 -70
- package/dist/Operations-BlQtRP31.d.cts +0 -47
- package/dist/Operations-BlQtRP31.d.ts +0 -47
- package/dist/chunk-KP7GRUCO.cjs +0 -1279
- package/dist/chunk-KP7GRUCO.cjs.map +0 -1
- package/dist/chunk-ORHAR2XI.js +0 -1279
- package/dist/chunk-ORHAR2XI.js.map +0 -1
- package/src/OperationGenerator.tsx +0 -54
- package/src/SchemaGenerator.tsx +0 -31
- package/src/components/OperationSchema.tsx +0 -66
- package/src/components/Schema.tsx +0 -171
- package/src/components/__snapshots__/operations.ts +0 -50
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { Zod, Operations } from './chunk-KGKZCQKF.js';
|
|
2
|
+
import { createReactGenerator, SchemaGenerator, pluginOasName, OperationGenerator, schemaKeywords } from '@kubb/plugin-oas';
|
|
3
|
+
import { Oas } from '@kubb/plugin-oas/components';
|
|
4
|
+
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks';
|
|
5
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
6
|
+
import { useApp, File } from '@kubb/react';
|
|
7
|
+
import { jsxs, jsx } from '@kubb/react/jsx-runtime';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
10
|
+
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
11
|
+
import { renderTemplate } from '@kubb/core/utils';
|
|
12
|
+
|
|
13
|
+
var zodGenerator = createReactGenerator({
|
|
14
|
+
name: "zod",
|
|
15
|
+
Operation({ operation, options }) {
|
|
16
|
+
const { coercion, inferred, typed, mapper } = options;
|
|
17
|
+
const { plugin, pluginManager, mode } = useApp();
|
|
18
|
+
const oas = useOas();
|
|
19
|
+
const { getSchemas, getFile } = useOperationManager();
|
|
20
|
+
const schemaManager = useSchemaManager();
|
|
21
|
+
const file = getFile(operation);
|
|
22
|
+
const schemas = getSchemas(operation);
|
|
23
|
+
const schemaGenerator = new SchemaGenerator(options, {
|
|
24
|
+
oas,
|
|
25
|
+
plugin,
|
|
26
|
+
pluginManager,
|
|
27
|
+
mode,
|
|
28
|
+
override: options.override
|
|
29
|
+
});
|
|
30
|
+
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
31
|
+
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options2 }, i) => {
|
|
32
|
+
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
33
|
+
const optional = !required && !!name.includes("Params");
|
|
34
|
+
const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: schemaKeywords.optional } : void 0].filter(Boolean);
|
|
35
|
+
const imports = schemaManager.getImports(tree);
|
|
36
|
+
const zod = {
|
|
37
|
+
name: schemaManager.getName(name, { type: "function" }),
|
|
38
|
+
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
39
|
+
file: schemaManager.getFile(name)
|
|
40
|
+
};
|
|
41
|
+
const type = {
|
|
42
|
+
name: schemaManager.getName(name, { type: "type", pluginKey: [pluginTsName] }),
|
|
43
|
+
file: schemaManager.getFile(options2.operationName || name, { pluginKey: [pluginTsName], tag: options2.operation?.getTags()[0]?.name })
|
|
44
|
+
};
|
|
45
|
+
return /* @__PURE__ */ jsxs(Oas.Schema, { name, value: schema, tree, children: [
|
|
46
|
+
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root: file.path, path: type.file.path, name: [type.name] }),
|
|
47
|
+
imports.map((imp, index) => /* @__PURE__ */ jsx(File.Import, { root: file.path, path: imp.path, name: imp.name }, index)),
|
|
48
|
+
/* @__PURE__ */ jsx(
|
|
49
|
+
Zod,
|
|
50
|
+
{
|
|
51
|
+
name: zod.name,
|
|
52
|
+
typeName: typed ? type.name : void 0,
|
|
53
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
54
|
+
description,
|
|
55
|
+
tree,
|
|
56
|
+
mapper,
|
|
57
|
+
coercion,
|
|
58
|
+
keysToOmit
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
] }, i);
|
|
62
|
+
};
|
|
63
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
64
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
65
|
+
operationSchemas.map(mapOperationSchema)
|
|
66
|
+
] });
|
|
67
|
+
},
|
|
68
|
+
Schema({ schema, options }) {
|
|
69
|
+
const { coercion, inferred, typed, mapper, importPath } = options;
|
|
70
|
+
const { getName, getFile, getImports } = useSchemaManager();
|
|
71
|
+
const {
|
|
72
|
+
plugin: {
|
|
73
|
+
options: { output }
|
|
74
|
+
}
|
|
75
|
+
} = useApp();
|
|
76
|
+
const imports = getImports(schema.tree);
|
|
77
|
+
const zod = {
|
|
78
|
+
name: getName(schema.name, { type: "function" }),
|
|
79
|
+
inferTypeName: getName(schema.name, { type: "type" }),
|
|
80
|
+
file: getFile(schema.name)
|
|
81
|
+
};
|
|
82
|
+
const type = {
|
|
83
|
+
name: getName(schema.name, { type: "type", pluginKey: [pluginTsName] }),
|
|
84
|
+
file: getFile(schema.name, { pluginKey: [pluginTsName] })
|
|
85
|
+
};
|
|
86
|
+
return /* @__PURE__ */ jsxs(File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
87
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: importPath }),
|
|
88
|
+
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
|
|
89
|
+
imports.map((imp, index) => /* @__PURE__ */ jsx(File.Import, { root: zod.file.path, path: imp.path, name: imp.name }, index)),
|
|
90
|
+
/* @__PURE__ */ jsx(
|
|
91
|
+
Zod,
|
|
92
|
+
{
|
|
93
|
+
name: zod.name,
|
|
94
|
+
typeName: typed ? type.name : void 0,
|
|
95
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
96
|
+
description: schema.value.description,
|
|
97
|
+
tree: schema.tree,
|
|
98
|
+
mapper,
|
|
99
|
+
coercion
|
|
100
|
+
}
|
|
101
|
+
)
|
|
102
|
+
] });
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
var pluginZodName = "plugin-zod";
|
|
106
|
+
var pluginZod = createPlugin((options) => {
|
|
107
|
+
const {
|
|
108
|
+
output = { path: "zod" },
|
|
109
|
+
group,
|
|
110
|
+
exclude = [],
|
|
111
|
+
include,
|
|
112
|
+
override = [],
|
|
113
|
+
transformers = {},
|
|
114
|
+
dateType = "string",
|
|
115
|
+
unknownType = "any",
|
|
116
|
+
typed = false,
|
|
117
|
+
mapper = {},
|
|
118
|
+
operations = false,
|
|
119
|
+
importPath = "zod",
|
|
120
|
+
coercion = false,
|
|
121
|
+
inferred = false
|
|
122
|
+
} = options;
|
|
123
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
124
|
+
return {
|
|
125
|
+
name: pluginZodName,
|
|
126
|
+
options: {
|
|
127
|
+
output: {
|
|
128
|
+
exportType: "barrelNamed",
|
|
129
|
+
...output
|
|
130
|
+
},
|
|
131
|
+
extName: output.extName,
|
|
132
|
+
transformers,
|
|
133
|
+
include,
|
|
134
|
+
exclude,
|
|
135
|
+
override,
|
|
136
|
+
typed,
|
|
137
|
+
dateType,
|
|
138
|
+
unknownType,
|
|
139
|
+
mapper,
|
|
140
|
+
importPath,
|
|
141
|
+
coercion,
|
|
142
|
+
operations,
|
|
143
|
+
inferred
|
|
144
|
+
},
|
|
145
|
+
pre: [pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
|
|
146
|
+
resolvePath(baseName, pathMode, options2) {
|
|
147
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
148
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
149
|
+
if (mode === "single") {
|
|
150
|
+
return path.resolve(root, output.path);
|
|
151
|
+
}
|
|
152
|
+
if (options2?.tag && group?.type === "tag") {
|
|
153
|
+
const tag = camelCase(options2.tag);
|
|
154
|
+
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
155
|
+
}
|
|
156
|
+
return path.resolve(root, output.path, baseName);
|
|
157
|
+
},
|
|
158
|
+
resolveName(name, type) {
|
|
159
|
+
let resolvedName = camelCase(name, {
|
|
160
|
+
suffix: type ? "schema" : void 0,
|
|
161
|
+
isFile: type === "file"
|
|
162
|
+
});
|
|
163
|
+
if (type === "type") {
|
|
164
|
+
resolvedName = pascalCase(resolvedName);
|
|
165
|
+
}
|
|
166
|
+
if (type) {
|
|
167
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
168
|
+
}
|
|
169
|
+
return resolvedName;
|
|
170
|
+
},
|
|
171
|
+
async buildStart() {
|
|
172
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
173
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
174
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
175
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
176
|
+
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
177
|
+
oas,
|
|
178
|
+
pluginManager: this.pluginManager,
|
|
179
|
+
plugin: this.plugin,
|
|
180
|
+
contentType: swaggerPlugin.context.contentType,
|
|
181
|
+
include: void 0,
|
|
182
|
+
override,
|
|
183
|
+
mode,
|
|
184
|
+
output: output.path
|
|
185
|
+
});
|
|
186
|
+
const schemaFiles = await schemaGenerator.build(...[zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean));
|
|
187
|
+
await this.addFile(...schemaFiles);
|
|
188
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
189
|
+
oas,
|
|
190
|
+
pluginManager: this.pluginManager,
|
|
191
|
+
plugin: this.plugin,
|
|
192
|
+
contentType: swaggerPlugin.context.contentType,
|
|
193
|
+
exclude,
|
|
194
|
+
include,
|
|
195
|
+
override,
|
|
196
|
+
mode
|
|
197
|
+
});
|
|
198
|
+
const operationFiles = await operationGenerator.build(...[zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean));
|
|
199
|
+
await this.addFile(...operationFiles);
|
|
200
|
+
if (this.config.output.exportType) {
|
|
201
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
202
|
+
root,
|
|
203
|
+
output,
|
|
204
|
+
files: this.fileManager.files,
|
|
205
|
+
meta: {
|
|
206
|
+
pluginKey: this.plugin.key
|
|
207
|
+
},
|
|
208
|
+
logger: this.logger
|
|
209
|
+
});
|
|
210
|
+
await this.addFile(...barrelFiles);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
var operationsGenerator = createReactGenerator({
|
|
216
|
+
name: "operations",
|
|
217
|
+
Operations({ operations }) {
|
|
218
|
+
const {
|
|
219
|
+
pluginManager,
|
|
220
|
+
plugin: {
|
|
221
|
+
options: { output }
|
|
222
|
+
}
|
|
223
|
+
} = useApp();
|
|
224
|
+
const { getFile, groupSchemasByName } = useOperationManager();
|
|
225
|
+
const name = "operations";
|
|
226
|
+
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: [pluginZodName] });
|
|
227
|
+
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
228
|
+
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
229
|
+
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
230
|
+
return /* @__PURE__ */ jsx(File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
231
|
+
}).filter(Boolean);
|
|
232
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
233
|
+
imports,
|
|
234
|
+
/* @__PURE__ */ jsx(Operations, { name, operations: transformedOperations })
|
|
235
|
+
] });
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
export { operationsGenerator, pluginZod, pluginZodName, zodGenerator };
|
|
240
|
+
//# sourceMappingURL=chunk-WIOP5MTW.js.map
|
|
241
|
+
//# sourceMappingURL=chunk-WIOP5MTW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/plugin.ts","../src/generators/operationsGenerator.tsx"],"names":["options","pluginTsName","SchemaGenerator","createReactGenerator","useApp","useOperationManager","jsx","File","jsxs"],"mappings":";;;;;;;;;;;;AAQO,IAAM,eAAe,oBAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,KAAA,EAAO,QAAW,GAAA,OAAA,CAAA;AAE9C,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAAS,MAAkB,EAAA,CAAA;AAC1D,IAAA,MAAM,MAAM,MAAO,EAAA,CAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAQ,EAAA,GAAI,mBAAoB,EAAA,CAAA;AACpD,IAAA,MAAM,gBAAgB,gBAAiB,EAAA,CAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAI,eAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OAAQ,CAAA,QAAA;AAAA,KACnB,CAAA,CAAA;AAED,IAAA,MAAM,mBAAmB,CAAC,OAAA,CAAQ,YAAY,OAAQ,CAAA,WAAA,EAAa,QAAQ,YAAc,EAAA,OAAA,CAAQ,WAAa,EAAA,OAAA,CAAQ,SAAS,OAAQ,CAAA,QAAQ,EAC5I,IAAK,EAAA,CACL,OAAO,OAAO,CAAA,CAAA;AAEjB,IAAM,MAAA,kBAAA,GAAqB,CAAC,EAAE,IAAM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;AAAA,GAEJ;AACF,CAAC","file":"chunk-WIOP5MTW.js","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion, inferred, typed, mapper } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile } = useOperationManager()\n const schemaManager = useSchemaManager()\n\n const file = getFile(operation)\n const schemas = getSchemas(operation)\n const schemaGenerator = new SchemaGenerator(options, {\n oas,\n plugin,\n pluginManager,\n mode,\n override: options.override,\n })\n\n const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response]\n .flat()\n .filter(Boolean)\n\n const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options }: OperationSchemaType, i: number) => {\n // hack so Params can be optional when needed\n const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required\n const optional = !required && !!name.includes('Params')\n const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: schemaKeywords.optional } : undefined].filter(Boolean)\n const imports = schemaManager.getImports(tree)\n\n const zod = {\n name: schemaManager.getName(name, { type: 'function' }),\n inferTypeName: schemaManager.getName(name, { type: 'type' }),\n file: schemaManager.getFile(name),\n }\n\n const type = {\n name: schemaManager.getName(name, { type: 'type', pluginKey: [pluginTsName] }),\n file: schemaManager.getFile(options.operationName || name, { pluginKey: [pluginTsName], tag: options.operation?.getTags()[0]?.name }),\n }\n\n return (\n <Oas.Schema key={i} name={name} value={schema} tree={tree}>\n {typed && <File.Import isTypeOnly root={file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={file.path} path={imp.path} name={imp.name} />\n ))}\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={description}\n tree={tree}\n mapper={mapper}\n coercion={coercion}\n keysToOmit={keysToOmit}\n />\n </Oas.Schema>\n )\n }\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={plugin.options.output?.banner} footer={plugin.options.output?.footer}>\n <File.Import name={['z']} path={plugin.options.importPath} />\n {operationSchemas.map(mapOperationSchema)}\n </File>\n )\n },\n Schema({ schema, options }) {\n const { coercion, inferred, typed, mapper, importPath } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n\n const imports = getImports(schema.tree)\n\n const zod = {\n name: getName(schema.name, { type: 'function' }),\n inferTypeName: getName(schema.name, { type: 'type' }),\n file: getFile(schema.name),\n }\n\n const type = {\n name: getName(schema.name, { type: 'type', pluginKey: [pluginTsName] }),\n file: getFile(schema.name, { pluginKey: [pluginTsName] }),\n }\n\n return (\n <File baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={output?.banner} footer={output?.footer}>\n <File.Import name={['z']} path={importPath} />\n {typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n mapper={mapper}\n coercion={coercion}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n } = options\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginZodName,\n options: {\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n extName: output.extName,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n },\n pre: [pluginOasName, typed ? pluginTsName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...[zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean))\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...[zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean))\n await this.addFile(...operationFiles)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport { pluginZodName } from '../plugin.ts'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n options: { output },\n },\n } = useApp<PluginZod>()\n const { getFile, groupSchemasByName } = useOperationManager()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: [pluginZodName] })\n\n const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: 'function' }) }))\n\n const imports = Object.entries(transformedOperations)\n .map(([key, { data, operation }]) => {\n const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean)\n\n return <File.Import key={key} name={names} root={file.path} path={getFile(operation).path} />\n })\n .filter(Boolean)\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={output?.banner} footer={output?.footer}>\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|
package/dist/components.cjs
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkRPZWETTK_cjs = require('./chunk-RPZWETTK.cjs');
|
|
3
4
|
|
|
4
5
|
|
|
5
|
-
var _chunkKP7GRUCOcjs = require('./chunk-KP7GRUCO.cjs');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
Object.defineProperty(exports, "Operations", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkRPZWETTK_cjs.Operations; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "Zod", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkRPZWETTK_cjs.Zod; }
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=components.cjs.map
|
|
11
16
|
//# sourceMappingURL=components.cjs.map
|
package/dist/components.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"components.cjs"}
|
package/dist/components.d.cts
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import '@kubb/
|
|
4
|
-
import '@kubb/
|
|
1
|
+
import { SchemaNames } from '@kubb/plugin-oas/hooks';
|
|
2
|
+
import { Operation } from '@kubb/oas';
|
|
3
|
+
import { KubbNode } from '@kubb/react/types';
|
|
4
|
+
import { Schema } from '@kubb/plugin-oas';
|
|
5
|
+
import { P as PluginZod } from './types-BRWHhUnI.cjs';
|
|
6
|
+
import '@kubb/core';
|
|
5
7
|
|
|
6
8
|
type Props$1 = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
name: string;
|
|
10
|
+
operations: Array<{
|
|
11
|
+
operation: Operation;
|
|
12
|
+
data: SchemaNames;
|
|
13
|
+
}>;
|
|
9
14
|
};
|
|
10
|
-
declare function
|
|
11
|
-
declare namespace OperationSchema {
|
|
12
|
-
var File: ({}: FileProps$1) => ReactNode;
|
|
13
|
-
}
|
|
14
|
-
type FileProps$1 = {};
|
|
15
|
+
declare function Operations({ name, operations }: Props$1): KubbNode;
|
|
15
16
|
|
|
16
17
|
type Props = {
|
|
18
|
+
name: string;
|
|
19
|
+
typeName?: string;
|
|
20
|
+
inferTypeName?: string;
|
|
21
|
+
tree: Array<Schema>;
|
|
17
22
|
description?: string;
|
|
18
|
-
|
|
23
|
+
coercion: PluginZod['resolvedOptions']['coercion'];
|
|
24
|
+
mapper: PluginZod['resolvedOptions']['mapper'];
|
|
19
25
|
keysToOmit?: string[];
|
|
20
26
|
};
|
|
21
|
-
declare function
|
|
22
|
-
declare namespace Schema {
|
|
23
|
-
var File: ({}: FileProps) => ReactNode;
|
|
24
|
-
var Imports: () => ReactNode;
|
|
25
|
-
}
|
|
26
|
-
type FileProps = {};
|
|
27
|
+
declare function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, keysToOmit, description }: Props): KubbNode;
|
|
27
28
|
|
|
28
|
-
export {
|
|
29
|
+
export { Operations, Zod };
|
package/dist/components.d.ts
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import '@kubb/
|
|
4
|
-
import '@kubb/
|
|
1
|
+
import { SchemaNames } from '@kubb/plugin-oas/hooks';
|
|
2
|
+
import { Operation } from '@kubb/oas';
|
|
3
|
+
import { KubbNode } from '@kubb/react/types';
|
|
4
|
+
import { Schema } from '@kubb/plugin-oas';
|
|
5
|
+
import { P as PluginZod } from './types-BRWHhUnI.js';
|
|
6
|
+
import '@kubb/core';
|
|
5
7
|
|
|
6
8
|
type Props$1 = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
name: string;
|
|
10
|
+
operations: Array<{
|
|
11
|
+
operation: Operation;
|
|
12
|
+
data: SchemaNames;
|
|
13
|
+
}>;
|
|
9
14
|
};
|
|
10
|
-
declare function
|
|
11
|
-
declare namespace OperationSchema {
|
|
12
|
-
var File: ({}: FileProps$1) => ReactNode;
|
|
13
|
-
}
|
|
14
|
-
type FileProps$1 = {};
|
|
15
|
+
declare function Operations({ name, operations }: Props$1): KubbNode;
|
|
15
16
|
|
|
16
17
|
type Props = {
|
|
18
|
+
name: string;
|
|
19
|
+
typeName?: string;
|
|
20
|
+
inferTypeName?: string;
|
|
21
|
+
tree: Array<Schema>;
|
|
17
22
|
description?: string;
|
|
18
|
-
|
|
23
|
+
coercion: PluginZod['resolvedOptions']['coercion'];
|
|
24
|
+
mapper: PluginZod['resolvedOptions']['mapper'];
|
|
19
25
|
keysToOmit?: string[];
|
|
20
26
|
};
|
|
21
|
-
declare function
|
|
22
|
-
declare namespace Schema {
|
|
23
|
-
var File: ({}: FileProps) => ReactNode;
|
|
24
|
-
var Imports: () => ReactNode;
|
|
25
|
-
}
|
|
26
|
-
type FileProps = {};
|
|
27
|
+
declare function Zod({ name, typeName, tree, inferTypeName, mapper, coercion, keysToOmit, description }: Props): KubbNode;
|
|
27
28
|
|
|
28
|
-
export {
|
|
29
|
+
export { Operations, Zod };
|
package/dist/components.js
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Operations,
|
|
4
|
-
Schema
|
|
5
|
-
} from "./chunk-ORHAR2XI.js";
|
|
6
|
-
export {
|
|
7
|
-
OperationSchema,
|
|
8
|
-
Operations,
|
|
9
|
-
Schema
|
|
10
|
-
};
|
|
1
|
+
export { Operations, Zod } from './chunk-KGKZCQKF.js';
|
|
2
|
+
//# sourceMappingURL=components.js.map
|
|
11
3
|
//# sourceMappingURL=components.js.map
|
package/dist/components.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"components.js"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkGILKYHDS_cjs = require('./chunk-GILKYHDS.cjs');
|
|
4
|
+
require('./chunk-RPZWETTK.cjs');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Object.defineProperty(exports, "operationsGenerator", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkGILKYHDS_cjs.operationsGenerator; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "zodGenerator", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkGILKYHDS_cjs.zodGenerator; }
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=generators.cjs.map
|
|
17
|
+
//# sourceMappingURL=generators.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.cjs"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginZod } from './types-BRWHhUnI.cjs';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
import '@kubb/oas';
|
|
5
|
+
|
|
6
|
+
declare const zodGenerator: _kubb_plugin_oas.Generator<PluginZod>;
|
|
7
|
+
|
|
8
|
+
declare const operationsGenerator: _kubb_plugin_oas.Generator<PluginZod>;
|
|
9
|
+
|
|
10
|
+
export { operationsGenerator, zodGenerator };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as _kubb_plugin_oas from '@kubb/plugin-oas';
|
|
2
|
+
import { P as PluginZod } from './types-BRWHhUnI.js';
|
|
3
|
+
import '@kubb/core';
|
|
4
|
+
import '@kubb/oas';
|
|
5
|
+
|
|
6
|
+
declare const zodGenerator: _kubb_plugin_oas.Generator<PluginZod>;
|
|
7
|
+
|
|
8
|
+
declare const operationsGenerator: _kubb_plugin_oas.Generator<PluginZod>;
|
|
9
|
+
|
|
10
|
+
export { operationsGenerator, zodGenerator };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"generators.js"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkGILKYHDS_cjs = require('./chunk-GILKYHDS.cjs');
|
|
4
|
+
require('./chunk-RPZWETTK.cjs');
|
|
3
5
|
|
|
4
|
-
var _chunkKP7GRUCOcjs = require('./chunk-KP7GRUCO.cjs');
|
|
5
6
|
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
Object.defineProperty(exports, "pluginZod", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () { return chunkGILKYHDS_cjs.pluginZod; }
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "pluginZodName", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return chunkGILKYHDS_cjs.pluginZodName; }
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
9
17
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|