@kubb/plugin-zod 3.0.0-alpha.5 → 3.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Operations-BlQtRP31.d.cts → Operations-BG26e_MW.d.cts} +1 -1
- package/dist/{Operations-BlQtRP31.d.ts → Operations-BG26e_MW.d.ts} +1 -1
- package/dist/chunk-INEB36EJ.cjs +3479 -0
- package/dist/chunk-INEB36EJ.cjs.map +1 -0
- package/dist/chunk-PMYJN6KG.js +3479 -0
- package/dist/chunk-PMYJN6KG.js.map +1 -0
- package/dist/components.cjs +6 -2
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +2 -2
- package/dist/components.d.ts +2 -2
- package/dist/components.js +6 -2
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +6 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/src/components/OperationSchema.tsx +7 -11
- package/src/components/Operations.tsx +17 -15
- package/src/components/Schema.tsx +34 -30
- package/src/components/__snapshots__/operations.ts +47 -44
- package/src/plugin.ts +7 -27
- package/dist/chunk-MGSFBU7O.js +0 -1250
- package/dist/chunk-MGSFBU7O.js.map +0 -1
- package/dist/chunk-RISCJCJN.cjs +0 -1250
- package/dist/chunk-RISCJCJN.cjs.map +0 -1
package/dist/chunk-RISCJCJN.cjs
DELETED
|
@@ -1,1250 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/components/Operations.tsx
|
|
2
|
-
var _hooks = require('@kubb/plugin-oas/hooks');
|
|
3
|
-
var _react = require('@kubb/react');
|
|
4
|
-
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
|
5
|
-
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
6
|
-
function Template({ operationsName, pathsName, operations }) {
|
|
7
|
-
const { groupSchemasByName } = _hooks.useOperationManager.call(void 0, );
|
|
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__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
27
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Const, { export: true, name: operationsName, asConst: true, children: `{${_transformers2.default.stringifyObject(operationsJSON)}}` }),
|
|
28
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Const, { export: true, name: pathsName, asConst: true, children: `{${_transformers2.default.stringifyObject(pathsJSON)}}` })
|
|
29
|
-
] });
|
|
30
|
-
}
|
|
31
|
-
function RootTemplate({ children }) {
|
|
32
|
-
const {
|
|
33
|
-
mode,
|
|
34
|
-
pluginManager,
|
|
35
|
-
plugin: {
|
|
36
|
-
key: pluginKey,
|
|
37
|
-
options: { extName }
|
|
38
|
-
}
|
|
39
|
-
} = _react.useApp.call(void 0, );
|
|
40
|
-
const { getFile } = _hooks.useOperationManager.call(void 0, );
|
|
41
|
-
const operations = _hooks.useOperations.call(void 0, );
|
|
42
|
-
const { groupSchemasByName } = _hooks.useOperationManager.call(void 0, );
|
|
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__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { extName, name: names, root: file.path, path: getFile(operation).path }, index);
|
|
48
|
-
}).filter(Boolean);
|
|
49
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, exportable: false, children: [
|
|
50
|
-
mode === "split" && imports,
|
|
51
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children })
|
|
52
|
-
] }) });
|
|
53
|
-
}
|
|
54
|
-
var defaultTemplates = { default: Template, root: RootTemplate };
|
|
55
|
-
function Operations({ Template: Template3 = defaultTemplates.default }) {
|
|
56
|
-
const operations = _hooks.useOperations.call(void 0, );
|
|
57
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 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__ */ _jsxruntime.jsx.call(void 0, RootTemplate2, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Operations, { Template: Template3 }) });
|
|
64
|
-
};
|
|
65
|
-
Operations.templates = defaultTemplates;
|
|
66
|
-
|
|
67
|
-
// src/components/Schema.tsx
|
|
68
|
-
var _components = require('@kubb/plugin-oas/components');
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
// ../plugin-ts/src/plugin.ts
|
|
72
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
73
|
-
var _core = require('@kubb/core');
|
|
74
|
-
|
|
75
|
-
var _utils = require('@kubb/core/utils');
|
|
76
|
-
var _pluginoas = require('@kubb/plugin-oas');
|
|
77
|
-
|
|
78
|
-
// ../plugin-ts/src/OperationGenerator.tsx
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// ../plugin-ts/src/components/OasType.tsx
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
function Template2({ name, typeName, api }) {
|
|
88
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
89
|
-
`export const ${name} = ${JSON.stringify(api, void 0, 2)} as const`,
|
|
90
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "br", {}),
|
|
91
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.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 = _hooks.useOas.call(void 0, );
|
|
97
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Template3, { name, typeName, api: oas.api });
|
|
98
|
-
}
|
|
99
|
-
OasType.File = function({ name, typeName, templates = defaultTemplates2 }) {
|
|
100
|
-
const {
|
|
101
|
-
pluginManager,
|
|
102
|
-
plugin: { key: pluginKey }
|
|
103
|
-
} = _react.useApp.call(void 0, );
|
|
104
|
-
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
|
|
105
|
-
const Template3 = templates.default;
|
|
106
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
107
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
|
|
108
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OasType, { Template: Template3, name, typeName }) })
|
|
109
|
-
] }) });
|
|
110
|
-
};
|
|
111
|
-
OasType.templates = defaultTemplates2;
|
|
112
|
-
|
|
113
|
-
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
114
|
-
|
|
115
|
-
var _parserts = require('@kubb/parser-ts');
|
|
116
|
-
var _factory = require('@kubb/parser-ts/factory'); var factory3 = _interopRequireWildcard(_factory); var factory2 = _interopRequireWildcard(_factory); var factory = _interopRequireWildcard(_factory);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// ../plugin-ts/src/components/Schema.tsx
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// ../plugin-ts/src/parser/index.ts
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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 (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.union)) {
|
|
238
|
-
return typeKeywordMapper.union(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
239
|
-
}
|
|
240
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.and)) {
|
|
241
|
-
return typeKeywordMapper.and(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
242
|
-
}
|
|
243
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.array)) {
|
|
244
|
-
return typeKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
245
|
-
}
|
|
246
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.enum)) {
|
|
247
|
-
return typeKeywordMapper.enum(current.args.typeName);
|
|
248
|
-
}
|
|
249
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.ref)) {
|
|
250
|
-
return typeKeywordMapper.ref(current.args.name);
|
|
251
|
-
}
|
|
252
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.blob)) {
|
|
253
|
-
return value();
|
|
254
|
-
}
|
|
255
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.tuple)) {
|
|
256
|
-
return typeKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
257
|
-
}
|
|
258
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.const)) {
|
|
259
|
-
return typeKeywordMapper.const(current.args.name, current.args.format);
|
|
260
|
-
}
|
|
261
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.object)) {
|
|
262
|
-
const properties = Object.entries(_optionalChain([current, 'access', _ => _.args, 'optionalAccess', _2 => _2.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 === _pluginoas.schemaKeywords.name);
|
|
267
|
-
const mappedName = _optionalChain([nameSchema, 'optionalAccess', _3 => _3.args]) || name;
|
|
268
|
-
if (_optionalChain([options, 'access', _4 => _4.mapper, 'optionalAccess', _5 => _5[mappedName]])) {
|
|
269
|
-
return _optionalChain([options, 'access', _6 => _6.mapper, 'optionalAccess', _7 => _7[mappedName]]);
|
|
270
|
-
}
|
|
271
|
-
const isNullish = schemas.some((schema) => schema.keyword === _pluginoas.schemaKeywords.nullish);
|
|
272
|
-
const isNullable = schemas.some((schema) => schema.keyword === _pluginoas.schemaKeywords.nullable);
|
|
273
|
-
const isOptional = schemas.some((schema) => schema.keyword === _pluginoas.schemaKeywords.optional);
|
|
274
|
-
const isReadonly = schemas.some((schema) => schema.keyword === _pluginoas.schemaKeywords.readOnly);
|
|
275
|
-
const describeSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.describe);
|
|
276
|
-
const deprecatedSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.deprecated);
|
|
277
|
-
const defaultSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.default);
|
|
278
|
-
const exampleSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.example);
|
|
279
|
-
const schemaSchema = schemas.find((schema) => schema.keyword === _pluginoas.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.default.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
|
-
_optionalChain([schemaSchema, 'optionalAccess', _8 => _8.args, 'optionalAccess', _9 => _9.type]) || _optionalChain([schemaSchema, 'optionalAccess', _10 => _10.args, 'optionalAccess', _11 => _11.format]) ? [`@type ${_optionalChain([schemaSchema, 'optionalAccess', _12 => _12.args, 'optionalAccess', _13 => _13.type]) || "unknown"}${!isOptional ? "" : " | undefined"}`, _optionalChain([schemaSchema, 'optionalAccess', _14 => _14.args, 'optionalAccess', _15 => _15.format])].filter(Boolean).join(", ") : void 0
|
|
310
|
-
].filter(Boolean)
|
|
311
|
-
});
|
|
312
|
-
});
|
|
313
|
-
const additionalProperties = _optionalChain([current, 'access', _16 => _16.args, 'optionalAccess', _17 => _17.additionalProperties, 'optionalAccess', _18 => _18.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 (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.datetime)) {
|
|
319
|
-
return typeKeywordMapper.datetime();
|
|
320
|
-
}
|
|
321
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.date)) {
|
|
322
|
-
return typeKeywordMapper.date(current.args.type);
|
|
323
|
-
}
|
|
324
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.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
|
-
|
|
335
|
-
function Schema(props) {
|
|
336
|
-
const { keysToOmit, description } = props;
|
|
337
|
-
const { tree, name } = _hooks.useSchema.call(void 0, );
|
|
338
|
-
const {
|
|
339
|
-
pluginManager,
|
|
340
|
-
plugin: {
|
|
341
|
-
options: { mapper, enumType, optionalType }
|
|
342
|
-
}
|
|
343
|
-
} = _react.useApp.call(void 0, );
|
|
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 === _pluginoas.schemaKeywords.nullish);
|
|
360
|
-
const isNullable = tree.some((item) => item.keyword === _pluginoas.schemaKeywords.nullable);
|
|
361
|
-
const isOptional = tree.some((item) => item.keyword === _pluginoas.schemaKeywords.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: _optionalChain([keysToOmit, 'optionalAccess', _19 => _19.length]) ? factory2.createOmitDeclaration({
|
|
382
|
-
keys: keysToOmit,
|
|
383
|
-
type,
|
|
384
|
-
nonNullable: true
|
|
385
|
-
}) : type
|
|
386
|
-
});
|
|
387
|
-
const enumSchemas = _pluginoas.SchemaGenerator.deepSearch(tree, _pluginoas.schemaKeywords.enum);
|
|
388
|
-
if (enumSchemas) {
|
|
389
|
-
enumSchemas.forEach((enumSchema) => {
|
|
390
|
-
extraNodes.push(
|
|
391
|
-
...factory2.createEnumDeclaration({
|
|
392
|
-
name: _transformers2.default.camelCase(enumSchema.args.name),
|
|
393
|
-
typeName: enumSchema.args.typeName,
|
|
394
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [_transformers2.default.trimQuotes(_optionalChain([item, 'access', _20 => _20.name, 'optionalAccess', _21 => _21.toString, 'call', _22 => _22()])), item.value]).filter(Boolean),
|
|
395
|
-
type: enumType
|
|
396
|
-
})
|
|
397
|
-
);
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
nodes.push(
|
|
401
|
-
factory2.appendJSDocToNode({
|
|
402
|
-
node,
|
|
403
|
-
comments: [description ? `@description ${_transformers2.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
404
|
-
})
|
|
405
|
-
);
|
|
406
|
-
const filterdNodes = nodes.filter(
|
|
407
|
-
(node2) => !extraNodes.some(
|
|
408
|
-
(extraNode) => _optionalChain([extraNode, 'optionalAccess', _23 => _23.name, 'optionalAccess', _24 => _24.escapedText]) === _optionalChain([node2, 'optionalAccess', _25 => _25.name, 'optionalAccess', _26 => _26.escapedText])
|
|
409
|
-
)
|
|
410
|
-
);
|
|
411
|
-
return _parserts.print.call(void 0, [...extraNodes, ...filterdNodes]);
|
|
412
|
-
}
|
|
413
|
-
Schema.File = function({}) {
|
|
414
|
-
const { pluginManager } = _react.useApp.call(void 0, );
|
|
415
|
-
const { schema } = _hooks.useSchema.call(void 0, );
|
|
416
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.File, { output: pluginManager.config.output.path, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { description: _optionalChain([schema, 'optionalAccess', _27 => _27.description]) }) }) });
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
420
|
-
|
|
421
|
-
var SchemaGenerator2 = class extends _pluginoas.SchemaGenerator {
|
|
422
|
-
async schema(name, schema, options) {
|
|
423
|
-
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
424
|
-
const root = _react.createRoot.call(void 0, {
|
|
425
|
-
logger: pluginManager.logger
|
|
426
|
-
});
|
|
427
|
-
const tree = this.parse({ schema, name });
|
|
428
|
-
root.render(
|
|
429
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema.File, {}) }) }) })
|
|
430
|
-
);
|
|
431
|
-
return root.files;
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
|
|
435
|
-
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
436
|
-
|
|
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: _transformers2.default.pascalCase(key),
|
|
506
|
-
type
|
|
507
|
-
});
|
|
508
|
-
}).filter(Boolean)
|
|
509
|
-
),
|
|
510
|
-
modifiers: [factory3.modifiers.export]
|
|
511
|
-
});
|
|
512
|
-
return _parserts.print.call(void 0, namespaceNode);
|
|
513
|
-
}
|
|
514
|
-
function OperationSchema({ keysToOmit, description }) {
|
|
515
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema, { keysToOmit, description });
|
|
516
|
-
}
|
|
517
|
-
OperationSchema.File = function({}) {
|
|
518
|
-
const { pluginManager, plugin, mode, fileManager } = _react.useApp.call(void 0, );
|
|
519
|
-
const oas = _hooks.useOas.call(void 0, );
|
|
520
|
-
const { getSchemas, getFile, getName } = _hooks.useOperationManager.call(void 0, );
|
|
521
|
-
const operation = _hooks.useOperation.call(void 0, );
|
|
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__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree, children: [
|
|
536
|
-
mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, { extName: plugin.options.extName, isTypeOnly: true }),
|
|
537
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema, { description, keysToOmit }) })
|
|
538
|
-
] }, i);
|
|
539
|
-
};
|
|
540
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
541
|
-
items.map(mapItem),
|
|
542
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: printCombinedSchema({ name: factoryName, operation, schemas, pluginManager }) })
|
|
543
|
-
] }) });
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
// ../plugin-ts/src/OperationGenerator.tsx
|
|
547
|
-
|
|
548
|
-
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
549
|
-
async all(operations) {
|
|
550
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
551
|
-
const root = _react.createRoot.call(void 0, {
|
|
552
|
-
logger: pluginManager.logger
|
|
553
|
-
});
|
|
554
|
-
root.render(
|
|
555
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 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 = _react.createRoot.call(void 0, {
|
|
562
|
-
logger: pluginManager.logger
|
|
563
|
-
});
|
|
564
|
-
root.render(
|
|
565
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema.File, {}) }) }) })
|
|
566
|
-
);
|
|
567
|
-
return root.files;
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
// ../plugin-ts/src/plugin.ts
|
|
572
|
-
var pluginTsName = "plugin-ts";
|
|
573
|
-
var pluginTs = _core.createPlugin.call(void 0, (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 = _optionalChain([group, 'optionalAccess', _28 => _28.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: [_pluginoas.pluginOasName],
|
|
607
|
-
resolvePath(baseName, pathMode, options2) {
|
|
608
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
609
|
-
const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
|
|
610
|
-
if (mode === "single") {
|
|
611
|
-
return _path2.default.resolve(root, output.path);
|
|
612
|
-
}
|
|
613
|
-
if (_optionalChain([options2, 'optionalAccess', _29 => _29.tag]) && _optionalChain([group, 'optionalAccess', _30 => _30.type]) === "tag") {
|
|
614
|
-
const tag = _transformers.camelCase.call(void 0, options2.tag);
|
|
615
|
-
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
|
616
|
-
}
|
|
617
|
-
return _path2.default.resolve(root, output.path, baseName);
|
|
618
|
-
},
|
|
619
|
-
resolveName(name, type) {
|
|
620
|
-
const resolvedName = _transformers.pascalCase.call(void 0, name, { isFile: type === "file" });
|
|
621
|
-
if (type) {
|
|
622
|
-
return _optionalChain([transformers7, 'optionalAccess', _31 => _31.name, 'optionalCall', _32 => _32(resolvedName, type)]) || resolvedName;
|
|
623
|
-
}
|
|
624
|
-
return resolvedName;
|
|
625
|
-
},
|
|
626
|
-
async buildStart() {
|
|
627
|
-
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
|
628
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
629
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
630
|
-
const mode = _core.FileManager.getMode(_path2.default.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 = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
661
|
-
const files = await this.fileManager.getIndexFiles({
|
|
662
|
-
root,
|
|
663
|
-
output,
|
|
664
|
-
plugin: this.plugin,
|
|
665
|
-
logger: this.logger
|
|
666
|
-
});
|
|
667
|
-
await this.fileManager.processFiles({
|
|
668
|
-
logger: this.logger,
|
|
669
|
-
files
|
|
670
|
-
});
|
|
671
|
-
}
|
|
672
|
-
};
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
// src/components/Schema.tsx
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
// src/parser/index.ts
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
var zodKeywordMapper = {
|
|
684
|
-
any: () => "z.any()",
|
|
685
|
-
unknown: () => "z.unknown()",
|
|
686
|
-
number: (coercion, min, max) => {
|
|
687
|
-
return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
688
|
-
},
|
|
689
|
-
integer: (coercion, min, max) => {
|
|
690
|
-
return [coercion ? "z.coerce.number()" : "z.number()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
691
|
-
},
|
|
692
|
-
object: (value) => `z.object({${value}})`,
|
|
693
|
-
string: (coercion, min, max) => {
|
|
694
|
-
return [coercion ? "z.coerce.string()" : "z.string()", min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
695
|
-
},
|
|
696
|
-
boolean: () => "z.boolean()",
|
|
697
|
-
undefined: () => "z.undefined()",
|
|
698
|
-
nullable: () => ".nullable()",
|
|
699
|
-
null: () => "z.null()",
|
|
700
|
-
nullish: () => ".nullish()",
|
|
701
|
-
array: (items = [], min, max) => {
|
|
702
|
-
return [`z.array(${_optionalChain([items, 'optionalAccess', _33 => _33.join, 'call', _34 => _34("")])})`, min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
703
|
-
},
|
|
704
|
-
tuple: (items = []) => `z.tuple([${_optionalChain([items, 'optionalAccess', _35 => _35.join, 'call', _36 => _36(", ")])}])`,
|
|
705
|
-
enum: (items = []) => `z.enum([${_optionalChain([items, 'optionalAccess', _37 => _37.join, 'call', _38 => _38(", ")])}])`,
|
|
706
|
-
union: (items = []) => `z.union([${_optionalChain([items, 'optionalAccess', _39 => _39.join, 'call', _40 => _40(", ")])}])`,
|
|
707
|
-
const: (value) => `z.literal(${_nullishCoalesce(value, () => ( ""))})`,
|
|
708
|
-
/**
|
|
709
|
-
* ISO 8601
|
|
710
|
-
*/
|
|
711
|
-
datetime: (offset = false, local = false) => {
|
|
712
|
-
if (offset) {
|
|
713
|
-
return `z.string().datetime({ offset: ${offset} })`;
|
|
714
|
-
}
|
|
715
|
-
if (local) {
|
|
716
|
-
return `z.string().datetime({ local: ${local} })`;
|
|
717
|
-
}
|
|
718
|
-
return "z.string().datetime()";
|
|
719
|
-
},
|
|
720
|
-
/**
|
|
721
|
-
* Type `'date'` Date
|
|
722
|
-
* Type `'string'` ISO date format (YYYY-MM-DD)
|
|
723
|
-
* @default ISO date format (YYYY-MM-DD)
|
|
724
|
-
*/
|
|
725
|
-
date: (type = "string", coercion) => {
|
|
726
|
-
if (type === "string") {
|
|
727
|
-
return "z.string().date()";
|
|
728
|
-
}
|
|
729
|
-
if (coercion) {
|
|
730
|
-
return "z.coerce.date()";
|
|
731
|
-
}
|
|
732
|
-
return "z.date()";
|
|
733
|
-
},
|
|
734
|
-
/**
|
|
735
|
-
* Type `'date'` Date
|
|
736
|
-
* Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
|
|
737
|
-
* @default ISO time format (HH:mm:ss[.SSSSSS])
|
|
738
|
-
*/
|
|
739
|
-
time: (type = "string", coercion) => {
|
|
740
|
-
if (type === "string") {
|
|
741
|
-
return "z.string().time()";
|
|
742
|
-
}
|
|
743
|
-
if (coercion) {
|
|
744
|
-
return "z.coerce.date()";
|
|
745
|
-
}
|
|
746
|
-
return "z.date()";
|
|
747
|
-
},
|
|
748
|
-
uuid: () => ".uuid()",
|
|
749
|
-
url: () => ".url()",
|
|
750
|
-
strict: () => ".strict()",
|
|
751
|
-
default: (value) => `.default(${_nullishCoalesce(value, () => ( ""))})`,
|
|
752
|
-
and: (items = []) => _optionalChain([items, 'optionalAccess', _41 => _41.map, 'call', _42 => _42((item) => `.and(${item})`), 'access', _43 => _43.join, 'call', _44 => _44("")]),
|
|
753
|
-
describe: (value = "") => `.describe(${value})`,
|
|
754
|
-
min: (value) => `.min(${_nullishCoalesce(value, () => ( ""))})`,
|
|
755
|
-
max: (value) => `.max(${_nullishCoalesce(value, () => ( ""))})`,
|
|
756
|
-
optional: () => ".optional()",
|
|
757
|
-
matches: (value = "") => `.regex(${value})`,
|
|
758
|
-
email: () => ".email()",
|
|
759
|
-
firstName: void 0,
|
|
760
|
-
lastName: void 0,
|
|
761
|
-
password: void 0,
|
|
762
|
-
phone: void 0,
|
|
763
|
-
readOnly: void 0,
|
|
764
|
-
ref: (value) => value ? `z.lazy(() => ${value})` : void 0,
|
|
765
|
-
blob: () => "z.string()",
|
|
766
|
-
deprecated: void 0,
|
|
767
|
-
example: void 0,
|
|
768
|
-
schema: void 0,
|
|
769
|
-
catchall: (value) => value ? `.catchall(${value})` : void 0,
|
|
770
|
-
name: void 0
|
|
771
|
-
};
|
|
772
|
-
function sort(items) {
|
|
773
|
-
const order = [
|
|
774
|
-
_pluginoas.schemaKeywords.string,
|
|
775
|
-
_pluginoas.schemaKeywords.datetime,
|
|
776
|
-
_pluginoas.schemaKeywords.date,
|
|
777
|
-
_pluginoas.schemaKeywords.time,
|
|
778
|
-
_pluginoas.schemaKeywords.tuple,
|
|
779
|
-
_pluginoas.schemaKeywords.number,
|
|
780
|
-
_pluginoas.schemaKeywords.object,
|
|
781
|
-
_pluginoas.schemaKeywords.enum,
|
|
782
|
-
_pluginoas.schemaKeywords.url,
|
|
783
|
-
_pluginoas.schemaKeywords.email,
|
|
784
|
-
_pluginoas.schemaKeywords.firstName,
|
|
785
|
-
_pluginoas.schemaKeywords.lastName,
|
|
786
|
-
_pluginoas.schemaKeywords.password,
|
|
787
|
-
_pluginoas.schemaKeywords.matches,
|
|
788
|
-
_pluginoas.schemaKeywords.uuid,
|
|
789
|
-
_pluginoas.schemaKeywords.min,
|
|
790
|
-
_pluginoas.schemaKeywords.max,
|
|
791
|
-
_pluginoas.schemaKeywords.default,
|
|
792
|
-
_pluginoas.schemaKeywords.describe,
|
|
793
|
-
_pluginoas.schemaKeywords.optional,
|
|
794
|
-
_pluginoas.schemaKeywords.nullable,
|
|
795
|
-
_pluginoas.schemaKeywords.nullish,
|
|
796
|
-
_pluginoas.schemaKeywords.null
|
|
797
|
-
];
|
|
798
|
-
if (!items) {
|
|
799
|
-
return [];
|
|
800
|
-
}
|
|
801
|
-
return _transformers2.default.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
|
|
802
|
-
}
|
|
803
|
-
function parse2(parent, current, options) {
|
|
804
|
-
const value = zodKeywordMapper[current.keyword];
|
|
805
|
-
if (!value) {
|
|
806
|
-
return void 0;
|
|
807
|
-
}
|
|
808
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.union)) {
|
|
809
|
-
if (Array.isArray(current.args) && current.args.length === 1) {
|
|
810
|
-
return parse2(parent, current.args[0], options);
|
|
811
|
-
}
|
|
812
|
-
if (Array.isArray(current.args) && !current.args.length) {
|
|
813
|
-
return "";
|
|
814
|
-
}
|
|
815
|
-
return zodKeywordMapper.union(
|
|
816
|
-
sort(current.args).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
817
|
-
);
|
|
818
|
-
}
|
|
819
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.and)) {
|
|
820
|
-
const items = sort(current.args).filter((schema) => {
|
|
821
|
-
return ![_pluginoas.schemaKeywords.optional, _pluginoas.schemaKeywords.describe].includes(schema.keyword);
|
|
822
|
-
}).map((schema) => parse2(current, schema, options)).filter(Boolean);
|
|
823
|
-
return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
|
|
824
|
-
}
|
|
825
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.array)) {
|
|
826
|
-
return zodKeywordMapper.array(
|
|
827
|
-
sort(current.args.items).map((schemas) => parse2(current, schemas, options)).filter(Boolean),
|
|
828
|
-
current.args.min,
|
|
829
|
-
current.args.max
|
|
830
|
-
);
|
|
831
|
-
}
|
|
832
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.enum)) {
|
|
833
|
-
if (current.args.asConst) {
|
|
834
|
-
return zodKeywordMapper.union(
|
|
835
|
-
current.args.items.map((schema) => {
|
|
836
|
-
return parse2(
|
|
837
|
-
current,
|
|
838
|
-
{
|
|
839
|
-
keyword: _pluginoas.schemaKeywords.const,
|
|
840
|
-
args: schema
|
|
841
|
-
},
|
|
842
|
-
options
|
|
843
|
-
);
|
|
844
|
-
}).filter(Boolean)
|
|
845
|
-
);
|
|
846
|
-
}
|
|
847
|
-
return zodKeywordMapper.enum(
|
|
848
|
-
current.args.items.map((schema) => {
|
|
849
|
-
if (schema.format === "number") {
|
|
850
|
-
return _transformers2.default.stringify(schema.value);
|
|
851
|
-
}
|
|
852
|
-
return _transformers2.default.stringify(schema.value);
|
|
853
|
-
})
|
|
854
|
-
);
|
|
855
|
-
}
|
|
856
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.ref)) {
|
|
857
|
-
return zodKeywordMapper.ref(_optionalChain([current, 'access', _45 => _45.args, 'optionalAccess', _46 => _46.name]));
|
|
858
|
-
}
|
|
859
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.object)) {
|
|
860
|
-
const properties = Object.entries(_optionalChain([current, 'access', _47 => _47.args, 'optionalAccess', _48 => _48.properties]) || {}).filter((item) => {
|
|
861
|
-
const schema = item[1];
|
|
862
|
-
return schema && typeof schema.map === "function";
|
|
863
|
-
}).map(([name, schemas]) => {
|
|
864
|
-
const nameSchema = schemas.find((schema) => schema.keyword === _pluginoas.schemaKeywords.name);
|
|
865
|
-
const mappedName = _optionalChain([nameSchema, 'optionalAccess', _49 => _49.args]) || name;
|
|
866
|
-
if (_optionalChain([options, 'access', _50 => _50.mapper, 'optionalAccess', _51 => _51[mappedName]])) {
|
|
867
|
-
return `"${name}": ${_optionalChain([options, 'access', _52 => _52.mapper, 'optionalAccess', _53 => _53[mappedName]])}`;
|
|
868
|
-
}
|
|
869
|
-
return `"${name}": ${sort(schemas).map((schema, array) => {
|
|
870
|
-
return parse2(current, schema, options);
|
|
871
|
-
}).filter(Boolean).join("")}`;
|
|
872
|
-
}).join(",");
|
|
873
|
-
const additionalProperties = _optionalChain([current, 'access', _54 => _54.args, 'optionalAccess', _55 => _55.additionalProperties, 'optionalAccess', _56 => _56.length]) ? current.args.additionalProperties.map((schema) => parse2(current, schema, options)).filter(Boolean).at(0) : void 0;
|
|
874
|
-
const text = [
|
|
875
|
-
zodKeywordMapper.object(properties),
|
|
876
|
-
_optionalChain([current, 'access', _57 => _57.args, 'optionalAccess', _58 => _58.strict]) ? zodKeywordMapper.strict() : void 0,
|
|
877
|
-
additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0
|
|
878
|
-
].filter(Boolean);
|
|
879
|
-
return text.join("");
|
|
880
|
-
}
|
|
881
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.tuple)) {
|
|
882
|
-
return zodKeywordMapper.tuple(
|
|
883
|
-
sort(current.args.items).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
884
|
-
);
|
|
885
|
-
}
|
|
886
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.const)) {
|
|
887
|
-
if (current.args.format === "number" && current.args.value !== void 0) {
|
|
888
|
-
return zodKeywordMapper.const(Number.parseInt(_optionalChain([current, 'access', _59 => _59.args, 'access', _60 => _60.value, 'optionalAccess', _61 => _61.toString, 'call', _62 => _62()])));
|
|
889
|
-
}
|
|
890
|
-
return zodKeywordMapper.const(_transformers2.default.stringify(current.args.value));
|
|
891
|
-
}
|
|
892
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.matches)) {
|
|
893
|
-
if (current.args) {
|
|
894
|
-
return zodKeywordMapper.matches(_transformers2.default.toRegExpString(current.args));
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.default)) {
|
|
898
|
-
if (current.args) {
|
|
899
|
-
return zodKeywordMapper.default(current.args);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.describe)) {
|
|
903
|
-
if (current.args) {
|
|
904
|
-
return zodKeywordMapper.describe(_transformers2.default.stringify(current.args.toString()));
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.string)) {
|
|
908
|
-
return zodKeywordMapper.string(options.coercion);
|
|
909
|
-
}
|
|
910
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.number) || _pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.integer)) {
|
|
911
|
-
return zodKeywordMapper.number(options.coercion);
|
|
912
|
-
}
|
|
913
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.min)) {
|
|
914
|
-
return zodKeywordMapper.min(current.args);
|
|
915
|
-
}
|
|
916
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.max)) {
|
|
917
|
-
return zodKeywordMapper.max(current.args);
|
|
918
|
-
}
|
|
919
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.datetime)) {
|
|
920
|
-
return zodKeywordMapper.datetime(current.args.offset, current.args.local);
|
|
921
|
-
}
|
|
922
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.date)) {
|
|
923
|
-
return zodKeywordMapper.date(current.args.type, options.coercion);
|
|
924
|
-
}
|
|
925
|
-
if (_pluginoas.isKeyword.call(void 0, current, _pluginoas.schemaKeywords.time)) {
|
|
926
|
-
return zodKeywordMapper.time(current.args.type, options.coercion);
|
|
927
|
-
}
|
|
928
|
-
if (current.keyword in zodKeywordMapper && "args" in current) {
|
|
929
|
-
const value2 = zodKeywordMapper[current.keyword];
|
|
930
|
-
return value2(current.args);
|
|
931
|
-
}
|
|
932
|
-
if (current.keyword in zodKeywordMapper) {
|
|
933
|
-
return value();
|
|
934
|
-
}
|
|
935
|
-
return void 0;
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
// src/plugin.ts
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
var _utils3 = require('@kubb/plugin-oas/utils');
|
|
945
|
-
|
|
946
|
-
// src/SchemaGenerator.tsx
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
// src/components/OperationSchema.tsx
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
function OperationSchema2({ description, keysToOmit }) {
|
|
956
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
957
|
-
}
|
|
958
|
-
OperationSchema2.File = function({}) {
|
|
959
|
-
const { pluginManager, plugin, mode } = _react.useApp.call(void 0, );
|
|
960
|
-
const { getSchemas, getFile } = _hooks.useOperationManager.call(void 0, );
|
|
961
|
-
const oas = _hooks.useOas.call(void 0, );
|
|
962
|
-
const operation = _hooks.useOperation.call(void 0, );
|
|
963
|
-
const file = getFile(operation);
|
|
964
|
-
const schemas = getSchemas(operation);
|
|
965
|
-
const generator = new (0, _pluginoas.SchemaGenerator)(plugin.options, {
|
|
966
|
-
oas,
|
|
967
|
-
plugin,
|
|
968
|
-
pluginManager,
|
|
969
|
-
mode,
|
|
970
|
-
override: plugin.options.override
|
|
971
|
-
});
|
|
972
|
-
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
973
|
-
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
974
|
-
const required = Array.isArray(_optionalChain([schema, 'optionalAccess', _63 => _63.required])) ? !!schema.required.length : !!_optionalChain([schema, 'optionalAccess', _64 => _64.required]);
|
|
975
|
-
const optional = !required && !!name.includes("Params");
|
|
976
|
-
const tree = generator.parse({ schema, name });
|
|
977
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: _pluginoas.schemaKeywords.optional } : void 0].filter(Boolean), children: [
|
|
978
|
-
mode === "split" && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Schema.Imports, { extName: plugin.options.extName }),
|
|
979
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema2, { description, keysToOmit }) })
|
|
980
|
-
] }, i);
|
|
981
|
-
};
|
|
982
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Parser, { language: "typescript", children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
983
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
984
|
-
items.map(mapItem)
|
|
985
|
-
] }) });
|
|
986
|
-
};
|
|
987
|
-
|
|
988
|
-
// src/SchemaGenerator.tsx
|
|
989
|
-
|
|
990
|
-
var zodParser = _pluginoas.createReactParser.call(void 0, {
|
|
991
|
-
name: "plugin-zod",
|
|
992
|
-
Operations({ options }) {
|
|
993
|
-
if (!options.templates.operations) {
|
|
994
|
-
return null;
|
|
995
|
-
}
|
|
996
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Operations.File, { templates: options.templates.operations });
|
|
997
|
-
},
|
|
998
|
-
Operation() {
|
|
999
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, OperationSchema2.File, {});
|
|
1000
|
-
},
|
|
1001
|
-
Schema({ schema, name }) {
|
|
1002
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema2.File, {});
|
|
1003
|
-
}
|
|
1004
|
-
});
|
|
1005
|
-
|
|
1006
|
-
// src/plugin.ts
|
|
1007
|
-
var pluginZodName = "plugin-zod";
|
|
1008
|
-
var pluginZod = _core.createPlugin.call(void 0, (options) => {
|
|
1009
|
-
const {
|
|
1010
|
-
output = { path: "zod" },
|
|
1011
|
-
group,
|
|
1012
|
-
exclude = [],
|
|
1013
|
-
include,
|
|
1014
|
-
override = [],
|
|
1015
|
-
transformers: transformers7 = {},
|
|
1016
|
-
dateType = "string",
|
|
1017
|
-
unknownType = "any",
|
|
1018
|
-
typed = false,
|
|
1019
|
-
typedSchema = false,
|
|
1020
|
-
mapper = {},
|
|
1021
|
-
templates,
|
|
1022
|
-
importPath = "zod",
|
|
1023
|
-
coercion = false
|
|
1024
|
-
} = options;
|
|
1025
|
-
const template = _optionalChain([group, 'optionalAccess', _65 => _65.output]) ? group.output : `${output.path}/{{tag}}Controller`;
|
|
1026
|
-
return {
|
|
1027
|
-
name: pluginZodName,
|
|
1028
|
-
options: {
|
|
1029
|
-
extName: output.extName,
|
|
1030
|
-
transformers: transformers7,
|
|
1031
|
-
include,
|
|
1032
|
-
exclude,
|
|
1033
|
-
override,
|
|
1034
|
-
typed,
|
|
1035
|
-
typedSchema,
|
|
1036
|
-
dateType,
|
|
1037
|
-
unknownType,
|
|
1038
|
-
mapper,
|
|
1039
|
-
importPath,
|
|
1040
|
-
coercion,
|
|
1041
|
-
templates: {
|
|
1042
|
-
operations: Operations.templates,
|
|
1043
|
-
...templates
|
|
1044
|
-
}
|
|
1045
|
-
},
|
|
1046
|
-
pre: [_pluginoas.pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
|
|
1047
|
-
resolvePath(baseName, pathMode, options2) {
|
|
1048
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
1049
|
-
const mode = _nullishCoalesce(pathMode, () => ( _core.FileManager.getMode(_path2.default.resolve(root, output.path))));
|
|
1050
|
-
if (mode === "single") {
|
|
1051
|
-
return _path2.default.resolve(root, output.path);
|
|
1052
|
-
}
|
|
1053
|
-
if (_optionalChain([options2, 'optionalAccess', _66 => _66.tag]) && _optionalChain([group, 'optionalAccess', _67 => _67.type]) === "tag") {
|
|
1054
|
-
const tag = _transformers.camelCase.call(void 0, options2.tag);
|
|
1055
|
-
return _path2.default.resolve(root, _utils.renderTemplate.call(void 0, template, { tag }), baseName);
|
|
1056
|
-
}
|
|
1057
|
-
return _path2.default.resolve(root, output.path, baseName);
|
|
1058
|
-
},
|
|
1059
|
-
resolveName(name, type) {
|
|
1060
|
-
let resolvedName = _transformers.camelCase.call(void 0, name, {
|
|
1061
|
-
suffix: type ? "schema" : void 0,
|
|
1062
|
-
isFile: type === "file"
|
|
1063
|
-
});
|
|
1064
|
-
if (type === "type") {
|
|
1065
|
-
resolvedName = _transformers.pascalCase.call(void 0, resolvedName);
|
|
1066
|
-
}
|
|
1067
|
-
if (type) {
|
|
1068
|
-
return _optionalChain([transformers7, 'optionalAccess', _68 => _68.name, 'optionalCall', _69 => _69(resolvedName, type)]) || resolvedName;
|
|
1069
|
-
}
|
|
1070
|
-
return resolvedName;
|
|
1071
|
-
},
|
|
1072
|
-
async buildStart() {
|
|
1073
|
-
const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
|
|
1074
|
-
const oas = await swaggerPlugin.context.getOas();
|
|
1075
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
1076
|
-
const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
|
|
1077
|
-
const schemaGenerator = new (0, _pluginoas.SchemaGenerator)(this.plugin.options, {
|
|
1078
|
-
oas,
|
|
1079
|
-
pluginManager: this.pluginManager,
|
|
1080
|
-
plugin: this.plugin,
|
|
1081
|
-
contentType: swaggerPlugin.context.contentType,
|
|
1082
|
-
include: void 0,
|
|
1083
|
-
override,
|
|
1084
|
-
mode,
|
|
1085
|
-
output: output.path
|
|
1086
|
-
});
|
|
1087
|
-
const schemaFiles = await schemaGenerator.build(zodParser);
|
|
1088
|
-
await this.addFile(...schemaFiles);
|
|
1089
|
-
const operationGenerator = new (0, _pluginoas.OperationGenerator)(this.plugin.options, {
|
|
1090
|
-
oas,
|
|
1091
|
-
pluginManager: this.pluginManager,
|
|
1092
|
-
plugin: this.plugin,
|
|
1093
|
-
contentType: swaggerPlugin.context.contentType,
|
|
1094
|
-
exclude,
|
|
1095
|
-
include,
|
|
1096
|
-
override,
|
|
1097
|
-
mode
|
|
1098
|
-
});
|
|
1099
|
-
const operationFiles = await operationGenerator.build(zodParser);
|
|
1100
|
-
await this.addFile(...operationFiles);
|
|
1101
|
-
if (this.config.output.write && _optionalChain([group, 'optionalAccess', _70 => _70.type]) === "tag") {
|
|
1102
|
-
const rootFiles = await _utils3.getGroupedByTagFiles.call(void 0, {
|
|
1103
|
-
logger: this.logger,
|
|
1104
|
-
files: this.fileManager.files,
|
|
1105
|
-
plugin: this.plugin,
|
|
1106
|
-
template,
|
|
1107
|
-
exportAs: group.exportAs || "{{tag}}Schemas",
|
|
1108
|
-
root,
|
|
1109
|
-
output
|
|
1110
|
-
});
|
|
1111
|
-
await this.addFile(...rootFiles);
|
|
1112
|
-
}
|
|
1113
|
-
},
|
|
1114
|
-
async buildEnd() {
|
|
1115
|
-
if (this.config.output.write === false) {
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
const root = _path2.default.resolve(this.config.root, this.config.output.path);
|
|
1119
|
-
const files = await this.fileManager.getIndexFiles({
|
|
1120
|
-
root,
|
|
1121
|
-
output,
|
|
1122
|
-
plugin: this.plugin,
|
|
1123
|
-
logger: this.logger
|
|
1124
|
-
});
|
|
1125
|
-
await this.fileManager.processFiles({
|
|
1126
|
-
logger: this.logger,
|
|
1127
|
-
files
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
};
|
|
1131
|
-
});
|
|
1132
|
-
|
|
1133
|
-
// src/components/Schema.tsx
|
|
1134
|
-
|
|
1135
|
-
function Schema2(props) {
|
|
1136
|
-
const { keysToOmit, withTypeAnnotation, description } = props;
|
|
1137
|
-
const { tree, name } = _hooks.useSchema.call(void 0, );
|
|
1138
|
-
const {
|
|
1139
|
-
pluginManager,
|
|
1140
|
-
plugin: {
|
|
1141
|
-
options: { mapper, typedSchema, coercion }
|
|
1142
|
-
}
|
|
1143
|
-
} = _react.useApp.call(void 0, );
|
|
1144
|
-
const resolvedName = pluginManager.resolveName({
|
|
1145
|
-
name,
|
|
1146
|
-
pluginKey: [pluginZodName],
|
|
1147
|
-
type: "function"
|
|
1148
|
-
});
|
|
1149
|
-
const resolvedTypeName = pluginManager.resolveName({
|
|
1150
|
-
name,
|
|
1151
|
-
pluginKey: [pluginZodName],
|
|
1152
|
-
type: "type"
|
|
1153
|
-
});
|
|
1154
|
-
const typeName = pluginManager.resolveName({
|
|
1155
|
-
name,
|
|
1156
|
-
pluginKey: [pluginTsName],
|
|
1157
|
-
type: "type"
|
|
1158
|
-
});
|
|
1159
|
-
if (!tree.length) {
|
|
1160
|
-
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1161
|
-
_react.Const,
|
|
1162
|
-
{
|
|
1163
|
-
name: resolvedName,
|
|
1164
|
-
export: true,
|
|
1165
|
-
JSDoc: {
|
|
1166
|
-
comments: [description ? `@description ${_transformers2.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
1167
|
-
},
|
|
1168
|
-
children: "undefined"
|
|
1169
|
-
}
|
|
1170
|
-
);
|
|
1171
|
-
}
|
|
1172
|
-
const hasTuple = tree.some((item) => _pluginoas.isKeyword.call(void 0, item, _pluginoas.schemaKeywords.tuple));
|
|
1173
|
-
const output = sort(tree).filter((item) => {
|
|
1174
|
-
if (hasTuple && (_pluginoas.isKeyword.call(void 0, item, _pluginoas.schemaKeywords.min) || _pluginoas.isKeyword.call(void 0, item, _pluginoas.schemaKeywords.max))) {
|
|
1175
|
-
return false;
|
|
1176
|
-
}
|
|
1177
|
-
return true;
|
|
1178
|
-
}).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
|
|
1179
|
-
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
1180
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
1181
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
1182
|
-
_react.Const,
|
|
1183
|
-
{
|
|
1184
|
-
export: true,
|
|
1185
|
-
name: resolvedName,
|
|
1186
|
-
JSDoc: {
|
|
1187
|
-
comments: [description ? `@description ${_transformers2.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
1188
|
-
},
|
|
1189
|
-
children: [
|
|
1190
|
-
output,
|
|
1191
|
-
_optionalChain([keysToOmit, 'optionalAccess', _71 => _71.length]) ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(",")} }))` : void 0,
|
|
1192
|
-
withTypeAnnotation && typeName ? ` as z.ZodType<${typeName}>` : ""
|
|
1193
|
-
].filter(Boolean).join("") || ""
|
|
1194
|
-
}
|
|
1195
|
-
),
|
|
1196
|
-
typedSchema && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Type, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` })
|
|
1197
|
-
] });
|
|
1198
|
-
}
|
|
1199
|
-
Schema2.File = function({}) {
|
|
1200
|
-
const {
|
|
1201
|
-
pluginManager,
|
|
1202
|
-
plugin: {
|
|
1203
|
-
options: { typed }
|
|
1204
|
-
}
|
|
1205
|
-
} = _react.useApp.call(void 0, );
|
|
1206
|
-
const { schema } = _hooks.useSchema.call(void 0, );
|
|
1207
|
-
const withTypeAnnotation = !!typed;
|
|
1208
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _components.Oas.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
1209
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema2.Imports, {}),
|
|
1210
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Schema2, { withTypeAnnotation, description: _optionalChain([schema, 'optionalAccess', _72 => _72.description]) }) })
|
|
1211
|
-
] });
|
|
1212
|
-
};
|
|
1213
|
-
Schema2.Imports = () => {
|
|
1214
|
-
const {
|
|
1215
|
-
pluginManager,
|
|
1216
|
-
plugin: {
|
|
1217
|
-
options: { typed, importPath }
|
|
1218
|
-
}
|
|
1219
|
-
} = _react.useApp.call(void 0, );
|
|
1220
|
-
const { path: root } = _react.useFile.call(void 0, );
|
|
1221
|
-
const { name, tree, schema } = _hooks.useSchema.call(void 0, );
|
|
1222
|
-
const typeName = pluginManager.resolveName({
|
|
1223
|
-
name,
|
|
1224
|
-
pluginKey: [pluginTsName],
|
|
1225
|
-
type: "type"
|
|
1226
|
-
});
|
|
1227
|
-
const typeFileName = pluginManager.resolveName({
|
|
1228
|
-
name,
|
|
1229
|
-
pluginKey: [pluginTsName],
|
|
1230
|
-
type: "file"
|
|
1231
|
-
});
|
|
1232
|
-
const typePath = pluginManager.resolvePath({
|
|
1233
|
-
baseName: typeFileName,
|
|
1234
|
-
pluginKey: [pluginTsName]
|
|
1235
|
-
});
|
|
1236
|
-
const withTypeAnnotation = !!typed;
|
|
1237
|
-
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
|
|
1238
|
-
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { name: ["z"], path: importPath }),
|
|
1239
|
-
withTypeAnnotation && typeName && typePath && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
1240
|
-
] });
|
|
1241
|
-
};
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
exports.Operations = Operations; exports.Schema = Schema2; exports.OperationSchema = OperationSchema2; exports.pluginZodName = pluginZodName; exports.pluginZod = pluginZod;
|
|
1250
|
-
//# sourceMappingURL=chunk-RISCJCJN.cjs.map
|