@kubb/plugin-zod 3.0.0-alpha.8 → 3.0.0-beta.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/README.md +14 -5
- package/dist/chunk-5PR4KKK7.js +235 -0
- package/dist/chunk-5PR4KKK7.js.map +1 -0
- package/dist/chunk-6MMPQJME.cjs +244 -0
- package/dist/chunk-6MMPQJME.cjs.map +1 -0
- package/dist/chunk-FLFW72FT.cjs +344 -0
- package/dist/chunk-FLFW72FT.cjs.map +1 -0
- package/dist/chunk-UONLSRDV.js +337 -0
- package/dist/chunk-UONLSRDV.js.map +1 -0
- package/dist/components.cjs +11 -10
- 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 -14
- 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 -8
- 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 -12
- package/dist/index.js.map +1 -1
- package/dist/types-ryu2n1NA.d.cts +95 -0
- package/dist/types-ryu2n1NA.d.ts +95 -0
- package/package.json +19 -21
- package/src/components/Operations.tsx +12 -98
- 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__/discriminator.ts +3 -0
- package/src/generators/__snapshots__/enumBooleanLiteral.ts +3 -0
- package/src/generators/__snapshots__/enumNamesType.ts +3 -0
- package/src/generators/__snapshots__/enumNullable.ts +3 -0
- package/src/generators/__snapshots__/enumSingleLiteral.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 +34 -10
- package/src/plugin.ts +30 -39
- package/src/types.ts +42 -88
- package/dist/Operations-BG26e_MW.d.cts +0 -47
- package/dist/Operations-BG26e_MW.d.ts +0 -47
- package/dist/chunk-CD3EZWBX.js +0 -3495
- package/dist/chunk-CD3EZWBX.js.map +0 -1
- package/dist/chunk-TSJ74266.cjs +0 -3495
- package/dist/chunk-TSJ74266.cjs.map +0 -1
- package/src/SchemaGenerator.tsx +0 -22
- package/src/components/OperationSchema.tsx +0 -60
- package/src/components/Schema.tsx +0 -166
- package/src/components/__snapshots__/operations.ts +0 -53
package/README.md
CHANGED
|
@@ -13,12 +13,8 @@
|
|
|
13
13
|
[![Coverage][coverage-src]][coverage-href]
|
|
14
14
|
[![License][license-src]][license-href]
|
|
15
15
|
|
|
16
|
-
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
17
|
-
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
18
|
-
</p>
|
|
19
|
-
|
|
20
16
|
<h4>
|
|
21
|
-
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/
|
|
17
|
+
<a href="https://codesandbox.io/s/github/kubb-labs/kubb/tree/main//examples/typescript" target="_blank">View Demo</a>
|
|
22
18
|
<span> · </span>
|
|
23
19
|
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
24
20
|
<span> · </span>
|
|
@@ -28,6 +24,19 @@
|
|
|
28
24
|
</h4>
|
|
29
25
|
</div>
|
|
30
26
|
|
|
27
|
+
## Supporting Kubb
|
|
28
|
+
|
|
29
|
+
Kubb uses an MIT-licensed open source project with its ongoing development made possible entirely by the support of Sponsors. If you would like to become a sponsor, please consider:
|
|
30
|
+
|
|
31
|
+
- [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://github.com/sponsors/stijnvanhulle">
|
|
35
|
+
<img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
|
|
36
|
+
</a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
|
|
31
40
|
<!-- Badges -->
|
|
32
41
|
|
|
33
42
|
[npm-version-src]: https://img.shields.io/npm/v/@kubb/plugin-zod?flat&colorA=18181B&colorB=f58517
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { Zod, Operations } from './chunk-UONLSRDV.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
|
+
|
|
12
|
+
var zodGenerator = createReactGenerator({
|
|
13
|
+
name: "zod",
|
|
14
|
+
Operation({ operation, options }) {
|
|
15
|
+
const { coercion, inferred, typed, mapper } = options;
|
|
16
|
+
const { plugin, pluginManager, mode } = useApp();
|
|
17
|
+
const oas = useOas();
|
|
18
|
+
const { getSchemas, getFile } = useOperationManager();
|
|
19
|
+
const schemaManager = useSchemaManager();
|
|
20
|
+
const file = getFile(operation);
|
|
21
|
+
const schemas = getSchemas(operation);
|
|
22
|
+
const schemaGenerator = new SchemaGenerator(options, {
|
|
23
|
+
oas,
|
|
24
|
+
plugin,
|
|
25
|
+
pluginManager,
|
|
26
|
+
mode,
|
|
27
|
+
override: options.override
|
|
28
|
+
});
|
|
29
|
+
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
30
|
+
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options2 }, i) => {
|
|
31
|
+
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
32
|
+
const optional = !required && !!name.includes("Params");
|
|
33
|
+
const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: schemaKeywords.optional } : void 0].filter(Boolean);
|
|
34
|
+
const imports = schemaManager.getImports(tree);
|
|
35
|
+
const zod = {
|
|
36
|
+
name: schemaManager.getName(name, { type: "function" }),
|
|
37
|
+
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
38
|
+
file: schemaManager.getFile(name)
|
|
39
|
+
};
|
|
40
|
+
const type = {
|
|
41
|
+
name: schemaManager.getName(name, { type: "type", pluginKey: [pluginTsName] }),
|
|
42
|
+
file: schemaManager.getFile(options2.operationName || name, { pluginKey: [pluginTsName], tag: options2.operation?.getTags()[0]?.name })
|
|
43
|
+
};
|
|
44
|
+
return /* @__PURE__ */ jsxs(Oas.Schema, { name, value: schema, tree, children: [
|
|
45
|
+
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root: file.path, path: type.file.path, name: [type.name] }),
|
|
46
|
+
imports.map((imp, index) => /* @__PURE__ */ jsx(File.Import, { root: file.path, path: imp.path, name: imp.name }, index)),
|
|
47
|
+
/* @__PURE__ */ jsx(
|
|
48
|
+
Zod,
|
|
49
|
+
{
|
|
50
|
+
name: zod.name,
|
|
51
|
+
typeName: typed ? type.name : void 0,
|
|
52
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
53
|
+
description,
|
|
54
|
+
tree,
|
|
55
|
+
mapper,
|
|
56
|
+
coercion,
|
|
57
|
+
keysToOmit
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
] }, i);
|
|
61
|
+
};
|
|
62
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
63
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
64
|
+
operationSchemas.map(mapOperationSchema)
|
|
65
|
+
] });
|
|
66
|
+
},
|
|
67
|
+
Schema({ schema, options }) {
|
|
68
|
+
const { coercion, inferred, typed, mapper, importPath } = options;
|
|
69
|
+
const { getName, getFile, getImports } = useSchemaManager();
|
|
70
|
+
const {
|
|
71
|
+
plugin: {
|
|
72
|
+
options: { output }
|
|
73
|
+
}
|
|
74
|
+
} = useApp();
|
|
75
|
+
const imports = getImports(schema.tree);
|
|
76
|
+
const zod = {
|
|
77
|
+
name: getName(schema.name, { type: "function" }),
|
|
78
|
+
inferTypeName: getName(schema.name, { type: "type" }),
|
|
79
|
+
file: getFile(schema.name)
|
|
80
|
+
};
|
|
81
|
+
const type = {
|
|
82
|
+
name: getName(schema.name, { type: "type", pluginKey: [pluginTsName] }),
|
|
83
|
+
file: getFile(schema.name, { pluginKey: [pluginTsName] })
|
|
84
|
+
};
|
|
85
|
+
return /* @__PURE__ */ jsxs(File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
86
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: importPath }),
|
|
87
|
+
typed && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
|
|
88
|
+
imports.map((imp, index) => /* @__PURE__ */ jsx(File.Import, { root: zod.file.path, path: imp.path, name: imp.name }, index)),
|
|
89
|
+
/* @__PURE__ */ jsx(
|
|
90
|
+
Zod,
|
|
91
|
+
{
|
|
92
|
+
name: zod.name,
|
|
93
|
+
typeName: typed ? type.name : void 0,
|
|
94
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
95
|
+
description: schema.value.description,
|
|
96
|
+
tree: schema.tree,
|
|
97
|
+
mapper,
|
|
98
|
+
coercion
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
] });
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
var pluginZodName = "plugin-zod";
|
|
105
|
+
var pluginZod = createPlugin((options) => {
|
|
106
|
+
const {
|
|
107
|
+
output = { path: "zod", barrelType: "named" },
|
|
108
|
+
group,
|
|
109
|
+
exclude = [],
|
|
110
|
+
include,
|
|
111
|
+
override = [],
|
|
112
|
+
transformers = {},
|
|
113
|
+
dateType = "string",
|
|
114
|
+
unknownType = "any",
|
|
115
|
+
typed = false,
|
|
116
|
+
mapper = {},
|
|
117
|
+
operations = false,
|
|
118
|
+
importPath = "zod",
|
|
119
|
+
coercion = false,
|
|
120
|
+
inferred = false,
|
|
121
|
+
generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean)
|
|
122
|
+
} = options;
|
|
123
|
+
return {
|
|
124
|
+
name: pluginZodName,
|
|
125
|
+
options: {
|
|
126
|
+
output,
|
|
127
|
+
transformers,
|
|
128
|
+
include,
|
|
129
|
+
exclude,
|
|
130
|
+
override,
|
|
131
|
+
typed,
|
|
132
|
+
dateType,
|
|
133
|
+
unknownType,
|
|
134
|
+
mapper,
|
|
135
|
+
importPath,
|
|
136
|
+
coercion,
|
|
137
|
+
operations,
|
|
138
|
+
inferred
|
|
139
|
+
},
|
|
140
|
+
pre: [pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
|
|
141
|
+
resolvePath(baseName, pathMode, options2) {
|
|
142
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
143
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
144
|
+
if (options2?.tag && group?.type === "tag") {
|
|
145
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
146
|
+
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
147
|
+
}
|
|
148
|
+
if (mode === "single") {
|
|
149
|
+
return path.resolve(root, output.path);
|
|
150
|
+
}
|
|
151
|
+
return path.resolve(root, output.path, baseName);
|
|
152
|
+
},
|
|
153
|
+
resolveName(name, type) {
|
|
154
|
+
let resolvedName = camelCase(name, {
|
|
155
|
+
suffix: type ? "schema" : void 0,
|
|
156
|
+
isFile: type === "file"
|
|
157
|
+
});
|
|
158
|
+
if (type === "type") {
|
|
159
|
+
resolvedName = pascalCase(resolvedName);
|
|
160
|
+
}
|
|
161
|
+
if (type) {
|
|
162
|
+
return transformers?.name?.(resolvedName, type) || resolvedName;
|
|
163
|
+
}
|
|
164
|
+
return resolvedName;
|
|
165
|
+
},
|
|
166
|
+
async buildStart() {
|
|
167
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
168
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
169
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
170
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
171
|
+
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
172
|
+
oas,
|
|
173
|
+
pluginManager: this.pluginManager,
|
|
174
|
+
plugin: this.plugin,
|
|
175
|
+
contentType: swaggerPlugin.context.contentType,
|
|
176
|
+
include: void 0,
|
|
177
|
+
override,
|
|
178
|
+
mode,
|
|
179
|
+
output: output.path
|
|
180
|
+
});
|
|
181
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
182
|
+
await this.addFile(...schemaFiles);
|
|
183
|
+
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
184
|
+
oas,
|
|
185
|
+
pluginManager: this.pluginManager,
|
|
186
|
+
plugin: this.plugin,
|
|
187
|
+
contentType: swaggerPlugin.context.contentType,
|
|
188
|
+
exclude,
|
|
189
|
+
include,
|
|
190
|
+
override,
|
|
191
|
+
mode
|
|
192
|
+
});
|
|
193
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
194
|
+
await this.addFile(...operationFiles);
|
|
195
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
196
|
+
type: output.barrelType ?? "named",
|
|
197
|
+
root,
|
|
198
|
+
output,
|
|
199
|
+
files: this.fileManager.files,
|
|
200
|
+
meta: {
|
|
201
|
+
pluginKey: this.plugin.key
|
|
202
|
+
},
|
|
203
|
+
logger: this.logger
|
|
204
|
+
});
|
|
205
|
+
await this.addFile(...barrelFiles);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
var operationsGenerator = createReactGenerator({
|
|
210
|
+
name: "operations",
|
|
211
|
+
Operations({ operations }) {
|
|
212
|
+
const {
|
|
213
|
+
pluginManager,
|
|
214
|
+
plugin: {
|
|
215
|
+
options: { output }
|
|
216
|
+
}
|
|
217
|
+
} = useApp();
|
|
218
|
+
const { getFile, groupSchemasByName } = useOperationManager();
|
|
219
|
+
const name = "operations";
|
|
220
|
+
const file = pluginManager.getFile({ name, extname: ".ts", pluginKey: [pluginZodName] });
|
|
221
|
+
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
222
|
+
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
223
|
+
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
224
|
+
return /* @__PURE__ */ jsx(File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
225
|
+
}).filter(Boolean);
|
|
226
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
227
|
+
imports,
|
|
228
|
+
/* @__PURE__ */ jsx(Operations, { name, operations: transformedOperations })
|
|
229
|
+
] });
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
export { operationsGenerator, pluginZod, pluginZodName, zodGenerator };
|
|
234
|
+
//# sourceMappingURL=chunk-5PR4KKK7.js.map
|
|
235
|
+
//# sourceMappingURL=chunk-5PR4KKK7.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,oBAA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A,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,CAAA;AAEhH,MAAA,uBAAOC,GAAAA,CAACC,IAAK,CAAA,MAAA,EAAL,EAAsB,IAAM,EAAA,KAAA,EAAO,IAAM,EAAA,IAAA,CAAK,MAAM,IAAM,EAAA,OAAA,CAAQ,SAAS,CAAA,CAAE,QAA5D,GAAkE,CAAA,CAAA;AAAA,KAC5F,CACA,CAAA,MAAA,CAAO,OAAO,CAAA,CAAA;AAEjB,IAAA,uBACEC,IAACD,CAAAA,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,CAAA;AAAA,KAC7D,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-5PR4KKK7.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, 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 },\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 (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 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 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"]}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkFLFW72FT_cjs = require('./chunk-FLFW72FT.cjs');
|
|
4
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
5
|
+
var components = require('@kubb/plugin-oas/components');
|
|
6
|
+
var hooks = require('@kubb/plugin-oas/hooks');
|
|
7
|
+
var pluginTs = require('@kubb/plugin-ts');
|
|
8
|
+
var react = require('@kubb/react');
|
|
9
|
+
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
|
+
|
|
18
|
+
var zodGenerator = pluginOas.createReactGenerator({
|
|
19
|
+
name: "zod",
|
|
20
|
+
Operation({ operation, options }) {
|
|
21
|
+
const { coercion, inferred, typed, mapper } = options;
|
|
22
|
+
const { plugin, pluginManager, mode } = react.useApp();
|
|
23
|
+
const oas = hooks.useOas();
|
|
24
|
+
const { getSchemas, getFile } = hooks.useOperationManager();
|
|
25
|
+
const schemaManager = hooks.useSchemaManager();
|
|
26
|
+
const file = getFile(operation);
|
|
27
|
+
const schemas = getSchemas(operation);
|
|
28
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(options, {
|
|
29
|
+
oas,
|
|
30
|
+
plugin,
|
|
31
|
+
pluginManager,
|
|
32
|
+
mode,
|
|
33
|
+
override: options.override
|
|
34
|
+
});
|
|
35
|
+
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
36
|
+
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options2 }, i) => {
|
|
37
|
+
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
38
|
+
const optional = !required && !!name.includes("Params");
|
|
39
|
+
const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: pluginOas.schemaKeywords.optional } : void 0].filter(Boolean);
|
|
40
|
+
const imports = schemaManager.getImports(tree);
|
|
41
|
+
const zod = {
|
|
42
|
+
name: schemaManager.getName(name, { type: "function" }),
|
|
43
|
+
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
44
|
+
file: schemaManager.getFile(name)
|
|
45
|
+
};
|
|
46
|
+
const type = {
|
|
47
|
+
name: schemaManager.getName(name, { type: "type", pluginKey: [pluginTs.pluginTsName] }),
|
|
48
|
+
file: schemaManager.getFile(options2.operationName || name, { pluginKey: [pluginTs.pluginTsName], tag: options2.operation?.getTags()[0]?.name })
|
|
49
|
+
};
|
|
50
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
|
|
51
|
+
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: file.path, path: type.file.path, name: [type.name] }),
|
|
52
|
+
imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: file.path, path: imp.path, name: imp.name }, index)),
|
|
53
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
54
|
+
chunkFLFW72FT_cjs.Zod,
|
|
55
|
+
{
|
|
56
|
+
name: zod.name,
|
|
57
|
+
typeName: typed ? type.name : void 0,
|
|
58
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
59
|
+
description,
|
|
60
|
+
tree,
|
|
61
|
+
mapper,
|
|
62
|
+
coercion,
|
|
63
|
+
keysToOmit
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
] }, i);
|
|
67
|
+
};
|
|
68
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: plugin.options.output?.banner, footer: plugin.options.output?.footer, children: [
|
|
69
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
70
|
+
operationSchemas.map(mapOperationSchema)
|
|
71
|
+
] });
|
|
72
|
+
},
|
|
73
|
+
Schema({ schema, options }) {
|
|
74
|
+
const { coercion, inferred, typed, mapper, importPath } = options;
|
|
75
|
+
const { getName, getFile, getImports } = hooks.useSchemaManager();
|
|
76
|
+
const {
|
|
77
|
+
plugin: {
|
|
78
|
+
options: { output }
|
|
79
|
+
}
|
|
80
|
+
} = react.useApp();
|
|
81
|
+
const imports = getImports(schema.tree);
|
|
82
|
+
const zod = {
|
|
83
|
+
name: getName(schema.name, { type: "function" }),
|
|
84
|
+
inferTypeName: getName(schema.name, { type: "type" }),
|
|
85
|
+
file: getFile(schema.name)
|
|
86
|
+
};
|
|
87
|
+
const type = {
|
|
88
|
+
name: getName(schema.name, { type: "type", pluginKey: [pluginTs.pluginTsName] }),
|
|
89
|
+
file: getFile(schema.name, { pluginKey: [pluginTs.pluginTsName] })
|
|
90
|
+
};
|
|
91
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
92
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: importPath }),
|
|
93
|
+
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
|
|
94
|
+
imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: zod.file.path, path: imp.path, name: imp.name }, index)),
|
|
95
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
96
|
+
chunkFLFW72FT_cjs.Zod,
|
|
97
|
+
{
|
|
98
|
+
name: zod.name,
|
|
99
|
+
typeName: typed ? type.name : void 0,
|
|
100
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
101
|
+
description: schema.value.description,
|
|
102
|
+
tree: schema.tree,
|
|
103
|
+
mapper,
|
|
104
|
+
coercion
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
] });
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
var pluginZodName = "plugin-zod";
|
|
111
|
+
var pluginZod = core.createPlugin((options) => {
|
|
112
|
+
const {
|
|
113
|
+
output = { path: "zod", barrelType: "named" },
|
|
114
|
+
group,
|
|
115
|
+
exclude = [],
|
|
116
|
+
include,
|
|
117
|
+
override = [],
|
|
118
|
+
transformers: transformers$1 = {},
|
|
119
|
+
dateType = "string",
|
|
120
|
+
unknownType = "any",
|
|
121
|
+
typed = false,
|
|
122
|
+
mapper = {},
|
|
123
|
+
operations = false,
|
|
124
|
+
importPath = "zod",
|
|
125
|
+
coercion = false,
|
|
126
|
+
inferred = false,
|
|
127
|
+
generators = [zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean)
|
|
128
|
+
} = options;
|
|
129
|
+
return {
|
|
130
|
+
name: pluginZodName,
|
|
131
|
+
options: {
|
|
132
|
+
output,
|
|
133
|
+
transformers: transformers$1,
|
|
134
|
+
include,
|
|
135
|
+
exclude,
|
|
136
|
+
override,
|
|
137
|
+
typed,
|
|
138
|
+
dateType,
|
|
139
|
+
unknownType,
|
|
140
|
+
mapper,
|
|
141
|
+
importPath,
|
|
142
|
+
coercion,
|
|
143
|
+
operations,
|
|
144
|
+
inferred
|
|
145
|
+
},
|
|
146
|
+
pre: [pluginOas.pluginOasName, typed ? pluginTs.pluginTsName : void 0].filter(Boolean),
|
|
147
|
+
resolvePath(baseName, pathMode, options2) {
|
|
148
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
149
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
150
|
+
if (options2?.tag && group?.type === "tag") {
|
|
151
|
+
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
152
|
+
return path__default.default.resolve(root, output.path, groupName({ group: transformers.camelCase(options2.tag) }), baseName);
|
|
153
|
+
}
|
|
154
|
+
if (mode === "single") {
|
|
155
|
+
return path__default.default.resolve(root, output.path);
|
|
156
|
+
}
|
|
157
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
158
|
+
},
|
|
159
|
+
resolveName(name, type) {
|
|
160
|
+
let resolvedName = transformers.camelCase(name, {
|
|
161
|
+
suffix: type ? "schema" : void 0,
|
|
162
|
+
isFile: type === "file"
|
|
163
|
+
});
|
|
164
|
+
if (type === "type") {
|
|
165
|
+
resolvedName = transformers.pascalCase(resolvedName);
|
|
166
|
+
}
|
|
167
|
+
if (type) {
|
|
168
|
+
return transformers$1?.name?.(resolvedName, type) || resolvedName;
|
|
169
|
+
}
|
|
170
|
+
return resolvedName;
|
|
171
|
+
},
|
|
172
|
+
async buildStart() {
|
|
173
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
174
|
+
const oas = await swaggerPlugin.context.getOas();
|
|
175
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
176
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
177
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(this.plugin.options, {
|
|
178
|
+
oas,
|
|
179
|
+
pluginManager: this.pluginManager,
|
|
180
|
+
plugin: this.plugin,
|
|
181
|
+
contentType: swaggerPlugin.context.contentType,
|
|
182
|
+
include: void 0,
|
|
183
|
+
override,
|
|
184
|
+
mode,
|
|
185
|
+
output: output.path
|
|
186
|
+
});
|
|
187
|
+
const schemaFiles = await schemaGenerator.build(...generators);
|
|
188
|
+
await this.addFile(...schemaFiles);
|
|
189
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
190
|
+
oas,
|
|
191
|
+
pluginManager: this.pluginManager,
|
|
192
|
+
plugin: this.plugin,
|
|
193
|
+
contentType: swaggerPlugin.context.contentType,
|
|
194
|
+
exclude,
|
|
195
|
+
include,
|
|
196
|
+
override,
|
|
197
|
+
mode
|
|
198
|
+
});
|
|
199
|
+
const operationFiles = await operationGenerator.build(...generators);
|
|
200
|
+
await this.addFile(...operationFiles);
|
|
201
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
202
|
+
type: output.barrelType ?? "named",
|
|
203
|
+
root,
|
|
204
|
+
output,
|
|
205
|
+
files: this.fileManager.files,
|
|
206
|
+
meta: {
|
|
207
|
+
pluginKey: this.plugin.key
|
|
208
|
+
},
|
|
209
|
+
logger: this.logger
|
|
210
|
+
});
|
|
211
|
+
await this.addFile(...barrelFiles);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
var operationsGenerator = pluginOas.createReactGenerator({
|
|
216
|
+
name: "operations",
|
|
217
|
+
Operations({ operations }) {
|
|
218
|
+
const {
|
|
219
|
+
pluginManager,
|
|
220
|
+
plugin: {
|
|
221
|
+
options: { output }
|
|
222
|
+
}
|
|
223
|
+
} = react.useApp();
|
|
224
|
+
const { getFile, groupSchemasByName } = hooks.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__ */ jsxRuntime.jsx(react.File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
231
|
+
}).filter(Boolean);
|
|
232
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: output?.banner, footer: output?.footer, children: [
|
|
233
|
+
imports,
|
|
234
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkFLFW72FT_cjs.Operations, { name, operations: transformedOperations })
|
|
235
|
+
] });
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
exports.operationsGenerator = operationsGenerator;
|
|
240
|
+
exports.pluginZod = pluginZod;
|
|
241
|
+
exports.pluginZodName = pluginZodName;
|
|
242
|
+
exports.zodGenerator = zodGenerator;
|
|
243
|
+
//# sourceMappingURL=chunk-6MMPQJME.cjs.map
|
|
244
|
+
//# sourceMappingURL=chunk-6MMPQJME.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAA;AAE9C,IAAA,MAAM,EAAE,MAAA,EAAQ,aAAe,EAAA,IAAA,KAASC,YAAkB,EAAA,CAAA;AAC1D,IAAA,MAAM,MAAMC,YAAO,EAAA,CAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAQ,EAAA,GAAIC,yBAAoB,EAAA,CAAA;AACpD,IAAA,MAAM,gBAAgBC,sBAAiB,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,IAAIC,yBAAA,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,I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AEJ;AACF,CAAC","file":"chunk-6MMPQJME.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 } = 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, 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 },\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 (options?.tag && group?.type === 'tag') {\n const groupName: Group['name'] = group?.name ? group.name : (ctx) => `${ctx.group}Controller`\n\n return path.resolve(root, output.path, groupName({ group: camelCase(options.tag) }), baseName)\n }\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 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 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"]}
|