@kubb/plugin-zod 3.4.5 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-X3RBLACB.js → chunk-EWUPFTK7.js} +23 -131
- package/dist/chunk-EWUPFTK7.js.map +1 -0
- package/dist/{chunk-7AQ52OFH.cjs → chunk-LC2FWVGP.cjs} +21 -135
- package/dist/chunk-LC2FWVGP.cjs.map +1 -0
- package/dist/components.d.cts +1 -1
- package/dist/components.d.ts +1 -1
- package/dist/generators.cjs +3 -3
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/index.cjs +128 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +127 -1
- package/dist/index.js.map +1 -1
- package/dist/{types-D-ojxg4G.d.cts → types-BS3p0dlS.d.cts} +3 -3
- package/dist/{types-D-ojxg4G.d.ts → types-BS3p0dlS.d.ts} +3 -3
- package/package.json +10 -10
- package/src/generators/operationsGenerator.tsx +4 -3
- package/src/generators/zodGenerator.tsx +10 -2
- package/src/types.ts +3 -3
- package/dist/chunk-7AQ52OFH.cjs.map +0 -1
- package/dist/chunk-X3RBLACB.js.map +0 -1
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { Zod, Operations } from './chunk-ZOYMIBKT.js';
|
|
2
|
-
import { createReactGenerator, SchemaGenerator,
|
|
2
|
+
import { createReactGenerator, SchemaGenerator, schemaKeywords } from '@kubb/plugin-oas';
|
|
3
3
|
import { Oas } from '@kubb/plugin-oas/components';
|
|
4
4
|
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks';
|
|
5
|
+
import { getBanner, getFooter } from '@kubb/plugin-oas/utils';
|
|
5
6
|
import { pluginTsName } from '@kubb/plugin-ts';
|
|
6
7
|
import { useApp, File } from '@kubb/react';
|
|
7
8
|
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
9
|
|
|
12
10
|
var zodGenerator = createReactGenerator({
|
|
13
11
|
name: "zod",
|
|
@@ -61,10 +59,20 @@ var zodGenerator = createReactGenerator({
|
|
|
61
59
|
)
|
|
62
60
|
] }, i);
|
|
63
61
|
};
|
|
64
|
-
return /* @__PURE__ */ jsxs(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
return /* @__PURE__ */ jsxs(
|
|
63
|
+
File,
|
|
64
|
+
{
|
|
65
|
+
baseName: file.baseName,
|
|
66
|
+
path: file.path,
|
|
67
|
+
meta: file.meta,
|
|
68
|
+
banner: getBanner({ oas, output: plugin.options.output }),
|
|
69
|
+
footer: getFooter({ oas, output: plugin.options.output }),
|
|
70
|
+
children: [
|
|
71
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
72
|
+
operationSchemas.map(mapOperationSchema)
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
);
|
|
68
76
|
},
|
|
69
77
|
Schema({ schema, options }) {
|
|
70
78
|
const { coercion, inferred, typed, mapper, importPath } = options;
|
|
@@ -74,6 +82,7 @@ var zodGenerator = createReactGenerator({
|
|
|
74
82
|
options: { output }
|
|
75
83
|
}
|
|
76
84
|
} = useApp();
|
|
85
|
+
const oas = useOas();
|
|
77
86
|
const imports = getImports(schema.tree);
|
|
78
87
|
const zod = {
|
|
79
88
|
name: getName(schema.name, { type: "function" }),
|
|
@@ -84,7 +93,7 @@ var zodGenerator = createReactGenerator({
|
|
|
84
93
|
name: getName(schema.name, { type: "type", pluginKey: [pluginTsName] }),
|
|
85
94
|
file: getFile(schema.name, { pluginKey: [pluginTsName] })
|
|
86
95
|
};
|
|
87
|
-
return /* @__PURE__ */ jsxs(File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: output
|
|
96
|
+
return /* @__PURE__ */ jsxs(File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: getBanner({ oas, output }), footer: getFooter({ oas, output }), children: [
|
|
88
97
|
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: importPath }),
|
|
89
98
|
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
|
|
90
99
|
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, path: "@kubb/plugin-zod/utils", name: ["ToZod"] }),
|
|
@@ -104,124 +113,6 @@ var zodGenerator = createReactGenerator({
|
|
|
104
113
|
] });
|
|
105
114
|
}
|
|
106
115
|
});
|
|
107
|
-
var pluginZodName = "plugin-zod";
|
|
108
|
-
var pluginZod = createPlugin((options) => {
|
|
109
|
-
const {
|
|
110
|
-
output = { path: "zod", barrelType: "named" },
|
|
111
|
-
group,
|
|
112
|
-
exclude = [],
|
|
113
|
-
include,
|
|
114
|
-
override = [],
|
|
115
|
-
transformers = {},
|
|
116
|
-
dateType = "string",
|
|
117
|
-
unknownType = "any",
|
|
118
|
-
typed = false,
|
|
119
|
-
mapper = {},
|
|
120
|
-
operations = false,
|
|
121
|
-
importPath = "zod",
|
|
122
|
-
coercion = false,
|
|
123
|
-
inferred = false,
|
|
124
|
-
generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean)
|
|
125
|
-
} = options;
|
|
126
|
-
return {
|
|
127
|
-
name: pluginZodName,
|
|
128
|
-
options: {
|
|
129
|
-
output,
|
|
130
|
-
transformers,
|
|
131
|
-
include,
|
|
132
|
-
exclude,
|
|
133
|
-
override,
|
|
134
|
-
typed,
|
|
135
|
-
dateType,
|
|
136
|
-
unknownType,
|
|
137
|
-
mapper,
|
|
138
|
-
importPath,
|
|
139
|
-
coercion,
|
|
140
|
-
operations,
|
|
141
|
-
inferred,
|
|
142
|
-
group
|
|
143
|
-
},
|
|
144
|
-
pre: [pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
|
|
145
|
-
resolvePath(baseName, pathMode, options2) {
|
|
146
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
147
|
-
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
148
|
-
if (mode === "single") {
|
|
149
|
-
return path.resolve(root, output.path);
|
|
150
|
-
}
|
|
151
|
-
if (group && (options2?.group?.path || options2?.group?.tag)) {
|
|
152
|
-
const groupName = group?.name ? group.name : (ctx) => {
|
|
153
|
-
if (group?.type === "path") {
|
|
154
|
-
return `${ctx.group.split("/")[1]}`;
|
|
155
|
-
}
|
|
156
|
-
return `${camelCase(ctx.group)}Controller`;
|
|
157
|
-
};
|
|
158
|
-
return path.resolve(
|
|
159
|
-
root,
|
|
160
|
-
output.path,
|
|
161
|
-
groupName({
|
|
162
|
-
group: group.type === "path" ? options2.group.path : options2.group.tag
|
|
163
|
-
}),
|
|
164
|
-
baseName
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
return path.resolve(root, output.path, baseName);
|
|
168
|
-
},
|
|
169
|
-
resolveName(name, type) {
|
|
170
|
-
let resolvedName = camelCase(name, {
|
|
171
|
-
suffix: type ? "schema" : void 0,
|
|
172
|
-
isFile: type === "file"
|
|
173
|
-
});
|
|
174
|
-
if (type === "type") {
|
|
175
|
-
resolvedName = pascalCase(resolvedName);
|
|
176
|
-
}
|
|
177
|
-
if (type) {
|
|
178
|
-
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
179
|
-
}
|
|
180
|
-
return resolvedName;
|
|
181
|
-
},
|
|
182
|
-
async buildStart() {
|
|
183
|
-
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
184
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
185
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
186
|
-
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
187
|
-
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
188
|
-
oas,
|
|
189
|
-
pluginManager: this.pluginManager,
|
|
190
|
-
plugin: this.plugin,
|
|
191
|
-
contentType: swaggerPlugin.context.contentType,
|
|
192
|
-
include: void 0,
|
|
193
|
-
override,
|
|
194
|
-
mode,
|
|
195
|
-
output: output.path
|
|
196
|
-
});
|
|
197
|
-
const schemaFiles = await schemaGenerator.build(...generators);
|
|
198
|
-
await this.addFile(...schemaFiles);
|
|
199
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
200
|
-
oas,
|
|
201
|
-
pluginManager: this.pluginManager,
|
|
202
|
-
plugin: this.plugin,
|
|
203
|
-
contentType: swaggerPlugin.context.contentType,
|
|
204
|
-
exclude,
|
|
205
|
-
include,
|
|
206
|
-
override,
|
|
207
|
-
mode
|
|
208
|
-
});
|
|
209
|
-
const operationFiles = await operationGenerator.build(...generators);
|
|
210
|
-
await this.addFile(...operationFiles);
|
|
211
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
212
|
-
type: output.barrelType ?? "named",
|
|
213
|
-
root,
|
|
214
|
-
output,
|
|
215
|
-
files: this.fileManager.files,
|
|
216
|
-
meta: {
|
|
217
|
-
pluginKey: this.plugin.key
|
|
218
|
-
},
|
|
219
|
-
logger: this.logger
|
|
220
|
-
});
|
|
221
|
-
await this.addFile(...barrelFiles);
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
});
|
|
225
116
|
var operationsGenerator = createReactGenerator({
|
|
226
117
|
name: "operations",
|
|
227
118
|
Operations({ operations }) {
|
|
@@ -232,6 +123,7 @@ var operationsGenerator = createReactGenerator({
|
|
|
232
123
|
options: { output }
|
|
233
124
|
}
|
|
234
125
|
} = useApp();
|
|
126
|
+
const oas = useOas();
|
|
235
127
|
const { getFile, groupSchemasByName } = useOperationManager();
|
|
236
128
|
const name = "operations";
|
|
237
129
|
const file = pluginManager.getFile({ name, extname: ".ts", pluginKey });
|
|
@@ -240,13 +132,13 @@ var operationsGenerator = createReactGenerator({
|
|
|
240
132
|
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
241
133
|
return /* @__PURE__ */ jsx(File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
242
134
|
}).filter(Boolean);
|
|
243
|
-
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output
|
|
135
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: getBanner({ oas, output }), footer: getFooter({ oas, output }), children: [
|
|
244
136
|
imports,
|
|
245
137
|
/* @__PURE__ */ jsx(Operations, { name, operations: transformedOperations })
|
|
246
138
|
] });
|
|
247
139
|
}
|
|
248
140
|
});
|
|
249
141
|
|
|
250
|
-
export { operationsGenerator,
|
|
251
|
-
//# sourceMappingURL=chunk-
|
|
252
|
-
//# sourceMappingURL=chunk-
|
|
142
|
+
export { operationsGenerator, zodGenerator };
|
|
143
|
+
//# sourceMappingURL=chunk-EWUPFTK7.js.map
|
|
144
|
+
//# sourceMappingURL=chunk-EWUPFTK7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"names":["options","createReactGenerator","useApp","useOas","useOperationManager","jsx","File","jsxs","getBanner","getFooter"],"mappings":";;;;;;;;;AASO,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;AAE9C,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAAS,MAAkB,EAAA;AAC1D,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,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,CAAA,EAAG,MAAQC,EAAAA,SAAAA,CAAU,EAAE,GAAA,EAAK,MAAO,EAAC,CACnI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDJ,GAAAA,CAAC,UAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA;AAAA,KAC7D,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-EWUPFTK7.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 { 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, inferred, typed, mapper } = 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, 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 const group = options.operation ? getGroup(options.operation) : undefined\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], group }),\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 {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output })}\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 } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n plugin: {\n options: { output },\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 baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>\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, 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 { 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 baseName={file.baseName} path={file.path} meta={file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|
|
@@ -4,16 +4,10 @@ var chunkVZK7NWPL_cjs = require('./chunk-VZK7NWPL.cjs');
|
|
|
4
4
|
var pluginOas = require('@kubb/plugin-oas');
|
|
5
5
|
var components = require('@kubb/plugin-oas/components');
|
|
6
6
|
var hooks = require('@kubb/plugin-oas/hooks');
|
|
7
|
+
var utils = require('@kubb/plugin-oas/utils');
|
|
7
8
|
var pluginTs = require('@kubb/plugin-ts');
|
|
8
9
|
var react = require('@kubb/react');
|
|
9
10
|
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
10
|
-
var path = require('path');
|
|
11
|
-
var core = require('@kubb/core');
|
|
12
|
-
var transformers = require('@kubb/core/transformers');
|
|
13
|
-
|
|
14
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
|
|
16
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
17
11
|
|
|
18
12
|
var zodGenerator = pluginOas.createReactGenerator({
|
|
19
13
|
name: "zod",
|
|
@@ -67,10 +61,20 @@ var zodGenerator = pluginOas.createReactGenerator({
|
|
|
67
61
|
)
|
|
68
62
|
] }, i);
|
|
69
63
|
};
|
|
70
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
64
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
65
|
+
react.File,
|
|
66
|
+
{
|
|
67
|
+
baseName: file.baseName,
|
|
68
|
+
path: file.path,
|
|
69
|
+
meta: file.meta,
|
|
70
|
+
banner: utils.getBanner({ oas, output: plugin.options.output }),
|
|
71
|
+
footer: utils.getFooter({ oas, output: plugin.options.output }),
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
74
|
+
operationSchemas.map(mapOperationSchema)
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
);
|
|
74
78
|
},
|
|
75
79
|
Schema({ schema, options }) {
|
|
76
80
|
const { coercion, inferred, typed, mapper, importPath } = options;
|
|
@@ -80,6 +84,7 @@ var zodGenerator = pluginOas.createReactGenerator({
|
|
|
80
84
|
options: { output }
|
|
81
85
|
}
|
|
82
86
|
} = react.useApp();
|
|
87
|
+
const oas = hooks.useOas();
|
|
83
88
|
const imports = getImports(schema.tree);
|
|
84
89
|
const zod = {
|
|
85
90
|
name: getName(schema.name, { type: "function" }),
|
|
@@ -90,7 +95,7 @@ var zodGenerator = pluginOas.createReactGenerator({
|
|
|
90
95
|
name: getName(schema.name, { type: "type", pluginKey: [pluginTs.pluginTsName] }),
|
|
91
96
|
file: getFile(schema.name, { pluginKey: [pluginTs.pluginTsName] })
|
|
92
97
|
};
|
|
93
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: output
|
|
98
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: utils.getBanner({ oas, output }), footer: utils.getFooter({ oas, output }), children: [
|
|
94
99
|
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: importPath }),
|
|
95
100
|
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
|
|
96
101
|
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, path: "@kubb/plugin-zod/utils", name: ["ToZod"] }),
|
|
@@ -110,124 +115,6 @@ var zodGenerator = pluginOas.createReactGenerator({
|
|
|
110
115
|
] });
|
|
111
116
|
}
|
|
112
117
|
});
|
|
113
|
-
var pluginZodName = "plugin-zod";
|
|
114
|
-
var pluginZod = core.createPlugin((options) => {
|
|
115
|
-
const {
|
|
116
|
-
output = { path: "zod", barrelType: "named" },
|
|
117
|
-
group,
|
|
118
|
-
exclude = [],
|
|
119
|
-
include,
|
|
120
|
-
override = [],
|
|
121
|
-
transformers: transformers$1 = {},
|
|
122
|
-
dateType = "string",
|
|
123
|
-
unknownType = "any",
|
|
124
|
-
typed = false,
|
|
125
|
-
mapper = {},
|
|
126
|
-
operations = false,
|
|
127
|
-
importPath = "zod",
|
|
128
|
-
coercion = false,
|
|
129
|
-
inferred = false,
|
|
130
|
-
generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean)
|
|
131
|
-
} = options;
|
|
132
|
-
return {
|
|
133
|
-
name: pluginZodName,
|
|
134
|
-
options: {
|
|
135
|
-
output,
|
|
136
|
-
transformers: transformers$1,
|
|
137
|
-
include,
|
|
138
|
-
exclude,
|
|
139
|
-
override,
|
|
140
|
-
typed,
|
|
141
|
-
dateType,
|
|
142
|
-
unknownType,
|
|
143
|
-
mapper,
|
|
144
|
-
importPath,
|
|
145
|
-
coercion,
|
|
146
|
-
operations,
|
|
147
|
-
inferred,
|
|
148
|
-
group
|
|
149
|
-
},
|
|
150
|
-
pre: [pluginOas.pluginOasName, typed ? pluginTs.pluginTsName : void 0].filter(Boolean),
|
|
151
|
-
resolvePath(baseName, pathMode, options2) {
|
|
152
|
-
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
153
|
-
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
154
|
-
if (mode === "single") {
|
|
155
|
-
return path__default.default.resolve(root, output.path);
|
|
156
|
-
}
|
|
157
|
-
if (group && (options2?.group?.path || options2?.group?.tag)) {
|
|
158
|
-
const groupName = group?.name ? group.name : (ctx) => {
|
|
159
|
-
if (group?.type === "path") {
|
|
160
|
-
return `${ctx.group.split("/")[1]}`;
|
|
161
|
-
}
|
|
162
|
-
return `${transformers.camelCase(ctx.group)}Controller`;
|
|
163
|
-
};
|
|
164
|
-
return path__default.default.resolve(
|
|
165
|
-
root,
|
|
166
|
-
output.path,
|
|
167
|
-
groupName({
|
|
168
|
-
group: group.type === "path" ? options2.group.path : options2.group.tag
|
|
169
|
-
}),
|
|
170
|
-
baseName
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
return path__default.default.resolve(root, output.path, baseName);
|
|
174
|
-
},
|
|
175
|
-
resolveName(name, type) {
|
|
176
|
-
let resolvedName = transformers.camelCase(name, {
|
|
177
|
-
suffix: type ? "schema" : void 0,
|
|
178
|
-
isFile: type === "file"
|
|
179
|
-
});
|
|
180
|
-
if (type === "type") {
|
|
181
|
-
resolvedName = transformers.pascalCase(resolvedName);
|
|
182
|
-
}
|
|
183
|
-
if (type) {
|
|
184
|
-
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
185
|
-
}
|
|
186
|
-
return resolvedName;
|
|
187
|
-
},
|
|
188
|
-
async buildStart() {
|
|
189
|
-
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
190
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
191
|
-
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
192
|
-
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
193
|
-
const schemaGenerator = new pluginOas.SchemaGenerator(this.plugin.options, {
|
|
194
|
-
oas,
|
|
195
|
-
pluginManager: this.pluginManager,
|
|
196
|
-
plugin: this.plugin,
|
|
197
|
-
contentType: swaggerPlugin.context.contentType,
|
|
198
|
-
include: void 0,
|
|
199
|
-
override,
|
|
200
|
-
mode,
|
|
201
|
-
output: output.path
|
|
202
|
-
});
|
|
203
|
-
const schemaFiles = await schemaGenerator.build(...generators);
|
|
204
|
-
await this.addFile(...schemaFiles);
|
|
205
|
-
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
206
|
-
oas,
|
|
207
|
-
pluginManager: this.pluginManager,
|
|
208
|
-
plugin: this.plugin,
|
|
209
|
-
contentType: swaggerPlugin.context.contentType,
|
|
210
|
-
exclude,
|
|
211
|
-
include,
|
|
212
|
-
override,
|
|
213
|
-
mode
|
|
214
|
-
});
|
|
215
|
-
const operationFiles = await operationGenerator.build(...generators);
|
|
216
|
-
await this.addFile(...operationFiles);
|
|
217
|
-
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
218
|
-
type: output.barrelType ?? "named",
|
|
219
|
-
root,
|
|
220
|
-
output,
|
|
221
|
-
files: this.fileManager.files,
|
|
222
|
-
meta: {
|
|
223
|
-
pluginKey: this.plugin.key
|
|
224
|
-
},
|
|
225
|
-
logger: this.logger
|
|
226
|
-
});
|
|
227
|
-
await this.addFile(...barrelFiles);
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
});
|
|
231
118
|
var operationsGenerator = pluginOas.createReactGenerator({
|
|
232
119
|
name: "operations",
|
|
233
120
|
Operations({ operations }) {
|
|
@@ -238,6 +125,7 @@ var operationsGenerator = pluginOas.createReactGenerator({
|
|
|
238
125
|
options: { output }
|
|
239
126
|
}
|
|
240
127
|
} = react.useApp();
|
|
128
|
+
const oas = hooks.useOas();
|
|
241
129
|
const { getFile, groupSchemasByName } = hooks.useOperationManager();
|
|
242
130
|
const name = "operations";
|
|
243
131
|
const file = pluginManager.getFile({ name, extname: ".ts", pluginKey });
|
|
@@ -246,7 +134,7 @@ var operationsGenerator = pluginOas.createReactGenerator({
|
|
|
246
134
|
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
247
135
|
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
248
136
|
}).filter(Boolean);
|
|
249
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output
|
|
137
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: utils.getBanner({ oas, output }), footer: utils.getFooter({ oas, output }), children: [
|
|
250
138
|
imports,
|
|
251
139
|
/* @__PURE__ */ jsxRuntime.jsx(chunkVZK7NWPL_cjs.Operations, { name, operations: transformedOperations })
|
|
252
140
|
] });
|
|
@@ -254,8 +142,6 @@ var operationsGenerator = pluginOas.createReactGenerator({
|
|
|
254
142
|
});
|
|
255
143
|
|
|
256
144
|
exports.operationsGenerator = operationsGenerator;
|
|
257
|
-
exports.pluginZod = pluginZod;
|
|
258
|
-
exports.pluginZodName = pluginZodName;
|
|
259
145
|
exports.zodGenerator = zodGenerator;
|
|
260
|
-
//# sourceMappingURL=chunk-
|
|
261
|
-
//# sourceMappingURL=chunk-
|
|
146
|
+
//# sourceMappingURL=chunk-LC2FWVGP.cjs.map
|
|
147
|
+
//# sourceMappingURL=chunk-LC2FWVGP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","useSchemaManager","SchemaGenerator","options","schemaKeywords","pluginTsName","Oas","File","jsx","Zod","jsxs","getBanner","getFooter","Operations"],"mappings":";;;;;;;;;;;AASO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,KAAA,EAAO,QAAW,GAAA,OAAA;AAE9C,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAASC,YAAkB,EAAA;AAC1D,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,QAAA,KAAaC,yBAAoB,EAAA;AAC9D,IAAA,MAAM,gBAAgBC,sBAAiB,EAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAIC,yBAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OAAQ,CAAA;AAAA,KACnB,CAAA;AAED,IAAA,MAAM,mBAAmB,CAAC,OAAA,CAAQ,YAAY,OAAQ,CAAA,WAAA,EAAa,QAAQ,YAAc,EAAA,OAAA,CAAQ,WA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AW,EAAC,GAAI,CAAA,CAAA;AAEtI,IAAA,MAAM,OAAU,GAAA,MAAA,CAAO,OAAQ,CAAA,qBAAqB,CACjD,CAAA,GAAA,CAAI,CAAC,CAAC,GAAK,EAAA,EAAE,IAAM,EAAA,SAAA,EAAW,CAAM,KAAA;AACnC,MAAA,MAAM,QAAQ,CAAC,IAAA,CAAK,SAAS,GAAG,MAAA,CAAO,OAAO,IAAK,CAAA,SAAS,CAAG,EAAA,GAAG,OAAO,MAAO,CAAA,IAAA,CAAK,UAAU,CAAC,CAAA,CAAE,OAAO,OAAO,CAAA;AAEhH,MAAA,uBAAOQ,cAAAA,CAACD,UAAK,CAAA,MAAA,EAAL,EAAsB,IAAM,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,CAAK,MAAM,IAAM,EAAA,OAAA,CAAQ,SAAS,CAAA,CAAE,QAA5D,GAAkE,CAAA;AAAA,KAC5F,CACA,CAAA,MAAA,CAAO,OAAO,CAAA;AAEjB,IACE,uBAAAG,eAACH,CAAAA,UAAAA,EAAA,EAAK,QAAA,EAAU,IAAK,CAAA,QAAA,EAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,IAAK,CAAA,IAAA,EAAM,QAAQI,eAAU,CAAA,EAAE,GAAK,EAAA,MAAA,EAAQ,CAAA,EAAG,MAAQC,EAAAA,eAAAA,CAAU,EAAE,GAAA,EAAK,MAAO,EAAC,CACnI,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDJ,cAAAA,CAACK,4BAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA;AAAA,KAC7D,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-LC2FWVGP.cjs","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { 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, inferred, typed, mapper } = 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, 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 const group = options.operation ? getGroup(options.operation) : undefined\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], group }),\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 {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: plugin.options.output })}\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 } = options\n\n const { getName, getFile, getImports } = useSchemaManager()\n const {\n plugin: {\n options: { output },\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 baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>\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, 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 { 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 baseName={file.baseName} path={file.path} meta={file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>\n {imports}\n <Operations name={name} operations={transformedOperations} />\n </File>\n )\n },\n})\n"]}
|
package/dist/components.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SchemaNames } from '@kubb/plugin-oas/hooks';
|
|
2
2
|
import { Operation } from '@kubb/oas';
|
|
3
3
|
import { Schema } from '@kubb/plugin-oas';
|
|
4
|
-
import { P as PluginZod } from './types-
|
|
4
|
+
import { P as PluginZod } from './types-BS3p0dlS.cjs';
|
|
5
5
|
import '@kubb/core';
|
|
6
6
|
|
|
7
7
|
type Props$1 = {
|
package/dist/components.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SchemaNames } from '@kubb/plugin-oas/hooks';
|
|
2
2
|
import { Operation } from '@kubb/oas';
|
|
3
3
|
import { Schema } from '@kubb/plugin-oas';
|
|
4
|
-
import { P as PluginZod } from './types-
|
|
4
|
+
import { P as PluginZod } from './types-BS3p0dlS.js';
|
|
5
5
|
import '@kubb/core';
|
|
6
6
|
|
|
7
7
|
type Props$1 = {
|
package/dist/generators.cjs
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkLC2FWVGP_cjs = require('./chunk-LC2FWVGP.cjs');
|
|
4
4
|
require('./chunk-VZK7NWPL.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "operationsGenerator", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkLC2FWVGP_cjs.operationsGenerator; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "zodGenerator", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkLC2FWVGP_cjs.zodGenerator; }
|
|
15
15
|
});
|
|
16
16
|
//# sourceMappingURL=generators.cjs.map
|
|
17
17
|
//# sourceMappingURL=generators.cjs.map
|
package/dist/generators.d.cts
CHANGED
package/dist/generators.d.ts
CHANGED
package/dist/generators.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,17 +1,137 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkLC2FWVGP_cjs = require('./chunk-LC2FWVGP.cjs');
|
|
4
4
|
require('./chunk-VZK7NWPL.cjs');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var core = require('@kubb/core');
|
|
7
|
+
var transformers = require('@kubb/core/transformers');
|
|
8
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
9
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
5
10
|
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
12
|
|
|
13
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
7
14
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
var pluginZodName = "plugin-zod";
|
|
16
|
+
var pluginZod = core.createPlugin((options) => {
|
|
17
|
+
const {
|
|
18
|
+
output = { path: "zod", barrelType: "named" },
|
|
19
|
+
group,
|
|
20
|
+
exclude = [],
|
|
21
|
+
include,
|
|
22
|
+
override = [],
|
|
23
|
+
transformers: transformers$1 = {},
|
|
24
|
+
dateType = "string",
|
|
25
|
+
unknownType = "any",
|
|
26
|
+
typed = false,
|
|
27
|
+
mapper = {},
|
|
28
|
+
operations = false,
|
|
29
|
+
importPath = "zod",
|
|
30
|
+
coercion = false,
|
|
31
|
+
inferred = false,
|
|
32
|
+
generators = [chunkLC2FWVGP_cjs.zodGenerator, operations ? chunkLC2FWVGP_cjs.operationsGenerator : void 0].filter(Boolean)
|
|
33
|
+
} = options;
|
|
34
|
+
return {
|
|
35
|
+
name: pluginZodName,
|
|
36
|
+
options: {
|
|
37
|
+
output,
|
|
38
|
+
transformers: transformers$1,
|
|
39
|
+
include,
|
|
40
|
+
exclude,
|
|
41
|
+
override,
|
|
42
|
+
typed,
|
|
43
|
+
dateType,
|
|
44
|
+
unknownType,
|
|
45
|
+
mapper,
|
|
46
|
+
importPath,
|
|
47
|
+
coercion,
|
|
48
|
+
operations,
|
|
49
|
+
inferred,
|
|
50
|
+
group
|
|
51
|
+
},
|
|
52
|
+
pre: [pluginOas.pluginOasName, typed ? pluginTs.pluginTsName : void 0].filter(Boolean),
|
|
53
|
+
resolvePath(baseName, pathMode, options2) {
|
|
54
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
55
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
56
|
+
if (mode === "single") {
|
|
57
|
+
return path__default.default.resolve(root, output.path);
|
|
58
|
+
}
|
|
59
|
+
if (group && (options2?.group?.path || options2?.group?.tag)) {
|
|
60
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
61
|
+
if (group?.type === "path") {
|
|
62
|
+
return `${ctx.group.split("/")[1]}`;
|
|
63
|
+
}
|
|
64
|
+
return `${transformers.camelCase(ctx.group)}Controller`;
|
|
65
|
+
};
|
|
66
|
+
return path__default.default.resolve(
|
|
67
|
+
root,
|
|
68
|
+
output.path,
|
|
69
|
+
groupName({
|
|
70
|
+
group: group.type === "path" ? options2.group.path : options2.group.tag
|
|
71
|
+
}),
|
|
72
|
+
baseName
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
76
|
+
},
|
|
77
|
+
resolveName(name, type) {
|
|
78
|
+
let resolvedName = transformers.camelCase(name, {
|
|
79
|
+
suffix: type ? "schema" : void 0,
|
|
80
|
+
isFile: type === "file"
|
|
81
|
+
});
|
|
82
|
+
if (type === "type") {
|
|
83
|
+
resolvedName = transformers.pascalCase(resolvedName);
|
|
84
|
+
}
|
|
85
|
+
if (type) {
|
|
86
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
87
|
+
}
|
|
88
|
+
return resolvedName;
|
|
89
|
+
},
|
|
90
|
+
async buildStart() {
|
|
91
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
92
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
93
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
94
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
95
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(this.plugin.options, {
|
|
96
|
+
oas,
|
|
97
|
+
pluginManager: this.pluginManager,
|
|
98
|
+
plugin: this.plugin,
|
|
99
|
+
contentType: swaggerPlugin.context.contentType,
|
|
100
|
+
include: void 0,
|
|
101
|
+
override,
|
|
102
|
+
mode,
|
|
103
|
+
output: output.path
|
|
104
|
+
});
|
|
105
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
106
|
+
await this.addFile(...schemaFiles);
|
|
107
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
108
|
+
oas,
|
|
109
|
+
pluginManager: this.pluginManager,
|
|
110
|
+
plugin: this.plugin,
|
|
111
|
+
contentType: swaggerPlugin.context.contentType,
|
|
112
|
+
exclude,
|
|
113
|
+
include,
|
|
114
|
+
override,
|
|
115
|
+
mode
|
|
116
|
+
});
|
|
117
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
118
|
+
await this.addFile(...operationFiles);
|
|
119
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
120
|
+
type: output.barrelType ?? "named",
|
|
121
|
+
root,
|
|
122
|
+
output,
|
|
123
|
+
files: this.fileManager.files,
|
|
124
|
+
meta: {
|
|
125
|
+
pluginKey: this.plugin.key
|
|
126
|
+
},
|
|
127
|
+
logger: this.logger
|
|
128
|
+
});
|
|
129
|
+
await this.addFile(...barrelFiles);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
15
132
|
});
|
|
133
|
+
|
|
134
|
+
exports.pluginZod = pluginZod;
|
|
135
|
+
exports.pluginZodName = pluginZodName;
|
|
16
136
|
//# sourceMappingURL=index.cjs.map
|
|
17
137
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","zodGenerator","operationsGenerator","pluginOasName","pluginTsName","options","path","FileManager","camelCase","pascalCase","PluginManager","SchemaGenerator","OperationGenerator"],"mappings":";;;;;;;;;;;;;;AAcO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,KAAA,EAAO,YAAY,OAAQ,EAAA;AAAA,IAC5C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,kBACZC,iBAAe,EAAC;AAAA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CAAA;AAED,MAAA,MAAM,cAAiB,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AACnE,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,cAAc,CAAA;AAEpC,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\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 (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,130 @@
|
|
|
1
|
-
|
|
1
|
+
import { zodGenerator, operationsGenerator } from './chunk-EWUPFTK7.js';
|
|
2
2
|
import './chunk-ZOYMIBKT.js';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
|
+
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
6
|
+
import { pluginOasName, SchemaGenerator, OperationGenerator } from '@kubb/plugin-oas';
|
|
7
|
+
import { pluginTsName } from '@kubb/plugin-ts';
|
|
8
|
+
|
|
9
|
+
var pluginZodName = "plugin-zod";
|
|
10
|
+
var pluginZod = createPlugin((options) => {
|
|
11
|
+
const {
|
|
12
|
+
output = { path: "zod", barrelType: "named" },
|
|
13
|
+
group,
|
|
14
|
+
exclude = [],
|
|
15
|
+
include,
|
|
16
|
+
override = [],
|
|
17
|
+
transformers = {},
|
|
18
|
+
dateType = "string",
|
|
19
|
+
unknownType = "any",
|
|
20
|
+
typed = false,
|
|
21
|
+
mapper = {},
|
|
22
|
+
operations = false,
|
|
23
|
+
importPath = "zod",
|
|
24
|
+
coercion = false,
|
|
25
|
+
inferred = false,
|
|
26
|
+
generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean)
|
|
27
|
+
} = options;
|
|
28
|
+
return {
|
|
29
|
+
name: pluginZodName,
|
|
30
|
+
options: {
|
|
31
|
+
output,
|
|
32
|
+
transformers,
|
|
33
|
+
include,
|
|
34
|
+
exclude,
|
|
35
|
+
override,
|
|
36
|
+
typed,
|
|
37
|
+
dateType,
|
|
38
|
+
unknownType,
|
|
39
|
+
mapper,
|
|
40
|
+
importPath,
|
|
41
|
+
coercion,
|
|
42
|
+
operations,
|
|
43
|
+
inferred,
|
|
44
|
+
group
|
|
45
|
+
},
|
|
46
|
+
pre: [pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
|
|
47
|
+
resolvePath(baseName, pathMode, options2) {
|
|
48
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
49
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
50
|
+
if (mode === "single") {
|
|
51
|
+
return path.resolve(root, output.path);
|
|
52
|
+
}
|
|
53
|
+
if (group && (options2?.group?.path || options2?.group?.tag)) {
|
|
54
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
55
|
+
if (group?.type === "path") {
|
|
56
|
+
return `${ctx.group.split("/")[1]}`;
|
|
57
|
+
}
|
|
58
|
+
return `${camelCase(ctx.group)}Controller`;
|
|
59
|
+
};
|
|
60
|
+
return path.resolve(
|
|
61
|
+
root,
|
|
62
|
+
output.path,
|
|
63
|
+
groupName({
|
|
64
|
+
group: group.type === "path" ? options2.group.path : options2.group.tag
|
|
65
|
+
}),
|
|
66
|
+
baseName
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
return path.resolve(root, output.path, baseName);
|
|
70
|
+
},
|
|
71
|
+
resolveName(name, type) {
|
|
72
|
+
let resolvedName = camelCase(name, {
|
|
73
|
+
suffix: type ? "schema" : void 0,
|
|
74
|
+
isFile: type === "file"
|
|
75
|
+
});
|
|
76
|
+
if (type === "type") {
|
|
77
|
+
resolvedName = pascalCase(resolvedName);
|
|
78
|
+
}
|
|
79
|
+
if (type) {
|
|
80
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
81
|
+
}
|
|
82
|
+
return resolvedName;
|
|
83
|
+
},
|
|
84
|
+
async buildStart() {
|
|
85
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
86
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
87
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
88
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
89
|
+
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
90
|
+
oas,
|
|
91
|
+
pluginManager: this.pluginManager,
|
|
92
|
+
plugin: this.plugin,
|
|
93
|
+
contentType: swaggerPlugin.context.contentType,
|
|
94
|
+
include: void 0,
|
|
95
|
+
override,
|
|
96
|
+
mode,
|
|
97
|
+
output: output.path
|
|
98
|
+
});
|
|
99
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
100
|
+
await this.addFile(...schemaFiles);
|
|
101
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
102
|
+
oas,
|
|
103
|
+
pluginManager: this.pluginManager,
|
|
104
|
+
plugin: this.plugin,
|
|
105
|
+
contentType: swaggerPlugin.context.contentType,
|
|
106
|
+
exclude,
|
|
107
|
+
include,
|
|
108
|
+
override,
|
|
109
|
+
mode
|
|
110
|
+
});
|
|
111
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
112
|
+
await this.addFile(...operationFiles);
|
|
113
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
114
|
+
type: output.barrelType ?? "named",
|
|
115
|
+
root,
|
|
116
|
+
output,
|
|
117
|
+
files: this.fileManager.files,
|
|
118
|
+
meta: {
|
|
119
|
+
pluginKey: this.plugin.key
|
|
120
|
+
},
|
|
121
|
+
logger: this.logger
|
|
122
|
+
});
|
|
123
|
+
await this.addFile(...barrelFiles);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
export { pluginZod, pluginZodName };
|
|
3
129
|
//# sourceMappingURL=index.js.map
|
|
4
130
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;AAcO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAY,YAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,KAAA,EAAO,YAAY,OAAQ,EAAA;AAAA,IAC5C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,eAAe,EAAC;AAAA,IAChB,QAAW,GAAA,QAAA;AAAA,IACX,WAAc,GAAA,KAAA;AAAA,IACd,KAAQ,GAAA,KAAA;AAAA,IACR,SAAS,EAAC;AAAA,IACV,UAAa,GAAA,KAAA;AAAA,IACb,UAAa,GAAA,KAAA;AAAA,IACb,QAAW,GAAA,KAAA;AAAA,IACX,QAAW,GAAA,KAAA;AAAA,IACX,UAAA,GAAa,CAAC,YAAc,EAAA,UAAA,GAAa,sBAAsB,KAAS,CAAA,CAAA,CAAE,OAAO,OAAO;AAAA,GACtF,GAAA,OAAA;AAEJ,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,aAAA;AAAA,IACN,OAAS,EAAA;AAAA,MACP,MAAA;AAAA,MACA,YAAA;AAAA,MACA,OAAA;AAAA,MACA,OAAA;AAAA,MACA,QAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,WAAA;AAAA,MACA,MAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA;AAAA,MACA,UAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACF;AAAA,IACA,GAAA,EAAK,CAAC,aAAe,EAAA,KAAA,GAAQ,eAAe,KAAS,CAAA,CAAA,CAAE,OAAO,OAAO,CAAA;AAAA,IACrE,WAAA,CAAY,QAAU,EA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gB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC7D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAEjC,MAAA,MAAM,kBAAqB,GAAA,IAAI,kBAAmB,CAAA,IAAA,CAAK,OAAO,OAAS,EAAA;AAAA,QACrE,GAAA;AAAA,QACA,eAAe,IAAK,CAAA,aAAA;AAAA,QACpB,QAAQ,IAAK,CAAA,MAAA;AAAA,QACb,WAAA,EAAa,cAAc,OAAQ,CAAA,WAAA;AAAA,QACnC,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,cAAiB,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AACnE,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,cAAc,CAAA;AAEpC,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\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 (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
-
import { SchemaObject } from '@kubb/oas';
|
|
2
|
+
import { Oas, SchemaObject } from '@kubb/oas';
|
|
3
3
|
import { ResolvePathOptions, Exclude, Include, Override, Schema, Generator } from '@kubb/plugin-oas';
|
|
4
4
|
|
|
5
5
|
type Options = {
|
|
6
6
|
/**
|
|
7
7
|
* @default 'zod'
|
|
8
8
|
*/
|
|
9
|
-
output?: Output
|
|
9
|
+
output?: Output<Oas>;
|
|
10
10
|
/**
|
|
11
11
|
* Group the Zod schemas based on the provided name.
|
|
12
12
|
*/
|
|
@@ -83,7 +83,7 @@ type Options = {
|
|
|
83
83
|
generators?: Array<Generator<PluginZod>>;
|
|
84
84
|
};
|
|
85
85
|
type ResolvedOptions = {
|
|
86
|
-
output: Output
|
|
86
|
+
output: Output<Oas>;
|
|
87
87
|
group: Options['group'];
|
|
88
88
|
override: NonNullable<Options['override']>;
|
|
89
89
|
transformers: NonNullable<Options['transformers']>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { PluginFactoryOptions, Output, Group, ResolveNameParams } from '@kubb/core';
|
|
2
|
-
import { SchemaObject } from '@kubb/oas';
|
|
2
|
+
import { Oas, SchemaObject } from '@kubb/oas';
|
|
3
3
|
import { ResolvePathOptions, Exclude, Include, Override, Schema, Generator } from '@kubb/plugin-oas';
|
|
4
4
|
|
|
5
5
|
type Options = {
|
|
6
6
|
/**
|
|
7
7
|
* @default 'zod'
|
|
8
8
|
*/
|
|
9
|
-
output?: Output
|
|
9
|
+
output?: Output<Oas>;
|
|
10
10
|
/**
|
|
11
11
|
* Group the Zod schemas based on the provided name.
|
|
12
12
|
*/
|
|
@@ -83,7 +83,7 @@ type Options = {
|
|
|
83
83
|
generators?: Array<Generator<PluginZod>>;
|
|
84
84
|
};
|
|
85
85
|
type ResolvedOptions = {
|
|
86
|
-
output: Output
|
|
86
|
+
output: Output<Oas>;
|
|
87
87
|
group: Options['group'];
|
|
88
88
|
override: NonNullable<Options['override']>;
|
|
89
89
|
transformers: NonNullable<Options['transformers']>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-zod",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.1",
|
|
4
4
|
"description": "Generator plugin-zod",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -66,19 +66,19 @@
|
|
|
66
66
|
"!/**/__tests__/**"
|
|
67
67
|
],
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@kubb/core": "3.
|
|
70
|
-
"@kubb/fs": "3.
|
|
71
|
-
"@kubb/oas": "3.
|
|
72
|
-
"@kubb/parser-ts": "3.
|
|
73
|
-
"@kubb/plugin-oas": "3.
|
|
74
|
-
"@kubb/plugin-ts": "3.
|
|
75
|
-
"@kubb/react": "3.
|
|
69
|
+
"@kubb/core": "3.5.1",
|
|
70
|
+
"@kubb/fs": "3.5.1",
|
|
71
|
+
"@kubb/oas": "3.5.1",
|
|
72
|
+
"@kubb/parser-ts": "3.5.1",
|
|
73
|
+
"@kubb/plugin-oas": "3.5.1",
|
|
74
|
+
"@kubb/plugin-ts": "3.5.1",
|
|
75
|
+
"@kubb/react": "3.5.1"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"tsup": "^8.3.5",
|
|
79
79
|
"zod": "~3.24.1",
|
|
80
|
-
"@kubb/config-ts": "3.
|
|
81
|
-
"@kubb/config-tsup": "3.
|
|
80
|
+
"@kubb/config-ts": "3.5.1",
|
|
81
|
+
"@kubb/config-tsup": "3.5.1"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
84
|
"@kubb/react": "^3.0.0"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { createReactGenerator } from '@kubb/plugin-oas'
|
|
2
|
-
import { useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
2
|
+
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
3
|
+
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
3
4
|
import { File, useApp } from '@kubb/react'
|
|
4
5
|
import { Operations } from '../components/Operations'
|
|
5
|
-
import { pluginZodName } from '../plugin.ts'
|
|
6
6
|
import type { PluginZod } from '../types'
|
|
7
7
|
|
|
8
8
|
export const operationsGenerator = createReactGenerator<PluginZod>({
|
|
@@ -15,6 +15,7 @@ export const operationsGenerator = createReactGenerator<PluginZod>({
|
|
|
15
15
|
options: { output },
|
|
16
16
|
},
|
|
17
17
|
} = useApp<PluginZod>()
|
|
18
|
+
const oas = useOas()
|
|
18
19
|
const { getFile, groupSchemasByName } = useOperationManager()
|
|
19
20
|
|
|
20
21
|
const name = 'operations'
|
|
@@ -31,7 +32,7 @@ export const operationsGenerator = createReactGenerator<PluginZod>({
|
|
|
31
32
|
.filter(Boolean)
|
|
32
33
|
|
|
33
34
|
return (
|
|
34
|
-
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={output
|
|
35
|
+
<File baseName={file.baseName} path={file.path} meta={file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>
|
|
35
36
|
{imports}
|
|
36
37
|
<Operations name={name} operations={transformedOperations} />
|
|
37
38
|
</File>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'
|
|
2
2
|
import { Oas } from '@kubb/plugin-oas/components'
|
|
3
3
|
import { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'
|
|
4
|
+
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
4
5
|
import { pluginTsName } from '@kubb/plugin-ts'
|
|
5
6
|
import { File, useApp } from '@kubb/react'
|
|
6
7
|
import { Zod } from '../components'
|
|
@@ -71,7 +72,13 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
return (
|
|
74
|
-
<File
|
|
75
|
+
<File
|
|
76
|
+
baseName={file.baseName}
|
|
77
|
+
path={file.path}
|
|
78
|
+
meta={file.meta}
|
|
79
|
+
banner={getBanner({ oas, output: plugin.options.output })}
|
|
80
|
+
footer={getFooter({ oas, output: plugin.options.output })}
|
|
81
|
+
>
|
|
75
82
|
<File.Import name={['z']} path={plugin.options.importPath} />
|
|
76
83
|
{operationSchemas.map(mapOperationSchema)}
|
|
77
84
|
</File>
|
|
@@ -86,6 +93,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
86
93
|
options: { output },
|
|
87
94
|
},
|
|
88
95
|
} = useApp<PluginZod>()
|
|
96
|
+
const oas = useOas()
|
|
89
97
|
|
|
90
98
|
const imports = getImports(schema.tree)
|
|
91
99
|
|
|
@@ -101,7 +109,7 @@ export const zodGenerator = createReactGenerator<PluginZod>({
|
|
|
101
109
|
}
|
|
102
110
|
|
|
103
111
|
return (
|
|
104
|
-
<File baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={output
|
|
112
|
+
<File baseName={zod.file.baseName} path={zod.file.path} meta={zod.file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>
|
|
105
113
|
<File.Import name={['z']} path={importPath} />
|
|
106
114
|
{typed && <File.Import isTypeOnly root={zod.file.path} path={type.file.path} name={[type.name]} />}
|
|
107
115
|
{typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
|
-
import type { SchemaObject } from '@kubb/oas'
|
|
2
|
+
import type { Oas, SchemaObject } from '@kubb/oas'
|
|
3
3
|
import type { Exclude, Generator, Include, Override, ResolvePathOptions, Schema } from '@kubb/plugin-oas'
|
|
4
4
|
|
|
5
5
|
export type Options = {
|
|
6
6
|
/**
|
|
7
7
|
* @default 'zod'
|
|
8
8
|
*/
|
|
9
|
-
output?: Output
|
|
9
|
+
output?: Output<Oas>
|
|
10
10
|
/**
|
|
11
11
|
* Group the Zod schemas based on the provided name.
|
|
12
12
|
*/
|
|
@@ -90,7 +90,7 @@ export type Options = {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
type ResolvedOptions = {
|
|
93
|
-
output: Output
|
|
93
|
+
output: Output<Oas>
|
|
94
94
|
group: Options['group']
|
|
95
95
|
override: NonNullable<Options['override']>
|
|
96
96
|
transformers: NonNullable<Options['transformers']>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/generators/zodGenerator.tsx","../src/plugin.ts","../src/generators/operationsGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","useSchemaManager","SchemaGenerator","options","schemaKeywords","pluginTsName","Oas","File","jsx","Zod","jsxs","createPlugin","transformers","pluginOasName","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator","Operations"],"mappings":";;;;;;;;;;;;;;;;;AAQO,IAAM,eAAeA,8BAAgC,CAAA;AAAA,EAC1D,IAAM,EAAA,KAAA;AAAA,EACN,SAAU,CAAA,EAAE,SAAW,EAAA,OAAA,EAAW,EAAA;AAChC,IAAA,MAAM,EAAE,QAAA,EAAU,QAAU,EAAA,KAAA,EAAO,QAAW,GAAA,OAAA;AAE9C,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAASC,YAAkB,EAAA;AAC1D,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,QAAA,KAAaC,yBAAoB,EAAA;AAC9D,IAAA,MAAM,gBAAgBC,sBAAiB,EAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,CAAA;AACpC,IAAM,MAAA,eAAA,GAAkB,IAAIC,yBAAA,CAAgB,OAAS,EAAA;AAAA,MACnD,GAAA;AAAA,MACA,MAAA;AAAA,MACA,aAAA;AAAA,MACA,IAAA;AAAA,MACA,UAAU,OAAQ,CAAA;AAAA,KACnB,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;AAEjB,IAAM,MAAA,kBAAA,GAAqB,CAAC,EAAE,IAAM,EAAA,MAAA,EAAQ,aAAa,UAAY,EAAA,GAAGC,QAAQ,EAAA,EAAwB,CAAc,KAAA;AAEpH,MAAA,MAAM,QAAW,GAAA,KAAA,CAAM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AA;AAGN,CAAC","file":"chunk-7AQ52OFH.cjs","sourcesContent":["import { type OperationSchema as OperationSchemaType, SchemaGenerator, createReactGenerator, schemaKeywords } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { useOas, useOperationManager, useSchemaManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Zod } from '../components'\nimport type { PluginZod } from '../types'\n\nexport const zodGenerator = createReactGenerator<PluginZod>({\n name: 'zod',\n Operation({ operation, options }) {\n const { coercion, inferred, typed, mapper } = options\n\n const { plugin, pluginManager, mode } = useApp<PluginZod>()\n const oas = useOas()\n const { getSchemas, getFile, 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, 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 const group = options.operation ? getGroup(options.operation) : undefined\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], group }),\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 {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n mapper={mapper}\n coercion={coercion}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\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 (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport { pluginZodName } from '../plugin.ts'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\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 })\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"]}
|
|
@@ -1 +0,0 @@
|
|
|
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;AAE9C,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAAS,MAAkB,EAAA;AAC1D,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,QAAA,KAAa,mBAAoB,EAAA;AAC9D,IAAA,MAAM,gBAAgB,gBAAiB,EAAA;AAEvC,IAAM,MAAA,IAAA,GAAO,QAAQ,SAAS,CAAA;AAC9B,IAAM,MAAA,OAAA,GAAU,WAAW,SAAS,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,O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AAAA,IAAAA,EAAA,EAAK,QAAU,EAAA,IAAA,CAAK,UAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,MAAA,EAAQ,QAAQ,MAAQ,EAAA,MAAA,EAAQ,QAAQ,MACtG,EAAA,QAAA,EAAA;AAAA,MAAA,OAAA;AAAA,sBACDD,GAAAA,CAAC,UAAW,EAAA,EAAA,IAAA,EAAY,YAAY,qBAAuB,EAAA;AAAA,KAC7D,EAAA,CAAA;AAAA;AAGN,CAAC","file":"chunk-X3RBLACB.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, 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, 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 const group = options.operation ? getGroup(options.operation) : undefined\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], group }),\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 {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\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 {typed && <File.Import isTypeOnly path={'@kubb/plugin-zod/utils'} name={['ToZod']} />}\n {imports.map((imp, index) => (\n <File.Import key={index} root={zod.file.path} path={imp.path} name={imp.name} />\n ))}\n\n <Zod\n name={zod.name}\n typeName={typed ? type.name : undefined}\n inferTypeName={inferred ? zod.inferTypeName : undefined}\n description={schema.value.description}\n tree={schema.tree}\n mapper={mapper}\n coercion={coercion}\n />\n </File>\n )\n },\n})\n","import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, SchemaGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { operationsGenerator } from './generators'\nimport { zodGenerator } from './generators/zodGenerator.tsx'\nimport type { PluginZod } from './types.ts'\n\nexport const pluginZodName = 'plugin-zod' satisfies PluginZod['name']\n\nexport const pluginZod = createPlugin<PluginZod>((options) => {\n const {\n output = { path: 'zod', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dateType = 'string',\n unknownType = 'any',\n typed = false,\n mapper = {},\n operations = false,\n importPath = 'zod',\n coercion = false,\n inferred = false,\n generators = [zodGenerator, operations ? operationsGenerator : undefined].filter(Boolean),\n } = options\n\n return {\n name: pluginZodName,\n options: {\n output,\n transformers,\n include,\n exclude,\n override,\n typed,\n dateType,\n unknownType,\n mapper,\n importPath,\n coercion,\n operations,\n inferred,\n group,\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 (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name, {\n suffix: type ? 'schema' : undefined,\n isFile: type === 'file',\n })\n\n if (type === 'type') {\n resolvedName = pascalCase(resolvedName)\n }\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n\n const schemaGenerator = new SchemaGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n include: undefined,\n override,\n mode,\n output: output.path,\n })\n\n const schemaFiles = await schemaGenerator.build(...generators)\n await this.addFile(...schemaFiles)\n\n const operationGenerator = new OperationGenerator(this.plugin.options, {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n })\n\n const operationFiles = await operationGenerator.build(...generators)\n await this.addFile(...operationFiles)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport { pluginZodName } from '../plugin.ts'\nimport type { PluginZod } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginZod>({\n name: 'operations',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\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 })\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"]}
|