@kubb/plugin-zod 3.0.0-alpha.3 → 3.0.0-alpha.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/dist/chunk-FLFW72FT.cjs +344 -0
- package/dist/chunk-FLFW72FT.cjs.map +1 -0
- package/dist/chunk-G6GLWNC4.cjs +245 -0
- package/dist/chunk-G6GLWNC4.cjs.map +1 -0
- package/dist/chunk-KMSM5GLX.js +236 -0
- package/dist/chunk-KMSM5GLX.js.map +1 -0
- package/dist/chunk-UONLSRDV.js +337 -0
- package/dist/chunk-UONLSRDV.js.map +1 -0
- package/dist/components.cjs +11 -6
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +20 -19
- package/dist/components.d.ts +20 -19
- package/dist/components.js +2 -10
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +10 -0
- package/dist/generators.d.ts +10 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +12 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -137
- package/dist/index.d.ts +4 -137
- package/dist/index.js +3 -8
- package/dist/index.js.map +1 -1
- package/dist/types-ryu2n1NA.d.cts +95 -0
- package/dist/types-ryu2n1NA.d.ts +95 -0
- package/package.json +19 -21
- package/src/components/Operations.tsx +19 -103
- package/src/components/Zod.tsx +66 -0
- package/src/components/index.ts +1 -2
- package/src/generators/__snapshots__/anyof.ts +3 -0
- package/src/generators/__snapshots__/createPet.ts +15 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeAny.ts +13 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +15 -0
- package/src/generators/__snapshots__/deletePet.ts +3 -0
- package/src/generators/__snapshots__/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 +28 -46
- package/src/types.ts +42 -88
- package/dist/Operations-BlQtRP31.d.cts +0 -47
- package/dist/Operations-BlQtRP31.d.ts +0 -47
- package/dist/chunk-7X3NWYUN.cjs +0 -1242
- package/dist/chunk-7X3NWYUN.cjs.map +0 -1
- package/dist/chunk-XCGVHLYD.js +0 -1242
- package/dist/chunk-XCGVHLYD.js.map +0 -1
- package/src/SchemaGenerator.tsx +0 -22
- package/src/components/OperationSchema.tsx +0 -64
- package/src/components/Schema.tsx +0 -162
- package/src/components/__snapshots__/operations.ts +0 -50
package/dist/chunk-XCGVHLYD.js
DELETED
|
@@ -1,1242 +0,0 @@
|
|
|
1
|
-
// src/components/Operations.tsx
|
|
2
|
-
import { useOperationManager, useOperations } from "@kubb/plugin-oas/hooks";
|
|
3
|
-
import { Const, File, Parser, useApp } from "@kubb/react";
|
|
4
|
-
import transformers from "@kubb/core/transformers";
|
|
5
|
-
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
6
|
-
function Template({ operationsName, pathsName, operations }) {
|
|
7
|
-
const { groupSchemasByName } = useOperationManager();
|
|
8
|
-
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
9
|
-
const operationsJSON = transformedOperations.reduce(
|
|
10
|
-
(prev, acc) => {
|
|
11
|
-
prev[`"${acc.operation.getOperationId()}"`] = acc.data;
|
|
12
|
-
return prev;
|
|
13
|
-
},
|
|
14
|
-
{}
|
|
15
|
-
);
|
|
16
|
-
const pathsJSON = transformedOperations.reduce(
|
|
17
|
-
(prev, acc) => {
|
|
18
|
-
prev[`"${acc.operation.path}"`] = {
|
|
19
|
-
...prev[`"${acc.operation.path}"`] || {},
|
|
20
|
-
[acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
|
|
21
|
-
};
|
|
22
|
-
return prev;
|
|
23
|
-
},
|
|
24
|
-
{}
|
|
25
|
-
);
|
|
26
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
27
|
-
/* @__PURE__ */ jsx(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers.stringifyObject(operationsJSON)}}` }),
|
|
28
|
-
/* @__PURE__ */ jsx(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers.stringifyObject(pathsJSON)}}` })
|
|
29
|
-
] });
|
|
30
|
-
}
|
|
31
|
-
function RootTemplate({ children }) {
|
|
32
|
-
const {
|
|
33
|
-
mode,
|
|
34
|
-
pluginManager,
|
|
35
|
-
plugin: {
|
|
36
|
-
key: pluginKey,
|
|
37
|
-
options: { extName }
|
|
38
|
-
}
|
|
39
|
-
} = useApp();
|
|
40
|
-
const { getFile } = useOperationManager();
|
|
41
|
-
const operations = useOperations();
|
|
42
|
-
const { groupSchemasByName } = useOperationManager();
|
|
43
|
-
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
44
|
-
const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
|
|
45
|
-
const imports = Object.entries(transformedOperations).map(([_key, { data, operation }], index) => {
|
|
46
|
-
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
47
|
-
return /* @__PURE__ */ jsx(File.Import, { extName, name: names, root: file.path, path: getFile(operation).path }, index);
|
|
48
|
-
}).filter(Boolean);
|
|
49
|
-
return /* @__PURE__ */ jsx(Parser, { language: "typescript", children: /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, exportable: false, children: [
|
|
50
|
-
mode === "split" && imports,
|
|
51
|
-
/* @__PURE__ */ jsx(File.Source, { children })
|
|
52
|
-
] }) });
|
|
53
|
-
}
|
|
54
|
-
var defaultTemplates = { default: Template, root: RootTemplate };
|
|
55
|
-
function Operations({ Template: Template3 = defaultTemplates.default }) {
|
|
56
|
-
const operations = useOperations();
|
|
57
|
-
return /* @__PURE__ */ jsx(Template3, { operationsName: "operations", pathsName: "paths", operations });
|
|
58
|
-
}
|
|
59
|
-
Operations.File = function(props) {
|
|
60
|
-
const templates = { ...defaultTemplates, ...props.templates };
|
|
61
|
-
const Template3 = templates.default;
|
|
62
|
-
const RootTemplate2 = templates.root;
|
|
63
|
-
return /* @__PURE__ */ jsx(RootTemplate2, { children: /* @__PURE__ */ jsx(Operations, { Template: Template3 }) });
|
|
64
|
-
};
|
|
65
|
-
Operations.templates = defaultTemplates;
|
|
66
|
-
|
|
67
|
-
// src/components/Schema.tsx
|
|
68
|
-
import { Oas as Oas6 } from "@kubb/plugin-oas/components";
|
|
69
|
-
import { Const as Const2, File as File6, Type as Type2, useApp as useApp6, useFile } from "@kubb/react";
|
|
70
|
-
|
|
71
|
-
// ../plugin-ts/src/plugin.ts
|
|
72
|
-
import path from "path";
|
|
73
|
-
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
74
|
-
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
75
|
-
import { renderTemplate } from "@kubb/core/utils";
|
|
76
|
-
import { pluginOasName } from "@kubb/plugin-oas";
|
|
77
|
-
|
|
78
|
-
// ../plugin-ts/src/OperationGenerator.tsx
|
|
79
|
-
import { OperationGenerator as Generator2 } from "@kubb/plugin-oas";
|
|
80
|
-
import { Oas as Oas4 } from "@kubb/plugin-oas/components";
|
|
81
|
-
import { App as App2, createRoot as createRoot2 } from "@kubb/react";
|
|
82
|
-
|
|
83
|
-
// ../plugin-ts/src/components/OasType.tsx
|
|
84
|
-
import { Parser as Parser2, File as File2, Type, useApp as useApp2 } from "@kubb/react";
|
|
85
|
-
import { useOas } from "@kubb/plugin-oas/hooks";
|
|
86
|
-
import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
|
|
87
|
-
function Template2({ name, typeName, api }) {
|
|
88
|
-
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
89
|
-
`export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
|
|
90
|
-
/* @__PURE__ */ jsx2("br", {}),
|
|
91
|
-
/* @__PURE__ */ jsx2(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` })
|
|
92
|
-
] });
|
|
93
|
-
}
|
|
94
|
-
var defaultTemplates2 = { default: Template2 };
|
|
95
|
-
function OasType({ name, typeName, Template: Template3 = defaultTemplates2.default }) {
|
|
96
|
-
const oas = useOas();
|
|
97
|
-
return /* @__PURE__ */ jsx2(Template3, { name, typeName, api: oas.api });
|
|
98
|
-
}
|
|
99
|
-
OasType.File = function({ name, typeName, templates = defaultTemplates2 }) {
|
|
100
|
-
const {
|
|
101
|
-
pluginManager,
|
|
102
|
-
plugin: { key: pluginKey }
|
|
103
|
-
} = useApp2();
|
|
104
|
-
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
|
|
105
|
-
const Template3 = templates.default;
|
|
106
|
-
return /* @__PURE__ */ jsx2(Parser2, { language: "typescript", children: /* @__PURE__ */ jsxs2(File2, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
107
|
-
/* @__PURE__ */ jsx2(File2.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
|
|
108
|
-
/* @__PURE__ */ jsx2(File2.Source, { children: /* @__PURE__ */ jsx2(OasType, { Template: Template3, name, typeName }) })
|
|
109
|
-
] }) });
|
|
110
|
-
};
|
|
111
|
-
OasType.templates = defaultTemplates2;
|
|
112
|
-
|
|
113
|
-
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
114
|
-
import transformers4 from "@kubb/core/transformers";
|
|
115
|
-
import { print as print2 } from "@kubb/parser-ts";
|
|
116
|
-
import * as factory3 from "@kubb/parser-ts/factory";
|
|
117
|
-
import { Oas as Oas3 } from "@kubb/plugin-oas/components";
|
|
118
|
-
import { useOas as useOas2, useOperation, useOperationManager as useOperationManager2 } from "@kubb/plugin-oas/hooks";
|
|
119
|
-
import { File as File4, Parser as Parser3, useApp as useApp4 } from "@kubb/react";
|
|
120
|
-
|
|
121
|
-
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
122
|
-
import { SchemaGenerator as Generator } from "@kubb/plugin-oas";
|
|
123
|
-
import { Oas as Oas2 } from "@kubb/plugin-oas/components";
|
|
124
|
-
import { App, createRoot } from "@kubb/react";
|
|
125
|
-
|
|
126
|
-
// ../plugin-ts/src/components/Schema.tsx
|
|
127
|
-
import { Oas } from "@kubb/plugin-oas/components";
|
|
128
|
-
import { File as File3, useApp as useApp3 } from "@kubb/react";
|
|
129
|
-
import transformers3 from "@kubb/core/transformers";
|
|
130
|
-
import { print } from "@kubb/parser-ts";
|
|
131
|
-
import * as factory2 from "@kubb/parser-ts/factory";
|
|
132
|
-
import { SchemaGenerator, schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
|
|
133
|
-
import { useSchema } from "@kubb/plugin-oas/hooks";
|
|
134
|
-
|
|
135
|
-
// ../plugin-ts/src/parser/index.ts
|
|
136
|
-
import transformers2 from "@kubb/core/transformers";
|
|
137
|
-
import * as factory from "@kubb/parser-ts/factory";
|
|
138
|
-
import { isKeyword, schemaKeywords } from "@kubb/plugin-oas";
|
|
139
|
-
var typeKeywordMapper = {
|
|
140
|
-
any: () => factory.keywordTypeNodes.any,
|
|
141
|
-
unknown: () => factory.keywordTypeNodes.unknown,
|
|
142
|
-
number: () => factory.keywordTypeNodes.number,
|
|
143
|
-
integer: () => factory.keywordTypeNodes.number,
|
|
144
|
-
object: (nodes) => {
|
|
145
|
-
if (!nodes || !nodes.length) {
|
|
146
|
-
return factory.keywordTypeNodes.object;
|
|
147
|
-
}
|
|
148
|
-
return factory.createTypeLiteralNode(nodes);
|
|
149
|
-
},
|
|
150
|
-
string: () => factory.keywordTypeNodes.string,
|
|
151
|
-
boolean: () => factory.keywordTypeNodes.boolean,
|
|
152
|
-
undefined: () => factory.keywordTypeNodes.undefined,
|
|
153
|
-
nullable: void 0,
|
|
154
|
-
null: () => factory.keywordTypeNodes.null,
|
|
155
|
-
nullish: void 0,
|
|
156
|
-
array: (nodes) => {
|
|
157
|
-
if (!nodes) {
|
|
158
|
-
return void 0;
|
|
159
|
-
}
|
|
160
|
-
return factory.createArrayDeclaration({ nodes });
|
|
161
|
-
},
|
|
162
|
-
tuple: (nodes) => {
|
|
163
|
-
if (!nodes) {
|
|
164
|
-
return void 0;
|
|
165
|
-
}
|
|
166
|
-
return factory.createTupleTypeNode(nodes);
|
|
167
|
-
},
|
|
168
|
-
enum: (name) => {
|
|
169
|
-
if (!name) {
|
|
170
|
-
return void 0;
|
|
171
|
-
}
|
|
172
|
-
return factory.createTypeReferenceNode(name, void 0);
|
|
173
|
-
},
|
|
174
|
-
union: (nodes) => {
|
|
175
|
-
if (!nodes) {
|
|
176
|
-
return void 0;
|
|
177
|
-
}
|
|
178
|
-
return factory.createUnionDeclaration({
|
|
179
|
-
withParentheses: true,
|
|
180
|
-
nodes
|
|
181
|
-
});
|
|
182
|
-
},
|
|
183
|
-
const: (name, format) => {
|
|
184
|
-
if (!name) {
|
|
185
|
-
return void 0;
|
|
186
|
-
}
|
|
187
|
-
if (format === "number") {
|
|
188
|
-
return factory.createLiteralTypeNode(factory.createNumericLiteral(name));
|
|
189
|
-
}
|
|
190
|
-
return factory.createLiteralTypeNode(factory.createStringLiteral(name.toString()));
|
|
191
|
-
},
|
|
192
|
-
datetime: () => factory.keywordTypeNodes.string,
|
|
193
|
-
date: (type = "string") => type === "string" ? factory.keywordTypeNodes.string : factory.createTypeReferenceNode(factory.createIdentifier("Date")),
|
|
194
|
-
time: (type = "string") => type === "string" ? factory.keywordTypeNodes.string : factory.createTypeReferenceNode(factory.createIdentifier("Date")),
|
|
195
|
-
uuid: void 0,
|
|
196
|
-
url: void 0,
|
|
197
|
-
strict: void 0,
|
|
198
|
-
default: void 0,
|
|
199
|
-
and: (nodes) => {
|
|
200
|
-
if (!nodes) {
|
|
201
|
-
return void 0;
|
|
202
|
-
}
|
|
203
|
-
return factory.createIntersectionDeclaration({
|
|
204
|
-
withParentheses: true,
|
|
205
|
-
nodes
|
|
206
|
-
});
|
|
207
|
-
},
|
|
208
|
-
describe: void 0,
|
|
209
|
-
min: void 0,
|
|
210
|
-
max: void 0,
|
|
211
|
-
optional: void 0,
|
|
212
|
-
matches: void 0,
|
|
213
|
-
email: void 0,
|
|
214
|
-
firstName: void 0,
|
|
215
|
-
lastName: void 0,
|
|
216
|
-
password: void 0,
|
|
217
|
-
phone: void 0,
|
|
218
|
-
readOnly: void 0,
|
|
219
|
-
ref: (propertyName) => {
|
|
220
|
-
if (!propertyName) {
|
|
221
|
-
return void 0;
|
|
222
|
-
}
|
|
223
|
-
return factory.createTypeReferenceNode(propertyName, void 0);
|
|
224
|
-
},
|
|
225
|
-
blob: () => factory.createTypeReferenceNode("Blob", []),
|
|
226
|
-
deprecated: void 0,
|
|
227
|
-
example: void 0,
|
|
228
|
-
schema: void 0,
|
|
229
|
-
catchall: void 0,
|
|
230
|
-
name: void 0
|
|
231
|
-
};
|
|
232
|
-
function parse(parent, current, options) {
|
|
233
|
-
const value = typeKeywordMapper[current.keyword];
|
|
234
|
-
if (!value) {
|
|
235
|
-
return void 0;
|
|
236
|
-
}
|
|
237
|
-
if (isKeyword(current, schemaKeywords.union)) {
|
|
238
|
-
return typeKeywordMapper.union(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
239
|
-
}
|
|
240
|
-
if (isKeyword(current, schemaKeywords.and)) {
|
|
241
|
-
return typeKeywordMapper.and(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
242
|
-
}
|
|
243
|
-
if (isKeyword(current, schemaKeywords.array)) {
|
|
244
|
-
return typeKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
245
|
-
}
|
|
246
|
-
if (isKeyword(current, schemaKeywords.enum)) {
|
|
247
|
-
return typeKeywordMapper.enum(current.args.typeName);
|
|
248
|
-
}
|
|
249
|
-
if (isKeyword(current, schemaKeywords.ref)) {
|
|
250
|
-
return typeKeywordMapper.ref(current.args.name);
|
|
251
|
-
}
|
|
252
|
-
if (isKeyword(current, schemaKeywords.blob)) {
|
|
253
|
-
return value();
|
|
254
|
-
}
|
|
255
|
-
if (isKeyword(current, schemaKeywords.tuple)) {
|
|
256
|
-
return typeKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
257
|
-
}
|
|
258
|
-
if (isKeyword(current, schemaKeywords.const)) {
|
|
259
|
-
return typeKeywordMapper.const(current.args.name, current.args.format);
|
|
260
|
-
}
|
|
261
|
-
if (isKeyword(current, schemaKeywords.object)) {
|
|
262
|
-
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
263
|
-
const schemas = item[1];
|
|
264
|
-
return schemas && typeof schemas.map === "function";
|
|
265
|
-
}).map(([name, schemas]) => {
|
|
266
|
-
const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name);
|
|
267
|
-
const mappedName = nameSchema?.args || name;
|
|
268
|
-
if (options.mapper?.[mappedName]) {
|
|
269
|
-
return options.mapper?.[mappedName];
|
|
270
|
-
}
|
|
271
|
-
const isNullish = schemas.some((schema) => schema.keyword === schemaKeywords.nullish);
|
|
272
|
-
const isNullable = schemas.some((schema) => schema.keyword === schemaKeywords.nullable);
|
|
273
|
-
const isOptional = schemas.some((schema) => schema.keyword === schemaKeywords.optional);
|
|
274
|
-
const isReadonly = schemas.some((schema) => schema.keyword === schemaKeywords.readOnly);
|
|
275
|
-
const describeSchema = schemas.find((schema) => schema.keyword === schemaKeywords.describe);
|
|
276
|
-
const deprecatedSchema = schemas.find((schema) => schema.keyword === schemaKeywords.deprecated);
|
|
277
|
-
const defaultSchema = schemas.find((schema) => schema.keyword === schemaKeywords.default);
|
|
278
|
-
const exampleSchema = schemas.find((schema) => schema.keyword === schemaKeywords.example);
|
|
279
|
-
const schemaSchema = schemas.find((schema) => schema.keyword === schemaKeywords.schema);
|
|
280
|
-
let type = schemas.map((schema) => parse(current, schema, options)).filter(Boolean)[0];
|
|
281
|
-
if (isNullable) {
|
|
282
|
-
type = factory.createUnionDeclaration({
|
|
283
|
-
nodes: [type, factory.keywordTypeNodes.null]
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
|
|
287
|
-
type = factory.createUnionDeclaration({
|
|
288
|
-
nodes: [type, factory.keywordTypeNodes.undefined]
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
|
|
292
|
-
type = factory.createUnionDeclaration({
|
|
293
|
-
nodes: [type, factory.keywordTypeNodes.undefined]
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
const propertySignature = factory.createPropertySignature({
|
|
297
|
-
questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
|
|
298
|
-
name: mappedName,
|
|
299
|
-
type,
|
|
300
|
-
readOnly: isReadonly
|
|
301
|
-
});
|
|
302
|
-
return factory.appendJSDocToNode({
|
|
303
|
-
node: propertySignature,
|
|
304
|
-
comments: [
|
|
305
|
-
describeSchema ? `@description ${transformers2.jsStringEscape(describeSchema.args)}` : void 0,
|
|
306
|
-
deprecatedSchema ? "@deprecated" : void 0,
|
|
307
|
-
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
|
308
|
-
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
|
309
|
-
schemaSchema?.args?.type || schemaSchema?.args?.format ? [`@type ${schemaSchema?.args?.type || "unknown"}${!isOptional ? "" : " | undefined"}`, schemaSchema?.args?.format].filter(Boolean).join(", ") : void 0
|
|
310
|
-
].filter(Boolean)
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
const additionalProperties = current.args?.additionalProperties?.length ? factory.createIndexSignature(
|
|
314
|
-
current.args.additionalProperties.map((schema) => parse(current, schema, options)).filter(Boolean).at(0)
|
|
315
|
-
) : void 0;
|
|
316
|
-
return typeKeywordMapper.object([...properties, additionalProperties].filter(Boolean));
|
|
317
|
-
}
|
|
318
|
-
if (isKeyword(current, schemaKeywords.datetime)) {
|
|
319
|
-
return typeKeywordMapper.datetime();
|
|
320
|
-
}
|
|
321
|
-
if (isKeyword(current, schemaKeywords.date)) {
|
|
322
|
-
return typeKeywordMapper.date(current.args.type);
|
|
323
|
-
}
|
|
324
|
-
if (isKeyword(current, schemaKeywords.time)) {
|
|
325
|
-
return typeKeywordMapper.time(current.args.type);
|
|
326
|
-
}
|
|
327
|
-
if (current.keyword in typeKeywordMapper) {
|
|
328
|
-
return value();
|
|
329
|
-
}
|
|
330
|
-
return void 0;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// ../plugin-ts/src/components/Schema.tsx
|
|
334
|
-
import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
|
|
335
|
-
function Schema(props) {
|
|
336
|
-
const { keysToOmit, description } = props;
|
|
337
|
-
const { tree, name } = useSchema();
|
|
338
|
-
const {
|
|
339
|
-
pluginManager,
|
|
340
|
-
plugin: {
|
|
341
|
-
options: { mapper, enumType, optionalType }
|
|
342
|
-
}
|
|
343
|
-
} = useApp3();
|
|
344
|
-
const resolvedName = pluginManager.resolveName({
|
|
345
|
-
name,
|
|
346
|
-
pluginKey: [pluginTsName],
|
|
347
|
-
type: "function"
|
|
348
|
-
});
|
|
349
|
-
const typeName = pluginManager.resolveName({
|
|
350
|
-
name,
|
|
351
|
-
pluginKey: [pluginTsName],
|
|
352
|
-
type: "type"
|
|
353
|
-
});
|
|
354
|
-
const nodes = [];
|
|
355
|
-
const extraNodes = [];
|
|
356
|
-
if (!tree.length) {
|
|
357
|
-
return "";
|
|
358
|
-
}
|
|
359
|
-
const isNullish = tree.some((item) => item.keyword === schemaKeywords2.nullish);
|
|
360
|
-
const isNullable = tree.some((item) => item.keyword === schemaKeywords2.nullable);
|
|
361
|
-
const isOptional = tree.some((item) => item.keyword === schemaKeywords2.optional);
|
|
362
|
-
let type = tree.map((schema) => parse(void 0, schema, { name: resolvedName, typeName, description, keysToOmit, optionalType, enumType, mapper })).filter(Boolean).at(0) || typeKeywordMapper.undefined();
|
|
363
|
-
if (isNullable) {
|
|
364
|
-
type = factory2.createUnionDeclaration({
|
|
365
|
-
nodes: [type, factory2.keywordTypeNodes.null]
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
369
|
-
type = factory2.createUnionDeclaration({
|
|
370
|
-
nodes: [type, factory2.keywordTypeNodes.undefined]
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
374
|
-
type = factory2.createUnionDeclaration({
|
|
375
|
-
nodes: [type, factory2.keywordTypeNodes.undefined]
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
const node = factory2.createTypeAliasDeclaration({
|
|
379
|
-
modifiers: [factory2.modifiers.export],
|
|
380
|
-
name: resolvedName,
|
|
381
|
-
type: keysToOmit?.length ? factory2.createOmitDeclaration({
|
|
382
|
-
keys: keysToOmit,
|
|
383
|
-
type,
|
|
384
|
-
nonNullable: true
|
|
385
|
-
}) : type
|
|
386
|
-
});
|
|
387
|
-
const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords2.enum);
|
|
388
|
-
if (enumSchemas) {
|
|
389
|
-
enumSchemas.forEach((enumSchema) => {
|
|
390
|
-
extraNodes.push(
|
|
391
|
-
...factory2.createEnumDeclaration({
|
|
392
|
-
name: transformers3.camelCase(enumSchema.args.name),
|
|
393
|
-
typeName: enumSchema.args.typeName,
|
|
394
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers3.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
|
|
395
|
-
type: enumType
|
|
396
|
-
})
|
|
397
|
-
);
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
nodes.push(
|
|
401
|
-
factory2.appendJSDocToNode({
|
|
402
|
-
node,
|
|
403
|
-
comments: [description ? `@description ${transformers3.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
404
|
-
})
|
|
405
|
-
);
|
|
406
|
-
const filterdNodes = nodes.filter(
|
|
407
|
-
(node2) => !extraNodes.some(
|
|
408
|
-
(extraNode) => extraNode?.name?.escapedText === node2?.name?.escapedText
|
|
409
|
-
)
|
|
410
|
-
);
|
|
411
|
-
return print([...extraNodes, ...filterdNodes]);
|
|
412
|
-
}
|
|
413
|
-
Schema.File = function({}) {
|
|
414
|
-
const { pluginManager } = useApp3();
|
|
415
|
-
const { schema } = useSchema();
|
|
416
|
-
return /* @__PURE__ */ jsx3(Oas.Schema.File, { output: pluginManager.config.output.path, children: /* @__PURE__ */ jsx3(File3.Source, { children: /* @__PURE__ */ jsx3(Schema, { description: schema?.description }) }) });
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
420
|
-
import { jsx as jsx4 } from "@kubb/react/jsx-runtime";
|
|
421
|
-
var SchemaGenerator2 = class extends Generator {
|
|
422
|
-
async schema(name, schema, options) {
|
|
423
|
-
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
424
|
-
const root = createRoot({
|
|
425
|
-
logger: pluginManager.logger
|
|
426
|
-
});
|
|
427
|
-
const tree = this.parse({ schema, name });
|
|
428
|
-
root.render(
|
|
429
|
-
/* @__PURE__ */ jsx4(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx4(Oas2, { oas, children: /* @__PURE__ */ jsx4(Oas2.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx4(Schema.File, {}) }) }) })
|
|
430
|
-
);
|
|
431
|
-
return root.files;
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
436
|
-
import { jsx as jsx5, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
|
|
437
|
-
function printCombinedSchema({
|
|
438
|
-
name,
|
|
439
|
-
operation,
|
|
440
|
-
schemas,
|
|
441
|
-
pluginManager
|
|
442
|
-
}) {
|
|
443
|
-
const properties = {};
|
|
444
|
-
if (schemas.response) {
|
|
445
|
-
const identifier = pluginManager.resolveName({
|
|
446
|
-
name: schemas.response.name,
|
|
447
|
-
pluginKey: [pluginTsName],
|
|
448
|
-
type: "function"
|
|
449
|
-
});
|
|
450
|
-
properties["response"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
451
|
-
}
|
|
452
|
-
if (schemas.request) {
|
|
453
|
-
const identifier = pluginManager.resolveName({
|
|
454
|
-
name: schemas.request.name,
|
|
455
|
-
pluginKey: [pluginTsName],
|
|
456
|
-
type: "function"
|
|
457
|
-
});
|
|
458
|
-
properties["request"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
459
|
-
}
|
|
460
|
-
if (schemas.pathParams) {
|
|
461
|
-
const identifier = pluginManager.resolveName({
|
|
462
|
-
name: schemas.pathParams.name,
|
|
463
|
-
pluginKey: [pluginTsName],
|
|
464
|
-
type: "function"
|
|
465
|
-
});
|
|
466
|
-
properties["pathParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
467
|
-
}
|
|
468
|
-
if (schemas.queryParams) {
|
|
469
|
-
const identifier = pluginManager.resolveName({
|
|
470
|
-
name: schemas.queryParams.name,
|
|
471
|
-
pluginKey: [pluginTsName],
|
|
472
|
-
type: "function"
|
|
473
|
-
});
|
|
474
|
-
properties["queryParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
475
|
-
}
|
|
476
|
-
if (schemas.headerParams) {
|
|
477
|
-
const identifier = pluginManager.resolveName({
|
|
478
|
-
name: schemas.headerParams.name,
|
|
479
|
-
pluginKey: [pluginTsName],
|
|
480
|
-
type: "function"
|
|
481
|
-
});
|
|
482
|
-
properties["headerParams"] = factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
483
|
-
}
|
|
484
|
-
if (schemas.errors) {
|
|
485
|
-
properties["errors"] = factory3.createUnionDeclaration({
|
|
486
|
-
nodes: schemas.errors.map((error) => {
|
|
487
|
-
const identifier = pluginManager.resolveName({
|
|
488
|
-
name: error.name,
|
|
489
|
-
pluginKey: [pluginTsName],
|
|
490
|
-
type: "function"
|
|
491
|
-
});
|
|
492
|
-
return factory3.createTypeReferenceNode(factory3.createIdentifier(identifier), void 0);
|
|
493
|
-
})
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
const namespaceNode = factory3.createTypeAliasDeclaration({
|
|
497
|
-
name: operation.method === "get" ? `${name}Query` : `${name}Mutation`,
|
|
498
|
-
type: factory3.createTypeLiteralNode(
|
|
499
|
-
Object.keys(properties).map((key) => {
|
|
500
|
-
const type = properties[key];
|
|
501
|
-
if (!type) {
|
|
502
|
-
return void 0;
|
|
503
|
-
}
|
|
504
|
-
return factory3.createPropertySignature({
|
|
505
|
-
name: transformers4.pascalCase(key),
|
|
506
|
-
type
|
|
507
|
-
});
|
|
508
|
-
}).filter(Boolean)
|
|
509
|
-
),
|
|
510
|
-
modifiers: [factory3.modifiers.export]
|
|
511
|
-
});
|
|
512
|
-
return print2(namespaceNode);
|
|
513
|
-
}
|
|
514
|
-
function OperationSchema({ keysToOmit, description }) {
|
|
515
|
-
return /* @__PURE__ */ jsx5(Schema, { keysToOmit, description });
|
|
516
|
-
}
|
|
517
|
-
OperationSchema.File = function({}) {
|
|
518
|
-
const { pluginManager, plugin, mode, fileManager } = useApp4();
|
|
519
|
-
const oas = useOas2();
|
|
520
|
-
const { getSchemas, getFile, getName } = useOperationManager2();
|
|
521
|
-
const operation = useOperation();
|
|
522
|
-
const file = getFile(operation);
|
|
523
|
-
const schemas = getSchemas(operation);
|
|
524
|
-
const factoryName = getName(operation, { type: "type" });
|
|
525
|
-
const generator = new SchemaGenerator2(plugin.options, {
|
|
526
|
-
oas,
|
|
527
|
-
plugin,
|
|
528
|
-
pluginManager,
|
|
529
|
-
mode,
|
|
530
|
-
override: plugin.options.override
|
|
531
|
-
});
|
|
532
|
-
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
533
|
-
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
534
|
-
const tree = generator.parse({ schema, name });
|
|
535
|
-
return /* @__PURE__ */ jsxs3(Oas3.Schema, { name, value: schema, tree, children: [
|
|
536
|
-
mode === "split" && /* @__PURE__ */ jsx5(Oas3.Schema.Imports, { extName: plugin.options.extName, isTypeOnly: true }),
|
|
537
|
-
/* @__PURE__ */ jsx5(File4.Source, { children: /* @__PURE__ */ jsx5(OperationSchema, { description, keysToOmit }) })
|
|
538
|
-
] }, i);
|
|
539
|
-
};
|
|
540
|
-
return /* @__PURE__ */ jsx5(Parser3, { language: "typescript", children: /* @__PURE__ */ jsxs3(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
541
|
-
items.map(mapItem),
|
|
542
|
-
/* @__PURE__ */ jsx5(File4.Source, { children: printCombinedSchema({ name: factoryName, operation, schemas, pluginManager }) })
|
|
543
|
-
] }) });
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
// ../plugin-ts/src/OperationGenerator.tsx
|
|
547
|
-
import { jsx as jsx6 } from "@kubb/react/jsx-runtime";
|
|
548
|
-
var OperationGenerator = class extends Generator2 {
|
|
549
|
-
async all(operations) {
|
|
550
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
551
|
-
const root = createRoot2({
|
|
552
|
-
logger: pluginManager.logger
|
|
553
|
-
});
|
|
554
|
-
root.render(
|
|
555
|
-
/* @__PURE__ */ jsx6(App2, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx6(Oas4, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsx6(OasType.File, { name: "oas", typeName: "Oas" }) }) })
|
|
556
|
-
);
|
|
557
|
-
return root.files;
|
|
558
|
-
}
|
|
559
|
-
async operation(operation, options) {
|
|
560
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
561
|
-
const root = createRoot2({
|
|
562
|
-
logger: pluginManager.logger
|
|
563
|
-
});
|
|
564
|
-
root.render(
|
|
565
|
-
/* @__PURE__ */ jsx6(App2, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx6(Oas4, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx6(Oas4.Operation, { operation, children: /* @__PURE__ */ jsx6(OperationSchema.File, {}) }) }) })
|
|
566
|
-
);
|
|
567
|
-
return root.files;
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
// ../plugin-ts/src/plugin.ts
|
|
572
|
-
var pluginTsName = "plugin-ts";
|
|
573
|
-
var pluginTs = createPlugin((options) => {
|
|
574
|
-
const {
|
|
575
|
-
output = { path: "types" },
|
|
576
|
-
group,
|
|
577
|
-
exclude = [],
|
|
578
|
-
include,
|
|
579
|
-
override = [],
|
|
580
|
-
enumType = "asConst",
|
|
581
|
-
enumSuffix = "",
|
|
582
|
-
dateType = "string",
|
|
583
|
-
unknownType = "any",
|
|
584
|
-
optionalType = "questionToken",
|
|
585
|
-
transformers: transformers7 = {},
|
|
586
|
-
oasType = false,
|
|
587
|
-
mapper = {}
|
|
588
|
-
} = options;
|
|
589
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
590
|
-
return {
|
|
591
|
-
name: pluginTsName,
|
|
592
|
-
options: {
|
|
593
|
-
extName: output.extName,
|
|
594
|
-
transformers: transformers7,
|
|
595
|
-
dateType,
|
|
596
|
-
optionalType,
|
|
597
|
-
oasType,
|
|
598
|
-
enumType,
|
|
599
|
-
enumSuffix,
|
|
600
|
-
// keep the used enumnames between SchemaGenerator and OperationGenerator per plugin(pluginKey)
|
|
601
|
-
usedEnumNames: {},
|
|
602
|
-
unknownType,
|
|
603
|
-
override,
|
|
604
|
-
mapper
|
|
605
|
-
},
|
|
606
|
-
pre: [pluginOasName],
|
|
607
|
-
resolvePath(baseName, pathMode, options2) {
|
|
608
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
609
|
-
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
610
|
-
if (mode === "single") {
|
|
611
|
-
return path.resolve(root, output.path);
|
|
612
|
-
}
|
|
613
|
-
if (options2?.tag && group?.type === "tag") {
|
|
614
|
-
const tag = camelCase(options2.tag);
|
|
615
|
-
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
616
|
-
}
|
|
617
|
-
return path.resolve(root, output.path, baseName);
|
|
618
|
-
},
|
|
619
|
-
resolveName(name, type) {
|
|
620
|
-
const resolvedName = pascalCase(name, { isFile: type === "file" });
|
|
621
|
-
if (type) {
|
|
622
|
-
return transformers7?.name?.(resolvedName, type) || resolvedName;
|
|
623
|
-
}
|
|
624
|
-
return resolvedName;
|
|
625
|
-
},
|
|
626
|
-
async buildStart() {
|
|
627
|
-
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
628
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
629
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
630
|
-
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
631
|
-
const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
|
|
632
|
-
oas,
|
|
633
|
-
pluginManager: this.pluginManager,
|
|
634
|
-
plugin: this.plugin,
|
|
635
|
-
contentType: swaggerPlugin.context.contentType,
|
|
636
|
-
include: void 0,
|
|
637
|
-
override,
|
|
638
|
-
mode,
|
|
639
|
-
output: output.path
|
|
640
|
-
});
|
|
641
|
-
const schemaFiles = await schemaGenerator.build();
|
|
642
|
-
await this.addFile(...schemaFiles);
|
|
643
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
644
|
-
oas,
|
|
645
|
-
pluginManager: this.pluginManager,
|
|
646
|
-
plugin: this.plugin,
|
|
647
|
-
contentType: swaggerPlugin.context.contentType,
|
|
648
|
-
exclude,
|
|
649
|
-
include,
|
|
650
|
-
override,
|
|
651
|
-
mode
|
|
652
|
-
});
|
|
653
|
-
const operationFiles = await operationGenerator.build();
|
|
654
|
-
await this.addFile(...operationFiles);
|
|
655
|
-
},
|
|
656
|
-
async buildEnd() {
|
|
657
|
-
if (this.config.output.write === false) {
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
const root = path.resolve(this.config.root, this.config.output.path);
|
|
661
|
-
await this.fileManager.addIndexes({
|
|
662
|
-
root,
|
|
663
|
-
output,
|
|
664
|
-
meta: { pluginKey: this.plugin.key },
|
|
665
|
-
logger: this.logger
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
};
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
// src/components/Schema.tsx
|
|
672
|
-
import transformers6 from "@kubb/core/transformers";
|
|
673
|
-
import { isKeyword as isKeyword3, schemaKeywords as schemaKeywords5 } from "@kubb/plugin-oas";
|
|
674
|
-
import { useSchema as useSchema2 } from "@kubb/plugin-oas/hooks";
|
|
675
|
-
|
|
676
|
-
// src/parser/index.ts
|
|
677
|
-
import transformers5 from "@kubb/core/transformers";
|
|
678
|
-
import { isKeyword as isKeyword2, schemaKeywords as schemaKeywords3 } from "@kubb/plugin-oas";
|
|
679
|
-
var zodKeywordMapper = {
|
|
680
|
-
any: () => "z.any()",
|
|
681
|
-
unknown: () => "z.unknown()",
|
|
682
|
-
number: (coercion, min, max) => {
|
|
683
|
-
return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
684
|
-
},
|
|
685
|
-
integer: (coercion, min, max) => {
|
|
686
|
-
return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
687
|
-
},
|
|
688
|
-
object: (value) => `z.object({${value}})`,
|
|
689
|
-
string: (coercion, min, max) => {
|
|
690
|
-
return [coercion ? "z.coerce.string()" : "z.string()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
691
|
-
},
|
|
692
|
-
boolean: () => "z.boolean()",
|
|
693
|
-
undefined: () => "z.undefined()",
|
|
694
|
-
nullable: () => ".nullable()",
|
|
695
|
-
null: () => "z.null()",
|
|
696
|
-
nullish: () => ".nullish()",
|
|
697
|
-
array: (items = [], min, max) => {
|
|
698
|
-
return [`z.array(${items?.join("")})`, min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
699
|
-
},
|
|
700
|
-
tuple: (items = []) => `z.tuple([${items?.join(", ")}])`,
|
|
701
|
-
enum: (items = []) => `z.enum([${items?.join(", ")}])`,
|
|
702
|
-
union: (items = []) => `z.union([${items?.join(", ")}])`,
|
|
703
|
-
const: (value) => `z.literal(${value ?? ""})`,
|
|
704
|
-
/**
|
|
705
|
-
* ISO 8601
|
|
706
|
-
*/
|
|
707
|
-
datetime: (offset = false, local = false) => {
|
|
708
|
-
if (offset) {
|
|
709
|
-
return `z.string().datetime({ offset: ${offset} })`;
|
|
710
|
-
}
|
|
711
|
-
if (local) {
|
|
712
|
-
return `z.string().datetime({ local: ${local} })`;
|
|
713
|
-
}
|
|
714
|
-
return "z.string().datetime()";
|
|
715
|
-
},
|
|
716
|
-
/**
|
|
717
|
-
* Type `'date'` Date
|
|
718
|
-
* Type `'string'` ISO date format (YYYY-MM-DD)
|
|
719
|
-
* @default ISO date format (YYYY-MM-DD)
|
|
720
|
-
*/
|
|
721
|
-
date: (type = "string", coercion) => {
|
|
722
|
-
if (type === "string") {
|
|
723
|
-
return "z.string().date()";
|
|
724
|
-
}
|
|
725
|
-
if (coercion) {
|
|
726
|
-
return "z.coerce.date()";
|
|
727
|
-
}
|
|
728
|
-
return "z.date()";
|
|
729
|
-
},
|
|
730
|
-
/**
|
|
731
|
-
* Type `'date'` Date
|
|
732
|
-
* Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
|
|
733
|
-
* @default ISO time format (HH:mm:ss[.SSSSSS])
|
|
734
|
-
*/
|
|
735
|
-
time: (type = "string", coercion) => {
|
|
736
|
-
if (type === "string") {
|
|
737
|
-
return "z.string().time()";
|
|
738
|
-
}
|
|
739
|
-
if (coercion) {
|
|
740
|
-
return "z.coerce.date()";
|
|
741
|
-
}
|
|
742
|
-
return "z.date()";
|
|
743
|
-
},
|
|
744
|
-
uuid: () => ".uuid()",
|
|
745
|
-
url: () => ".url()",
|
|
746
|
-
strict: () => ".strict()",
|
|
747
|
-
default: (value) => `.default(${value ?? ""})`,
|
|
748
|
-
and: (items = []) => items?.map((item) => `.and(${item})`).join(""),
|
|
749
|
-
describe: (value = "") => `.describe(${value})`,
|
|
750
|
-
min: (value) => `.min(${value ?? ""})`,
|
|
751
|
-
max: (value) => `.max(${value ?? ""})`,
|
|
752
|
-
optional: () => ".optional()",
|
|
753
|
-
matches: (value = "") => `.regex(${value})`,
|
|
754
|
-
email: () => ".email()",
|
|
755
|
-
firstName: void 0,
|
|
756
|
-
lastName: void 0,
|
|
757
|
-
password: void 0,
|
|
758
|
-
phone: void 0,
|
|
759
|
-
readOnly: void 0,
|
|
760
|
-
ref: (value) => value ? `z.lazy(() => ${value})` : void 0,
|
|
761
|
-
blob: () => "z.string()",
|
|
762
|
-
deprecated: void 0,
|
|
763
|
-
example: void 0,
|
|
764
|
-
schema: void 0,
|
|
765
|
-
catchall: (value) => value ? `.catchall(${value})` : void 0,
|
|
766
|
-
name: void 0
|
|
767
|
-
};
|
|
768
|
-
function sort(items) {
|
|
769
|
-
const order = [
|
|
770
|
-
schemaKeywords3.string,
|
|
771
|
-
schemaKeywords3.datetime,
|
|
772
|
-
schemaKeywords3.date,
|
|
773
|
-
schemaKeywords3.time,
|
|
774
|
-
schemaKeywords3.tuple,
|
|
775
|
-
schemaKeywords3.number,
|
|
776
|
-
schemaKeywords3.object,
|
|
777
|
-
schemaKeywords3.enum,
|
|
778
|
-
schemaKeywords3.url,
|
|
779
|
-
schemaKeywords3.email,
|
|
780
|
-
schemaKeywords3.firstName,
|
|
781
|
-
schemaKeywords3.lastName,
|
|
782
|
-
schemaKeywords3.password,
|
|
783
|
-
schemaKeywords3.matches,
|
|
784
|
-
schemaKeywords3.uuid,
|
|
785
|
-
schemaKeywords3.min,
|
|
786
|
-
schemaKeywords3.max,
|
|
787
|
-
schemaKeywords3.default,
|
|
788
|
-
schemaKeywords3.describe,
|
|
789
|
-
schemaKeywords3.optional,
|
|
790
|
-
schemaKeywords3.nullable,
|
|
791
|
-
schemaKeywords3.nullish,
|
|
792
|
-
schemaKeywords3.null
|
|
793
|
-
];
|
|
794
|
-
if (!items) {
|
|
795
|
-
return [];
|
|
796
|
-
}
|
|
797
|
-
return transformers5.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
|
|
798
|
-
}
|
|
799
|
-
function parse2(parent, current, options) {
|
|
800
|
-
const value = zodKeywordMapper[current.keyword];
|
|
801
|
-
if (!value) {
|
|
802
|
-
return void 0;
|
|
803
|
-
}
|
|
804
|
-
if (isKeyword2(current, schemaKeywords3.union)) {
|
|
805
|
-
if (Array.isArray(current.args) && current.args.length === 1) {
|
|
806
|
-
return parse2(parent, current.args[0], options);
|
|
807
|
-
}
|
|
808
|
-
if (Array.isArray(current.args) && !current.args.length) {
|
|
809
|
-
return "";
|
|
810
|
-
}
|
|
811
|
-
return zodKeywordMapper.union(
|
|
812
|
-
sort(current.args).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
813
|
-
);
|
|
814
|
-
}
|
|
815
|
-
if (isKeyword2(current, schemaKeywords3.and)) {
|
|
816
|
-
const items = sort(current.args).filter((schema) => {
|
|
817
|
-
return ![schemaKeywords3.optional, schemaKeywords3.describe].includes(schema.keyword);
|
|
818
|
-
}).map((schema) => parse2(current, schema, options)).filter(Boolean);
|
|
819
|
-
return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
|
|
820
|
-
}
|
|
821
|
-
if (isKeyword2(current, schemaKeywords3.array)) {
|
|
822
|
-
return zodKeywordMapper.array(
|
|
823
|
-
sort(current.args.items).map((schemas) => parse2(current, schemas, options)).filter(Boolean),
|
|
824
|
-
current.args.min,
|
|
825
|
-
current.args.max
|
|
826
|
-
);
|
|
827
|
-
}
|
|
828
|
-
if (isKeyword2(current, schemaKeywords3.enum)) {
|
|
829
|
-
if (current.args.asConst) {
|
|
830
|
-
return zodKeywordMapper.union(
|
|
831
|
-
current.args.items.map((schema) => {
|
|
832
|
-
return parse2(
|
|
833
|
-
current,
|
|
834
|
-
{
|
|
835
|
-
keyword: schemaKeywords3.const,
|
|
836
|
-
args: schema
|
|
837
|
-
},
|
|
838
|
-
options
|
|
839
|
-
);
|
|
840
|
-
}).filter(Boolean)
|
|
841
|
-
);
|
|
842
|
-
}
|
|
843
|
-
return zodKeywordMapper.enum(
|
|
844
|
-
current.args.items.map((schema) => {
|
|
845
|
-
if (schema.format === "number") {
|
|
846
|
-
return transformers5.stringify(schema.value);
|
|
847
|
-
}
|
|
848
|
-
return transformers5.stringify(schema.value);
|
|
849
|
-
})
|
|
850
|
-
);
|
|
851
|
-
}
|
|
852
|
-
if (isKeyword2(current, schemaKeywords3.ref)) {
|
|
853
|
-
return zodKeywordMapper.ref(current.args?.name);
|
|
854
|
-
}
|
|
855
|
-
if (isKeyword2(current, schemaKeywords3.object)) {
|
|
856
|
-
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
857
|
-
const schema = item[1];
|
|
858
|
-
return schema && typeof schema.map === "function";
|
|
859
|
-
}).map(([name, schemas]) => {
|
|
860
|
-
const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords3.name);
|
|
861
|
-
const mappedName = nameSchema?.args || name;
|
|
862
|
-
if (options.mapper?.[mappedName]) {
|
|
863
|
-
return `"${name}": ${options.mapper?.[mappedName]}`;
|
|
864
|
-
}
|
|
865
|
-
return `"${name}": ${sort(schemas).map((schema, array) => {
|
|
866
|
-
return parse2(current, schema, options);
|
|
867
|
-
}).filter(Boolean).join("")}`;
|
|
868
|
-
}).join(",");
|
|
869
|
-
const additionalProperties = current.args?.additionalProperties?.length ? current.args.additionalProperties.map((schema) => parse2(current, schema, options)).filter(Boolean).at(0) : void 0;
|
|
870
|
-
const text = [
|
|
871
|
-
zodKeywordMapper.object(properties),
|
|
872
|
-
current.args?.strict ? zodKeywordMapper.strict() : void 0,
|
|
873
|
-
additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0
|
|
874
|
-
].filter(Boolean);
|
|
875
|
-
return text.join("");
|
|
876
|
-
}
|
|
877
|
-
if (isKeyword2(current, schemaKeywords3.tuple)) {
|
|
878
|
-
return zodKeywordMapper.tuple(
|
|
879
|
-
sort(current.args.items).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
880
|
-
);
|
|
881
|
-
}
|
|
882
|
-
if (isKeyword2(current, schemaKeywords3.const)) {
|
|
883
|
-
if (current.args.format === "number" && current.args.value !== void 0) {
|
|
884
|
-
return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
|
|
885
|
-
}
|
|
886
|
-
return zodKeywordMapper.const(transformers5.stringify(current.args.value));
|
|
887
|
-
}
|
|
888
|
-
if (isKeyword2(current, schemaKeywords3.matches)) {
|
|
889
|
-
if (current.args) {
|
|
890
|
-
return zodKeywordMapper.matches(transformers5.toRegExpString(current.args));
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
if (isKeyword2(current, schemaKeywords3.default)) {
|
|
894
|
-
if (current.args) {
|
|
895
|
-
return zodKeywordMapper.default(current.args);
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
if (isKeyword2(current, schemaKeywords3.describe)) {
|
|
899
|
-
if (current.args) {
|
|
900
|
-
return zodKeywordMapper.describe(transformers5.stringify(current.args.toString()));
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
if (isKeyword2(current, schemaKeywords3.string)) {
|
|
904
|
-
return zodKeywordMapper.string(options.coercion);
|
|
905
|
-
}
|
|
906
|
-
if (isKeyword2(current, schemaKeywords3.number) || isKeyword2(current, schemaKeywords3.integer)) {
|
|
907
|
-
return zodKeywordMapper.number(options.coercion);
|
|
908
|
-
}
|
|
909
|
-
if (isKeyword2(current, schemaKeywords3.min)) {
|
|
910
|
-
return zodKeywordMapper.min(current.args);
|
|
911
|
-
}
|
|
912
|
-
if (isKeyword2(current, schemaKeywords3.max)) {
|
|
913
|
-
return zodKeywordMapper.max(current.args);
|
|
914
|
-
}
|
|
915
|
-
if (isKeyword2(current, schemaKeywords3.datetime)) {
|
|
916
|
-
return zodKeywordMapper.datetime(current.args.offset, current.args.local);
|
|
917
|
-
}
|
|
918
|
-
if (isKeyword2(current, schemaKeywords3.date)) {
|
|
919
|
-
return zodKeywordMapper.date(current.args.type, options.coercion);
|
|
920
|
-
}
|
|
921
|
-
if (isKeyword2(current, schemaKeywords3.time)) {
|
|
922
|
-
return zodKeywordMapper.time(current.args.type, options.coercion);
|
|
923
|
-
}
|
|
924
|
-
if (current.keyword in zodKeywordMapper && "args" in current) {
|
|
925
|
-
const value2 = zodKeywordMapper[current.keyword];
|
|
926
|
-
return value2(current.args);
|
|
927
|
-
}
|
|
928
|
-
if (current.keyword in zodKeywordMapper) {
|
|
929
|
-
return value();
|
|
930
|
-
}
|
|
931
|
-
return void 0;
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
// src/plugin.ts
|
|
935
|
-
import path2 from "path";
|
|
936
|
-
import { FileManager as FileManager2, PluginManager as PluginManager2, createPlugin as createPlugin2 } from "@kubb/core";
|
|
937
|
-
import { camelCase as camelCase2, pascalCase as pascalCase2 } from "@kubb/core/transformers";
|
|
938
|
-
import { renderTemplate as renderTemplate2 } from "@kubb/core/utils";
|
|
939
|
-
import { OperationGenerator as OperationGenerator2, pluginOasName as pluginOasName2, SchemaGenerator as SchemaGenerator4 } from "@kubb/plugin-oas";
|
|
940
|
-
import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
|
|
941
|
-
|
|
942
|
-
// src/SchemaGenerator.tsx
|
|
943
|
-
import { createReactParser } from "@kubb/plugin-oas";
|
|
944
|
-
|
|
945
|
-
// src/components/OperationSchema.tsx
|
|
946
|
-
import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
|
|
947
|
-
import { Oas as Oas5 } from "@kubb/plugin-oas/components";
|
|
948
|
-
import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager3 } from "@kubb/plugin-oas/hooks";
|
|
949
|
-
import { File as File5, Parser as Parser4, useApp as useApp5 } from "@kubb/react";
|
|
950
|
-
import { jsx as jsx7, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
|
|
951
|
-
function OperationSchema2({ description, keysToOmit }) {
|
|
952
|
-
return /* @__PURE__ */ jsx7(Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
953
|
-
}
|
|
954
|
-
OperationSchema2.File = function({}) {
|
|
955
|
-
const { pluginManager, plugin, mode } = useApp5();
|
|
956
|
-
const { getSchemas, getFile } = useOperationManager3();
|
|
957
|
-
const oas = useOas3();
|
|
958
|
-
const operation = useOperation2();
|
|
959
|
-
const file = getFile(operation);
|
|
960
|
-
const schemas = getSchemas(operation);
|
|
961
|
-
const generator = new SchemaGenerator3(plugin.options, {
|
|
962
|
-
oas,
|
|
963
|
-
plugin,
|
|
964
|
-
pluginManager,
|
|
965
|
-
mode,
|
|
966
|
-
override: plugin.options.override
|
|
967
|
-
});
|
|
968
|
-
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
969
|
-
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
970
|
-
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
971
|
-
const optional = !required && !!name.includes("Params");
|
|
972
|
-
const tree = generator.parse({ schema, name });
|
|
973
|
-
return /* @__PURE__ */ jsxs4(Oas5.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
|
|
974
|
-
mode === "split" && /* @__PURE__ */ jsx7(Oas5.Schema.Imports, { extName: plugin.options.extName }),
|
|
975
|
-
/* @__PURE__ */ jsx7(File5.Source, { children: /* @__PURE__ */ jsx7(OperationSchema2, { description, keysToOmit }) })
|
|
976
|
-
] }, i);
|
|
977
|
-
};
|
|
978
|
-
return /* @__PURE__ */ jsx7(Parser4, { language: "typescript", children: /* @__PURE__ */ jsxs4(File5, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
979
|
-
/* @__PURE__ */ jsx7(File5.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
980
|
-
items.map(mapItem)
|
|
981
|
-
] }) });
|
|
982
|
-
};
|
|
983
|
-
|
|
984
|
-
// src/SchemaGenerator.tsx
|
|
985
|
-
import { jsx as jsx8 } from "@kubb/react/jsx-runtime";
|
|
986
|
-
var zodParser = createReactParser({
|
|
987
|
-
name: "plugin-zod",
|
|
988
|
-
Operations({ options }) {
|
|
989
|
-
if (!options.templates.operations) {
|
|
990
|
-
return null;
|
|
991
|
-
}
|
|
992
|
-
return /* @__PURE__ */ jsx8(Operations.File, { templates: options.templates.operations });
|
|
993
|
-
},
|
|
994
|
-
Operation() {
|
|
995
|
-
return /* @__PURE__ */ jsx8(OperationSchema2.File, {});
|
|
996
|
-
},
|
|
997
|
-
Schema({ schema, name }) {
|
|
998
|
-
return /* @__PURE__ */ jsx8(Schema2.File, {});
|
|
999
|
-
}
|
|
1000
|
-
});
|
|
1001
|
-
|
|
1002
|
-
// src/plugin.ts
|
|
1003
|
-
var pluginZodName = "plugin-zod";
|
|
1004
|
-
var pluginZod = createPlugin2((options) => {
|
|
1005
|
-
const {
|
|
1006
|
-
output = { path: "zod" },
|
|
1007
|
-
group,
|
|
1008
|
-
exclude = [],
|
|
1009
|
-
include,
|
|
1010
|
-
override = [],
|
|
1011
|
-
transformers: transformers7 = {},
|
|
1012
|
-
dateType = "string",
|
|
1013
|
-
unknownType = "any",
|
|
1014
|
-
typed = false,
|
|
1015
|
-
typedSchema = false,
|
|
1016
|
-
mapper = {},
|
|
1017
|
-
templates,
|
|
1018
|
-
importPath = "zod",
|
|
1019
|
-
coercion = false
|
|
1020
|
-
} = options;
|
|
1021
|
-
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
1022
|
-
return {
|
|
1023
|
-
name: pluginZodName,
|
|
1024
|
-
options: {
|
|
1025
|
-
extName: output.extName,
|
|
1026
|
-
transformers: transformers7,
|
|
1027
|
-
include,
|
|
1028
|
-
exclude,
|
|
1029
|
-
override,
|
|
1030
|
-
typed,
|
|
1031
|
-
typedSchema,
|
|
1032
|
-
dateType,
|
|
1033
|
-
unknownType,
|
|
1034
|
-
mapper,
|
|
1035
|
-
importPath,
|
|
1036
|
-
coercion,
|
|
1037
|
-
templates: {
|
|
1038
|
-
operations: Operations.templates,
|
|
1039
|
-
...templates
|
|
1040
|
-
}
|
|
1041
|
-
},
|
|
1042
|
-
pre: [pluginOasName2, typed ? pluginTsName : void 0].filter(Boolean),
|
|
1043
|
-
resolvePath(baseName, pathMode, options2) {
|
|
1044
|
-
const root = path2.resolve(this.config.root, this.config.output.path);
|
|
1045
|
-
const mode = pathMode ?? FileManager2.getMode(path2.resolve(root, output.path));
|
|
1046
|
-
if (mode === "single") {
|
|
1047
|
-
return path2.resolve(root, output.path);
|
|
1048
|
-
}
|
|
1049
|
-
if (options2?.tag && group?.type === "tag") {
|
|
1050
|
-
const tag = camelCase2(options2.tag);
|
|
1051
|
-
return path2.resolve(root, renderTemplate2(template, { tag }), baseName);
|
|
1052
|
-
}
|
|
1053
|
-
return path2.resolve(root, output.path, baseName);
|
|
1054
|
-
},
|
|
1055
|
-
resolveName(name, type) {
|
|
1056
|
-
let resolvedName = camelCase2(name, {
|
|
1057
|
-
suffix: type ? "schema" : void 0,
|
|
1058
|
-
isFile: type === "file"
|
|
1059
|
-
});
|
|
1060
|
-
if (type === "type") {
|
|
1061
|
-
resolvedName = pascalCase2(resolvedName);
|
|
1062
|
-
}
|
|
1063
|
-
if (type) {
|
|
1064
|
-
return transformers7?.name?.(resolvedName, type) || resolvedName;
|
|
1065
|
-
}
|
|
1066
|
-
return resolvedName;
|
|
1067
|
-
},
|
|
1068
|
-
async buildStart() {
|
|
1069
|
-
const [swaggerPlugin] = PluginManager2.getDependedPlugins(this.plugins, [pluginOasName2]);
|
|
1070
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
1071
|
-
const root = path2.resolve(this.config.root, this.config.output.path);
|
|
1072
|
-
const mode = FileManager2.getMode(path2.resolve(root, output.path));
|
|
1073
|
-
const schemaGenerator = new SchemaGenerator4(this.plugin.options, {
|
|
1074
|
-
oas,
|
|
1075
|
-
pluginManager: this.pluginManager,
|
|
1076
|
-
plugin: this.plugin,
|
|
1077
|
-
contentType: swaggerPlugin.context.contentType,
|
|
1078
|
-
include: void 0,
|
|
1079
|
-
override,
|
|
1080
|
-
mode,
|
|
1081
|
-
output: output.path
|
|
1082
|
-
});
|
|
1083
|
-
const schemaFiles = await schemaGenerator.build(zodParser);
|
|
1084
|
-
await this.addFile(...schemaFiles);
|
|
1085
|
-
const operationGenerator = new OperationGenerator2(this.plugin.options, {
|
|
1086
|
-
oas,
|
|
1087
|
-
pluginManager: this.pluginManager,
|
|
1088
|
-
plugin: this.plugin,
|
|
1089
|
-
contentType: swaggerPlugin.context.contentType,
|
|
1090
|
-
exclude,
|
|
1091
|
-
include,
|
|
1092
|
-
override,
|
|
1093
|
-
mode
|
|
1094
|
-
});
|
|
1095
|
-
const operationFiles = await operationGenerator.build(zodParser);
|
|
1096
|
-
await this.addFile(...operationFiles);
|
|
1097
|
-
},
|
|
1098
|
-
async buildEnd() {
|
|
1099
|
-
if (this.config.output.write === false) {
|
|
1100
|
-
return;
|
|
1101
|
-
}
|
|
1102
|
-
const root = path2.resolve(this.config.root, this.config.output.path);
|
|
1103
|
-
if (group?.type === "tag") {
|
|
1104
|
-
const rootFiles = await getGroupedByTagFiles({
|
|
1105
|
-
logger: this.logger,
|
|
1106
|
-
files: this.fileManager.files,
|
|
1107
|
-
plugin: this.plugin,
|
|
1108
|
-
template,
|
|
1109
|
-
exportAs: group.exportAs || "{{tag}}Schemas",
|
|
1110
|
-
root,
|
|
1111
|
-
output
|
|
1112
|
-
});
|
|
1113
|
-
await this.addFile(...rootFiles);
|
|
1114
|
-
}
|
|
1115
|
-
await this.fileManager.addIndexes({
|
|
1116
|
-
root,
|
|
1117
|
-
output,
|
|
1118
|
-
meta: { pluginKey: this.plugin.key },
|
|
1119
|
-
logger: this.logger
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
};
|
|
1123
|
-
});
|
|
1124
|
-
|
|
1125
|
-
// src/components/Schema.tsx
|
|
1126
|
-
import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
|
|
1127
|
-
function Schema2(props) {
|
|
1128
|
-
const { keysToOmit, withTypeAnnotation, description } = props;
|
|
1129
|
-
const { tree, name } = useSchema2();
|
|
1130
|
-
const {
|
|
1131
|
-
pluginManager,
|
|
1132
|
-
plugin: {
|
|
1133
|
-
options: { mapper, typedSchema, coercion }
|
|
1134
|
-
}
|
|
1135
|
-
} = useApp6();
|
|
1136
|
-
const resolvedName = pluginManager.resolveName({
|
|
1137
|
-
name,
|
|
1138
|
-
pluginKey: [pluginZodName],
|
|
1139
|
-
type: "function"
|
|
1140
|
-
});
|
|
1141
|
-
const resolvedTypeName = pluginManager.resolveName({
|
|
1142
|
-
name,
|
|
1143
|
-
pluginKey: [pluginZodName],
|
|
1144
|
-
type: "type"
|
|
1145
|
-
});
|
|
1146
|
-
const typeName = pluginManager.resolveName({
|
|
1147
|
-
name,
|
|
1148
|
-
pluginKey: [pluginTsName],
|
|
1149
|
-
type: "type"
|
|
1150
|
-
});
|
|
1151
|
-
if (!tree.length) {
|
|
1152
|
-
return /* @__PURE__ */ jsx9(
|
|
1153
|
-
Const2,
|
|
1154
|
-
{
|
|
1155
|
-
name: resolvedName,
|
|
1156
|
-
export: true,
|
|
1157
|
-
JSDoc: {
|
|
1158
|
-
comments: [description ? `@description ${transformers6.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
1159
|
-
},
|
|
1160
|
-
children: "undefined"
|
|
1161
|
-
}
|
|
1162
|
-
);
|
|
1163
|
-
}
|
|
1164
|
-
const hasTuple = tree.some((item) => isKeyword3(item, schemaKeywords5.tuple));
|
|
1165
|
-
const output = sort(tree).filter((item) => {
|
|
1166
|
-
if (hasTuple && (isKeyword3(item, schemaKeywords5.min) || isKeyword3(item, schemaKeywords5.max))) {
|
|
1167
|
-
return false;
|
|
1168
|
-
}
|
|
1169
|
-
return true;
|
|
1170
|
-
}).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
|
|
1171
|
-
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
1172
|
-
return /* @__PURE__ */ jsxs5(Fragment3, { children: [
|
|
1173
|
-
/* @__PURE__ */ jsx9(
|
|
1174
|
-
Const2,
|
|
1175
|
-
{
|
|
1176
|
-
export: true,
|
|
1177
|
-
name: resolvedName,
|
|
1178
|
-
JSDoc: {
|
|
1179
|
-
comments: [description ? `@description ${transformers6.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
1180
|
-
},
|
|
1181
|
-
children: [
|
|
1182
|
-
output,
|
|
1183
|
-
keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(",")} }))` : void 0,
|
|
1184
|
-
withTypeAnnotation && typeName ? ` as z.ZodType<${typeName}>` : ""
|
|
1185
|
-
].filter(Boolean).join("") || ""
|
|
1186
|
-
}
|
|
1187
|
-
),
|
|
1188
|
-
typedSchema && /* @__PURE__ */ jsx9(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` })
|
|
1189
|
-
] });
|
|
1190
|
-
}
|
|
1191
|
-
Schema2.File = function({}) {
|
|
1192
|
-
const {
|
|
1193
|
-
pluginManager,
|
|
1194
|
-
plugin: {
|
|
1195
|
-
options: { typed }
|
|
1196
|
-
}
|
|
1197
|
-
} = useApp6();
|
|
1198
|
-
const { schema } = useSchema2();
|
|
1199
|
-
const withTypeAnnotation = !!typed;
|
|
1200
|
-
return /* @__PURE__ */ jsxs5(Oas6.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
1201
|
-
/* @__PURE__ */ jsx9(Schema2.Imports, {}),
|
|
1202
|
-
/* @__PURE__ */ jsx9(File6.Source, { children: /* @__PURE__ */ jsx9(Schema2, { withTypeAnnotation, description: schema?.description }) })
|
|
1203
|
-
] });
|
|
1204
|
-
};
|
|
1205
|
-
Schema2.Imports = () => {
|
|
1206
|
-
const {
|
|
1207
|
-
pluginManager,
|
|
1208
|
-
plugin: {
|
|
1209
|
-
options: { typed, importPath }
|
|
1210
|
-
}
|
|
1211
|
-
} = useApp6();
|
|
1212
|
-
const { path: root } = useFile();
|
|
1213
|
-
const { name, tree, schema } = useSchema2();
|
|
1214
|
-
const typeName = pluginManager.resolveName({
|
|
1215
|
-
name,
|
|
1216
|
-
pluginKey: [pluginTsName],
|
|
1217
|
-
type: "type"
|
|
1218
|
-
});
|
|
1219
|
-
const typeFileName = pluginManager.resolveName({
|
|
1220
|
-
name,
|
|
1221
|
-
pluginKey: [pluginTsName],
|
|
1222
|
-
type: "file"
|
|
1223
|
-
});
|
|
1224
|
-
const typePath = pluginManager.resolvePath({
|
|
1225
|
-
baseName: typeFileName,
|
|
1226
|
-
pluginKey: [pluginTsName]
|
|
1227
|
-
});
|
|
1228
|
-
const withTypeAnnotation = !!typed;
|
|
1229
|
-
return /* @__PURE__ */ jsxs5(Fragment3, { children: [
|
|
1230
|
-
/* @__PURE__ */ jsx9(File6.Import, { name: ["z"], path: importPath }),
|
|
1231
|
-
withTypeAnnotation && typeName && typePath && /* @__PURE__ */ jsx9(File6.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
1232
|
-
] });
|
|
1233
|
-
};
|
|
1234
|
-
|
|
1235
|
-
export {
|
|
1236
|
-
Operations,
|
|
1237
|
-
Schema2 as Schema,
|
|
1238
|
-
OperationSchema2 as OperationSchema,
|
|
1239
|
-
pluginZodName,
|
|
1240
|
-
pluginZod
|
|
1241
|
-
};
|
|
1242
|
-
//# sourceMappingURL=chunk-XCGVHLYD.js.map
|