@kubb/plugin-zod 3.0.0-alpha.10 → 3.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-57AHBVYK.cjs → chunk-WDPKVCXH.cjs} +334 -374
- package/dist/chunk-WDPKVCXH.cjs.map +1 -0
- package/dist/{chunk-CUPQVLRZ.js → chunk-Z5LNW4XC.js} +183 -254
- package/dist/chunk-Z5LNW4XC.js.map +1 -0
- package/dist/components.cjs +17 -11
- package/dist/components.cjs.map +1 -1
- package/dist/components.js +3 -11
- package/dist/components.js.map +1 -1
- package/dist/index.cjs +12 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -9
- package/dist/index.js.map +1 -1
- package/package.json +12 -12
- package/dist/chunk-57AHBVYK.cjs.map +0 -1
- package/dist/chunk-CUPQVLRZ.js.map +0 -1
|
@@ -1,4 +1,42 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var components = require('@kubb/plugin-oas/components');
|
|
4
|
+
var react = require('@kubb/react');
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var core = require('@kubb/core');
|
|
7
|
+
var transformers4 = require('@kubb/core/transformers');
|
|
8
|
+
var utils = require('@kubb/core/utils');
|
|
9
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
10
|
+
var hooks = require('@kubb/plugin-oas/hooks');
|
|
11
|
+
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
12
|
+
var parserTs = require('@kubb/parser-ts');
|
|
13
|
+
var factory = require('@kubb/parser-ts/factory');
|
|
14
|
+
|
|
15
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
|
|
17
|
+
function _interopNamespace(e) {
|
|
18
|
+
if (e && e.__esModule) return e;
|
|
19
|
+
var n = Object.create(null);
|
|
20
|
+
if (e) {
|
|
21
|
+
Object.keys(e).forEach(function (k) {
|
|
22
|
+
if (k !== 'default') {
|
|
23
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return e[k]; }
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
n.default = e;
|
|
32
|
+
return Object.freeze(n);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
36
|
+
var transformers4__default = /*#__PURE__*/_interopDefault(transformers4);
|
|
37
|
+
var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
|
|
38
|
+
|
|
39
|
+
var __create = Object.create;
|
|
2
40
|
var __defProp = Object.defineProperty;
|
|
3
41
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
42
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -23,21 +61,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
61
|
// file that has been converted to a CommonJS file using a Babel-
|
|
24
62
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
63
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
|
|
64
|
+
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
27
65
|
mod
|
|
28
66
|
));
|
|
29
67
|
|
|
30
|
-
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
68
|
+
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__@swc+core@1.7.22_jiti@1.21.6__vls2oipdlkyfowb7gcil3cs6ye/node_modules/tsup/assets/cjs_shims.js
|
|
31
69
|
var init_cjs_shims = __esm({
|
|
32
|
-
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
33
|
-
"use strict";
|
|
70
|
+
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__@swc+core@1.7.22_jiti@1.21.6__vls2oipdlkyfowb7gcil3cs6ye/node_modules/tsup/assets/cjs_shims.js"() {
|
|
34
71
|
}
|
|
35
72
|
});
|
|
36
73
|
|
|
37
74
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
|
|
38
75
|
var require_react_production_min = __commonJS({
|
|
39
76
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js"(exports) {
|
|
40
|
-
"use strict";
|
|
41
77
|
init_cjs_shims();
|
|
42
78
|
var l = Symbol.for("react.element");
|
|
43
79
|
var n = Symbol.for("react.portal");
|
|
@@ -311,11 +347,9 @@ var require_react_production_min = __commonJS({
|
|
|
311
347
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js
|
|
312
348
|
var require_react_development = __commonJS({
|
|
313
349
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js"(exports, module) {
|
|
314
|
-
"use strict";
|
|
315
350
|
init_cjs_shims();
|
|
316
351
|
if (process.env.NODE_ENV !== "production") {
|
|
317
352
|
(function() {
|
|
318
|
-
"use strict";
|
|
319
353
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
320
354
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
321
355
|
}
|
|
@@ -2186,7 +2220,6 @@ var require_react_development = __commonJS({
|
|
|
2186
2220
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js
|
|
2187
2221
|
var require_react = __commonJS({
|
|
2188
2222
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js"(exports, module) {
|
|
2189
|
-
"use strict";
|
|
2190
2223
|
init_cjs_shims();
|
|
2191
2224
|
if (process.env.NODE_ENV === "production") {
|
|
2192
2225
|
module.exports = require_react_production_min();
|
|
@@ -2198,53 +2231,40 @@ var require_react = __commonJS({
|
|
|
2198
2231
|
|
|
2199
2232
|
// src/components/Schema.tsx
|
|
2200
2233
|
init_cjs_shims();
|
|
2201
|
-
var _components = require('@kubb/plugin-oas/components');
|
|
2202
|
-
var _react = require('@kubb/react');
|
|
2203
2234
|
|
|
2204
2235
|
// ../plugin-ts/src/index.ts
|
|
2205
2236
|
init_cjs_shims();
|
|
2206
2237
|
|
|
2207
2238
|
// ../plugin-ts/src/plugin.ts
|
|
2208
2239
|
init_cjs_shims();
|
|
2209
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
2210
|
-
var _core = require('@kubb/core');
|
|
2211
|
-
var _transformers = require('@kubb/core/transformers'); var _transformers2 = _interopRequireDefault(_transformers);
|
|
2212
|
-
var _utils = require('@kubb/core/utils');
|
|
2213
|
-
var _pluginoas = require('@kubb/plugin-oas');
|
|
2214
2240
|
|
|
2215
2241
|
// ../plugin-ts/src/OperationGenerator.tsx
|
|
2216
2242
|
init_cjs_shims();
|
|
2217
2243
|
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
2244
|
// ../plugin-ts/src/components/OasType.tsx
|
|
2222
2245
|
init_cjs_shims();
|
|
2223
|
-
var _hooks = require('@kubb/plugin-oas/hooks');
|
|
2224
|
-
|
|
2225
|
-
var _jsxruntime = require('@kubb/react/jsx-runtime');
|
|
2226
2246
|
function Template({ name, typeName, api }) {
|
|
2227
|
-
return /* @__PURE__ */
|
|
2228
|
-
/* @__PURE__ */
|
|
2229
|
-
/* @__PURE__ */
|
|
2230
|
-
/* @__PURE__ */
|
|
2247
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2248
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2249
|
+
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
2250
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
|
|
2231
2251
|
] });
|
|
2232
2252
|
}
|
|
2233
2253
|
var defaultTemplates = { default: Template };
|
|
2234
2254
|
function OasType({ name, typeName, Template: Template3 = defaultTemplates.default }) {
|
|
2235
|
-
const oas =
|
|
2236
|
-
return /* @__PURE__ */
|
|
2255
|
+
const oas = hooks.useOas();
|
|
2256
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template3, { name, typeName, api: oas.api });
|
|
2237
2257
|
}
|
|
2238
2258
|
OasType.File = function({ name, typeName, templates = defaultTemplates }) {
|
|
2239
2259
|
const {
|
|
2240
2260
|
pluginManager,
|
|
2241
2261
|
plugin: { key: pluginKey }
|
|
2242
|
-
} =
|
|
2262
|
+
} = react.useApp();
|
|
2243
2263
|
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
|
|
2244
2264
|
const Template3 = templates.default;
|
|
2245
|
-
return /* @__PURE__ */
|
|
2246
|
-
/* @__PURE__ */
|
|
2247
|
-
/* @__PURE__ */
|
|
2265
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2266
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
|
|
2267
|
+
/* @__PURE__ */ jsxRuntime.jsx(OasType, { Template: Template3, name, typeName })
|
|
2248
2268
|
] });
|
|
2249
2269
|
};
|
|
2250
2270
|
OasType.templates = defaultTemplates;
|
|
@@ -2252,74 +2272,55 @@ OasType.templates = defaultTemplates;
|
|
|
2252
2272
|
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
2253
2273
|
init_cjs_shims();
|
|
2254
2274
|
|
|
2255
|
-
var _parserts = require('@kubb/parser-ts');
|
|
2256
|
-
var _factory = require('@kubb/parser-ts/factory'); var factory3 = _interopRequireWildcard(_factory); var factory2 = _interopRequireWildcard(_factory); var factory = _interopRequireWildcard(_factory);
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
2275
|
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
2262
2276
|
init_cjs_shims();
|
|
2263
2277
|
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
2278
|
// ../plugin-ts/src/components/Schema.tsx
|
|
2268
2279
|
init_cjs_shims();
|
|
2269
|
-
var import_react3 = __toESM(require_react()
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2280
|
+
var import_react3 = __toESM(require_react());
|
|
2277
2281
|
|
|
2278
2282
|
// ../plugin-ts/src/parser/index.ts
|
|
2279
2283
|
init_cjs_shims();
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
2284
|
var typeKeywordMapper = {
|
|
2284
|
-
any: () =>
|
|
2285
|
-
unknown: () =>
|
|
2286
|
-
number: () =>
|
|
2287
|
-
integer: () =>
|
|
2285
|
+
any: () => factory__namespace.keywordTypeNodes.any,
|
|
2286
|
+
unknown: () => factory__namespace.keywordTypeNodes.unknown,
|
|
2287
|
+
number: () => factory__namespace.keywordTypeNodes.number,
|
|
2288
|
+
integer: () => factory__namespace.keywordTypeNodes.number,
|
|
2288
2289
|
object: (nodes) => {
|
|
2289
2290
|
if (!nodes || !nodes.length) {
|
|
2290
|
-
return
|
|
2291
|
+
return factory__namespace.keywordTypeNodes.object;
|
|
2291
2292
|
}
|
|
2292
|
-
return
|
|
2293
|
+
return factory__namespace.createTypeLiteralNode(nodes);
|
|
2293
2294
|
},
|
|
2294
|
-
string: () =>
|
|
2295
|
-
boolean: () =>
|
|
2296
|
-
undefined: () =>
|
|
2295
|
+
string: () => factory__namespace.keywordTypeNodes.string,
|
|
2296
|
+
boolean: () => factory__namespace.keywordTypeNodes.boolean,
|
|
2297
|
+
undefined: () => factory__namespace.keywordTypeNodes.undefined,
|
|
2297
2298
|
nullable: void 0,
|
|
2298
|
-
null: () =>
|
|
2299
|
+
null: () => factory__namespace.keywordTypeNodes.null,
|
|
2299
2300
|
nullish: void 0,
|
|
2300
2301
|
array: (nodes) => {
|
|
2301
2302
|
if (!nodes) {
|
|
2302
2303
|
return void 0;
|
|
2303
2304
|
}
|
|
2304
|
-
return
|
|
2305
|
+
return factory__namespace.createArrayDeclaration({ nodes });
|
|
2305
2306
|
},
|
|
2306
2307
|
tuple: (nodes) => {
|
|
2307
2308
|
if (!nodes) {
|
|
2308
2309
|
return void 0;
|
|
2309
2310
|
}
|
|
2310
|
-
return
|
|
2311
|
+
return factory__namespace.createTupleTypeNode(nodes);
|
|
2311
2312
|
},
|
|
2312
2313
|
enum: (name) => {
|
|
2313
2314
|
if (!name) {
|
|
2314
2315
|
return void 0;
|
|
2315
2316
|
}
|
|
2316
|
-
return
|
|
2317
|
+
return factory__namespace.createTypeReferenceNode(name, void 0);
|
|
2317
2318
|
},
|
|
2318
2319
|
union: (nodes) => {
|
|
2319
2320
|
if (!nodes) {
|
|
2320
2321
|
return void 0;
|
|
2321
2322
|
}
|
|
2322
|
-
return
|
|
2323
|
+
return factory__namespace.createUnionDeclaration({
|
|
2323
2324
|
withParentheses: true,
|
|
2324
2325
|
nodes
|
|
2325
2326
|
});
|
|
@@ -2329,13 +2330,13 @@ var typeKeywordMapper = {
|
|
|
2329
2330
|
return void 0;
|
|
2330
2331
|
}
|
|
2331
2332
|
if (format === "number") {
|
|
2332
|
-
return
|
|
2333
|
+
return factory__namespace.createLiteralTypeNode(factory__namespace.createNumericLiteral(name));
|
|
2333
2334
|
}
|
|
2334
|
-
return
|
|
2335
|
+
return factory__namespace.createLiteralTypeNode(factory__namespace.createStringLiteral(name.toString()));
|
|
2335
2336
|
},
|
|
2336
|
-
datetime: () =>
|
|
2337
|
-
date: (type = "string") => type === "string" ?
|
|
2338
|
-
time: (type = "string") => type === "string" ?
|
|
2337
|
+
datetime: () => factory__namespace.keywordTypeNodes.string,
|
|
2338
|
+
date: (type = "string") => type === "string" ? factory__namespace.keywordTypeNodes.string : factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier("Date")),
|
|
2339
|
+
time: (type = "string") => type === "string" ? factory__namespace.keywordTypeNodes.string : factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier("Date")),
|
|
2339
2340
|
uuid: void 0,
|
|
2340
2341
|
url: void 0,
|
|
2341
2342
|
strict: void 0,
|
|
@@ -2344,7 +2345,7 @@ var typeKeywordMapper = {
|
|
|
2344
2345
|
if (!nodes) {
|
|
2345
2346
|
return void 0;
|
|
2346
2347
|
}
|
|
2347
|
-
return
|
|
2348
|
+
return factory__namespace.createIntersectionDeclaration({
|
|
2348
2349
|
withParentheses: true,
|
|
2349
2350
|
nodes
|
|
2350
2351
|
});
|
|
@@ -2364,9 +2365,9 @@ var typeKeywordMapper = {
|
|
|
2364
2365
|
if (!propertyName) {
|
|
2365
2366
|
return void 0;
|
|
2366
2367
|
}
|
|
2367
|
-
return
|
|
2368
|
+
return factory__namespace.createTypeReferenceNode(propertyName, void 0);
|
|
2368
2369
|
},
|
|
2369
|
-
blob: () =>
|
|
2370
|
+
blob: () => factory__namespace.createTypeReferenceNode("Blob", []),
|
|
2370
2371
|
deprecated: void 0,
|
|
2371
2372
|
example: void 0,
|
|
2372
2373
|
schema: void 0,
|
|
@@ -2378,94 +2379,94 @@ function parse(parent, current, options) {
|
|
|
2378
2379
|
if (!value) {
|
|
2379
2380
|
return void 0;
|
|
2380
2381
|
}
|
|
2381
|
-
if (
|
|
2382
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.union)) {
|
|
2382
2383
|
return typeKeywordMapper.union(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
2383
2384
|
}
|
|
2384
|
-
if (
|
|
2385
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.and)) {
|
|
2385
2386
|
return typeKeywordMapper.and(current.args.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
2386
2387
|
}
|
|
2387
|
-
if (
|
|
2388
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.array)) {
|
|
2388
2389
|
return typeKeywordMapper.array(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
2389
2390
|
}
|
|
2390
|
-
if (
|
|
2391
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.enum)) {
|
|
2391
2392
|
return typeKeywordMapper.enum(current.args.typeName);
|
|
2392
2393
|
}
|
|
2393
|
-
if (
|
|
2394
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.ref)) {
|
|
2394
2395
|
return typeKeywordMapper.ref(current.args.name);
|
|
2395
2396
|
}
|
|
2396
|
-
if (
|
|
2397
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.blob)) {
|
|
2397
2398
|
return value();
|
|
2398
2399
|
}
|
|
2399
|
-
if (
|
|
2400
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.tuple)) {
|
|
2400
2401
|
return typeKeywordMapper.tuple(current.args.items.map((schema) => parse(current, schema, options)).filter(Boolean));
|
|
2401
2402
|
}
|
|
2402
|
-
if (
|
|
2403
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.const)) {
|
|
2403
2404
|
return typeKeywordMapper.const(current.args.name, current.args.format);
|
|
2404
2405
|
}
|
|
2405
|
-
if (
|
|
2406
|
-
const properties = Object.entries(
|
|
2406
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.object)) {
|
|
2407
|
+
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
2407
2408
|
const schemas = item[1];
|
|
2408
2409
|
return schemas && typeof schemas.map === "function";
|
|
2409
2410
|
}).map(([name, schemas]) => {
|
|
2410
|
-
const nameSchema = schemas.find((schema) => schema.keyword ===
|
|
2411
|
-
const mappedName =
|
|
2412
|
-
if (
|
|
2413
|
-
return
|
|
2411
|
+
const nameSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.name);
|
|
2412
|
+
const mappedName = nameSchema?.args || name;
|
|
2413
|
+
if (options.mapper?.[mappedName]) {
|
|
2414
|
+
return options.mapper?.[mappedName];
|
|
2414
2415
|
}
|
|
2415
|
-
const isNullish = schemas.some((schema) => schema.keyword ===
|
|
2416
|
-
const isNullable = schemas.some((schema) => schema.keyword ===
|
|
2417
|
-
const isOptional = schemas.some((schema) => schema.keyword ===
|
|
2418
|
-
const isReadonly = schemas.some((schema) => schema.keyword ===
|
|
2419
|
-
const describeSchema = schemas.find((schema) => schema.keyword ===
|
|
2420
|
-
const deprecatedSchema = schemas.find((schema) => schema.keyword ===
|
|
2421
|
-
const defaultSchema = schemas.find((schema) => schema.keyword ===
|
|
2422
|
-
const exampleSchema = schemas.find((schema) => schema.keyword ===
|
|
2423
|
-
const schemaSchema = schemas.find((schema) => schema.keyword ===
|
|
2416
|
+
const isNullish = schemas.some((schema) => schema.keyword === pluginOas.schemaKeywords.nullish);
|
|
2417
|
+
const isNullable = schemas.some((schema) => schema.keyword === pluginOas.schemaKeywords.nullable);
|
|
2418
|
+
const isOptional = schemas.some((schema) => schema.keyword === pluginOas.schemaKeywords.optional);
|
|
2419
|
+
const isReadonly = schemas.some((schema) => schema.keyword === pluginOas.schemaKeywords.readOnly);
|
|
2420
|
+
const describeSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.describe);
|
|
2421
|
+
const deprecatedSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.deprecated);
|
|
2422
|
+
const defaultSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.default);
|
|
2423
|
+
const exampleSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.example);
|
|
2424
|
+
const schemaSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.schema);
|
|
2424
2425
|
let type = schemas.map((schema) => parse(current, schema, options)).filter(Boolean)[0];
|
|
2425
2426
|
if (isNullable) {
|
|
2426
|
-
type =
|
|
2427
|
-
nodes: [type,
|
|
2427
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2428
|
+
nodes: [type, factory__namespace.keywordTypeNodes.null]
|
|
2428
2429
|
});
|
|
2429
2430
|
}
|
|
2430
2431
|
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
|
|
2431
|
-
type =
|
|
2432
|
-
nodes: [type,
|
|
2432
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2433
|
+
nodes: [type, factory__namespace.keywordTypeNodes.undefined]
|
|
2433
2434
|
});
|
|
2434
2435
|
}
|
|
2435
2436
|
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(options.optionalType)) {
|
|
2436
|
-
type =
|
|
2437
|
-
nodes: [type,
|
|
2437
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2438
|
+
nodes: [type, factory__namespace.keywordTypeNodes.undefined]
|
|
2438
2439
|
});
|
|
2439
2440
|
}
|
|
2440
|
-
const propertySignature =
|
|
2441
|
+
const propertySignature = factory__namespace.createPropertySignature({
|
|
2441
2442
|
questionToken: isOptional || isNullish ? ["questionToken", "questionTokenAndUndefined"].includes(options.optionalType) : false,
|
|
2442
2443
|
name: mappedName,
|
|
2443
2444
|
type,
|
|
2444
2445
|
readOnly: isReadonly
|
|
2445
2446
|
});
|
|
2446
|
-
return
|
|
2447
|
+
return factory__namespace.appendJSDocToNode({
|
|
2447
2448
|
node: propertySignature,
|
|
2448
2449
|
comments: [
|
|
2449
|
-
describeSchema ? `@description ${
|
|
2450
|
+
describeSchema ? `@description ${transformers4__default.default.jsStringEscape(describeSchema.args)}` : void 0,
|
|
2450
2451
|
deprecatedSchema ? "@deprecated" : void 0,
|
|
2451
2452
|
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
|
2452
2453
|
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
|
2453
|
-
|
|
2454
|
+
schemaSchema?.args?.type || schemaSchema?.args?.format ? [`@type ${schemaSchema?.args?.type || "unknown"}${!isOptional ? "" : " | undefined"}`, schemaSchema?.args?.format].filter(Boolean).join(", ") : void 0
|
|
2454
2455
|
].filter(Boolean)
|
|
2455
2456
|
});
|
|
2456
2457
|
});
|
|
2457
|
-
const additionalProperties =
|
|
2458
|
+
const additionalProperties = current.args?.additionalProperties?.length ? factory__namespace.createIndexSignature(
|
|
2458
2459
|
current.args.additionalProperties.map((schema) => parse(current, schema, options)).filter(Boolean).at(0)
|
|
2459
2460
|
) : void 0;
|
|
2460
2461
|
return typeKeywordMapper.object([...properties, additionalProperties].filter(Boolean));
|
|
2461
2462
|
}
|
|
2462
|
-
if (
|
|
2463
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.datetime)) {
|
|
2463
2464
|
return typeKeywordMapper.datetime();
|
|
2464
2465
|
}
|
|
2465
|
-
if (
|
|
2466
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.date)) {
|
|
2466
2467
|
return typeKeywordMapper.date(current.args.type);
|
|
2467
2468
|
}
|
|
2468
|
-
if (
|
|
2469
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.time)) {
|
|
2469
2470
|
return typeKeywordMapper.time(current.args.type);
|
|
2470
2471
|
}
|
|
2471
2472
|
if (current.keyword in typeKeywordMapper) {
|
|
@@ -2473,18 +2474,15 @@ function parse(parent, current, options) {
|
|
|
2473
2474
|
}
|
|
2474
2475
|
return void 0;
|
|
2475
2476
|
}
|
|
2476
|
-
|
|
2477
|
-
// ../plugin-ts/src/components/Schema.tsx
|
|
2478
|
-
|
|
2479
2477
|
function Schema(props) {
|
|
2480
2478
|
const { keysToOmit, description } = props;
|
|
2481
|
-
const { tree, name } =
|
|
2479
|
+
const { tree, name } = hooks.useSchema();
|
|
2482
2480
|
const {
|
|
2483
2481
|
pluginManager,
|
|
2484
2482
|
plugin: {
|
|
2485
2483
|
options: { mapper, enumType, optionalType }
|
|
2486
2484
|
}
|
|
2487
|
-
} =
|
|
2485
|
+
} = react.useApp();
|
|
2488
2486
|
if (enumType === "asPascalConst") {
|
|
2489
2487
|
pluginManager.logger.emit("warning", `enumType '${enumType}' is deprecated`);
|
|
2490
2488
|
}
|
|
@@ -2502,9 +2500,9 @@ function Schema(props) {
|
|
|
2502
2500
|
if (!tree.length) {
|
|
2503
2501
|
return "";
|
|
2504
2502
|
}
|
|
2505
|
-
const isNullish = tree.some((item) => item.keyword ===
|
|
2506
|
-
const isNullable = tree.some((item) => item.keyword ===
|
|
2507
|
-
const isOptional = tree.some((item) => item.keyword ===
|
|
2503
|
+
const isNullish = tree.some((item) => item.keyword === pluginOas.schemaKeywords.nullish);
|
|
2504
|
+
const isNullable = tree.some((item) => item.keyword === pluginOas.schemaKeywords.nullable);
|
|
2505
|
+
const isOptional = tree.some((item) => item.keyword === pluginOas.schemaKeywords.optional);
|
|
2508
2506
|
let type = tree.map(
|
|
2509
2507
|
(schema) => parse(void 0, schema, {
|
|
2510
2508
|
name: resolvedName,
|
|
@@ -2517,37 +2515,37 @@ function Schema(props) {
|
|
|
2517
2515
|
})
|
|
2518
2516
|
).filter(Boolean).at(0) || typeKeywordMapper.undefined();
|
|
2519
2517
|
if (isNullable) {
|
|
2520
|
-
type =
|
|
2521
|
-
nodes: [type,
|
|
2518
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2519
|
+
nodes: [type, factory__namespace.keywordTypeNodes.null]
|
|
2522
2520
|
});
|
|
2523
2521
|
}
|
|
2524
2522
|
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
2525
|
-
type =
|
|
2526
|
-
nodes: [type,
|
|
2523
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2524
|
+
nodes: [type, factory__namespace.keywordTypeNodes.undefined]
|
|
2527
2525
|
});
|
|
2528
2526
|
}
|
|
2529
2527
|
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
2530
|
-
type =
|
|
2531
|
-
nodes: [type,
|
|
2528
|
+
type = factory__namespace.createUnionDeclaration({
|
|
2529
|
+
nodes: [type, factory__namespace.keywordTypeNodes.undefined]
|
|
2532
2530
|
});
|
|
2533
2531
|
}
|
|
2534
|
-
const node =
|
|
2535
|
-
modifiers: [
|
|
2532
|
+
const node = factory__namespace.createTypeAliasDeclaration({
|
|
2533
|
+
modifiers: [factory__namespace.modifiers.export],
|
|
2536
2534
|
name: resolvedName,
|
|
2537
|
-
type:
|
|
2535
|
+
type: keysToOmit?.length ? factory__namespace.createOmitDeclaration({
|
|
2538
2536
|
keys: keysToOmit,
|
|
2539
2537
|
type,
|
|
2540
2538
|
nonNullable: true
|
|
2541
2539
|
}) : type
|
|
2542
2540
|
});
|
|
2543
|
-
const enumSchemas =
|
|
2541
|
+
const enumSchemas = pluginOas.SchemaGenerator.deepSearch(tree, pluginOas.schemaKeywords.enum);
|
|
2544
2542
|
const enums = enumSchemas.map((enumSchema) => {
|
|
2545
|
-
const name2 = enumType === "asPascalConst" ?
|
|
2543
|
+
const name2 = enumType === "asPascalConst" ? transformers4__default.default.pascalCase(enumSchema.args.name) : transformers4__default.default.camelCase(enumSchema.args.name);
|
|
2546
2544
|
const typeName2 = enumSchema.args.typeName;
|
|
2547
|
-
const [nameNode, typeNode] =
|
|
2545
|
+
const [nameNode, typeNode] = factory__namespace.createEnumDeclaration({
|
|
2548
2546
|
name: name2,
|
|
2549
2547
|
typeName: typeName2,
|
|
2550
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [
|
|
2548
|
+
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers4__default.default.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
|
|
2551
2549
|
type: enumType
|
|
2552
2550
|
});
|
|
2553
2551
|
return {
|
|
@@ -2558,43 +2556,37 @@ function Schema(props) {
|
|
|
2558
2556
|
};
|
|
2559
2557
|
});
|
|
2560
2558
|
typeNodes.push(
|
|
2561
|
-
|
|
2559
|
+
factory__namespace.appendJSDocToNode({
|
|
2562
2560
|
node,
|
|
2563
|
-
comments: [description ? `@description ${
|
|
2561
|
+
comments: [description ? `@description ${transformers4__default.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
2564
2562
|
})
|
|
2565
2563
|
);
|
|
2566
|
-
return /* @__PURE__ */
|
|
2567
|
-
enums.map(({ name: name2, nameNode, typeName: typeName2, typeNode }, index) => /* @__PURE__ */
|
|
2568
|
-
nameNode && /* @__PURE__ */
|
|
2569
|
-
/* @__PURE__ */
|
|
2564
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(import_react3.Fragment, { children: [
|
|
2565
|
+
enums.map(({ name: name2, nameNode, typeName: typeName2, typeNode }, index) => /* @__PURE__ */ jsxRuntime.jsxs(import_react3.Fragment, { children: [
|
|
2566
|
+
nameNode && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: name2, isExportable: true, isIndexable: true, children: parserTs.print(nameNode) }),
|
|
2567
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName2, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: parserTs.print(typeNode) })
|
|
2570
2568
|
] }, [name2, nameNode].join("-"))),
|
|
2571
|
-
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */
|
|
2569
|
+
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isTypeOnly: true, isExportable: true, isIndexable: true, children: parserTs.print(typeNodes) })
|
|
2572
2570
|
] });
|
|
2573
2571
|
}
|
|
2574
2572
|
Schema.File = function({}) {
|
|
2575
|
-
const { pluginManager } =
|
|
2576
|
-
const { schema } =
|
|
2577
|
-
return /* @__PURE__ */
|
|
2573
|
+
const { pluginManager } = react.useApp();
|
|
2574
|
+
const { schema } = hooks.useSchema();
|
|
2575
|
+
return /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema.File, { isTypeOnly: true, output: pluginManager.config.output.path, children: /* @__PURE__ */ jsxRuntime.jsx(Schema, { description: schema?.description }) });
|
|
2578
2576
|
};
|
|
2579
|
-
|
|
2580
|
-
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
2581
|
-
|
|
2582
|
-
var SchemaGenerator2 = class extends _pluginoas.SchemaGenerator {
|
|
2577
|
+
var SchemaGenerator2 = class extends pluginOas.SchemaGenerator {
|
|
2583
2578
|
async schema(name, schema, options) {
|
|
2584
2579
|
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
2585
|
-
const root =
|
|
2580
|
+
const root = react.createRoot({
|
|
2586
2581
|
logger: pluginManager.logger
|
|
2587
2582
|
});
|
|
2588
2583
|
const tree = this.parse({ schema, name });
|
|
2589
2584
|
root.render(
|
|
2590
|
-
/* @__PURE__ */
|
|
2585
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsxRuntime.jsx(Schema.File, {}) }) }) })
|
|
2591
2586
|
);
|
|
2592
2587
|
return root.files;
|
|
2593
2588
|
}
|
|
2594
2589
|
};
|
|
2595
|
-
|
|
2596
|
-
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
2597
|
-
|
|
2598
2590
|
function printCombinedSchema({
|
|
2599
2591
|
name,
|
|
2600
2592
|
operation,
|
|
@@ -2608,7 +2600,7 @@ function printCombinedSchema({
|
|
|
2608
2600
|
pluginKey: [pluginTsName],
|
|
2609
2601
|
type: "function"
|
|
2610
2602
|
});
|
|
2611
|
-
properties["response"] =
|
|
2603
|
+
properties["response"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
|
|
2612
2604
|
}
|
|
2613
2605
|
if (schemas.request) {
|
|
2614
2606
|
const identifier = pluginManager.resolveName({
|
|
@@ -2616,7 +2608,7 @@ function printCombinedSchema({
|
|
|
2616
2608
|
pluginKey: [pluginTsName],
|
|
2617
2609
|
type: "function"
|
|
2618
2610
|
});
|
|
2619
|
-
properties["request"] =
|
|
2611
|
+
properties["request"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
|
|
2620
2612
|
}
|
|
2621
2613
|
if (schemas.pathParams) {
|
|
2622
2614
|
const identifier = pluginManager.resolveName({
|
|
@@ -2624,7 +2616,7 @@ function printCombinedSchema({
|
|
|
2624
2616
|
pluginKey: [pluginTsName],
|
|
2625
2617
|
type: "function"
|
|
2626
2618
|
});
|
|
2627
|
-
properties["pathParams"] =
|
|
2619
|
+
properties["pathParams"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
|
|
2628
2620
|
}
|
|
2629
2621
|
if (schemas.queryParams) {
|
|
2630
2622
|
const identifier = pluginManager.resolveName({
|
|
@@ -2632,7 +2624,7 @@ function printCombinedSchema({
|
|
|
2632
2624
|
pluginKey: [pluginTsName],
|
|
2633
2625
|
type: "function"
|
|
2634
2626
|
});
|
|
2635
|
-
properties["queryParams"] =
|
|
2627
|
+
properties["queryParams"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
|
|
2636
2628
|
}
|
|
2637
2629
|
if (schemas.headerParams) {
|
|
2638
2630
|
const identifier = pluginManager.resolveName({
|
|
@@ -2640,46 +2632,46 @@ function printCombinedSchema({
|
|
|
2640
2632
|
pluginKey: [pluginTsName],
|
|
2641
2633
|
type: "function"
|
|
2642
2634
|
});
|
|
2643
|
-
properties["headerParams"] =
|
|
2635
|
+
properties["headerParams"] = factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
|
|
2644
2636
|
}
|
|
2645
2637
|
if (schemas.errors) {
|
|
2646
|
-
properties["errors"] =
|
|
2638
|
+
properties["errors"] = factory__namespace.createUnionDeclaration({
|
|
2647
2639
|
nodes: schemas.errors.map((error) => {
|
|
2648
2640
|
const identifier = pluginManager.resolveName({
|
|
2649
2641
|
name: error.name,
|
|
2650
2642
|
pluginKey: [pluginTsName],
|
|
2651
2643
|
type: "function"
|
|
2652
2644
|
});
|
|
2653
|
-
return
|
|
2645
|
+
return factory__namespace.createTypeReferenceNode(factory__namespace.createIdentifier(identifier), void 0);
|
|
2654
2646
|
})
|
|
2655
2647
|
});
|
|
2656
2648
|
}
|
|
2657
|
-
const namespaceNode =
|
|
2649
|
+
const namespaceNode = factory__namespace.createTypeAliasDeclaration({
|
|
2658
2650
|
name,
|
|
2659
|
-
type:
|
|
2651
|
+
type: factory__namespace.createTypeLiteralNode(
|
|
2660
2652
|
Object.keys(properties).map((key) => {
|
|
2661
2653
|
const type = properties[key];
|
|
2662
2654
|
if (!type) {
|
|
2663
2655
|
return void 0;
|
|
2664
2656
|
}
|
|
2665
|
-
return
|
|
2666
|
-
name:
|
|
2657
|
+
return factory__namespace.createPropertySignature({
|
|
2658
|
+
name: transformers4__default.default.pascalCase(key),
|
|
2667
2659
|
type
|
|
2668
2660
|
});
|
|
2669
2661
|
}).filter(Boolean)
|
|
2670
2662
|
),
|
|
2671
|
-
modifiers: [
|
|
2663
|
+
modifiers: [factory__namespace.modifiers.export]
|
|
2672
2664
|
});
|
|
2673
|
-
return
|
|
2665
|
+
return parserTs.print(namespaceNode);
|
|
2674
2666
|
}
|
|
2675
2667
|
function OperationSchema({ keysToOmit, description }) {
|
|
2676
|
-
return /* @__PURE__ */
|
|
2668
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Schema, { keysToOmit, description });
|
|
2677
2669
|
}
|
|
2678
2670
|
OperationSchema.File = function({}) {
|
|
2679
|
-
const { pluginManager, plugin, mode } =
|
|
2680
|
-
const oas =
|
|
2681
|
-
const { getSchemas, getFile, getName } =
|
|
2682
|
-
const operation =
|
|
2671
|
+
const { pluginManager, plugin, mode } = react.useApp();
|
|
2672
|
+
const oas = hooks.useOas();
|
|
2673
|
+
const { getSchemas, getFile, getName } = hooks.useOperationManager();
|
|
2674
|
+
const operation = hooks.useOperation();
|
|
2683
2675
|
const file = getFile(operation);
|
|
2684
2676
|
const schemas = getSchemas(operation);
|
|
2685
2677
|
const factoryName = getName(operation, { type: "type" });
|
|
@@ -2693,38 +2685,35 @@ OperationSchema.File = function({}) {
|
|
|
2693
2685
|
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
2694
2686
|
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
2695
2687
|
const tree = generator.parse({ schema, name });
|
|
2696
|
-
return /* @__PURE__ */
|
|
2697
|
-
mode === "split" && /* @__PURE__ */
|
|
2698
|
-
/* @__PURE__ */
|
|
2688
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
|
|
2689
|
+
mode === "split" && /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema.Imports, { isTypeOnly: true }),
|
|
2690
|
+
/* @__PURE__ */ jsxRuntime.jsx(OperationSchema, { description, keysToOmit })
|
|
2699
2691
|
] }, i);
|
|
2700
2692
|
};
|
|
2701
2693
|
const combinedSchemaName = operation.method === "get" ? `${factoryName}Query` : `${factoryName}Mutation`;
|
|
2702
|
-
return /* @__PURE__ */
|
|
2694
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2703
2695
|
items.map(mapItem),
|
|
2704
|
-
/* @__PURE__ */
|
|
2696
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2705
2697
|
] });
|
|
2706
2698
|
};
|
|
2707
|
-
|
|
2708
|
-
// ../plugin-ts/src/OperationGenerator.tsx
|
|
2709
|
-
|
|
2710
|
-
var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
2699
|
+
var OperationGenerator = class extends pluginOas.OperationGenerator {
|
|
2711
2700
|
async all(operations) {
|
|
2712
2701
|
const { oas, pluginManager, plugin, mode } = this.context;
|
|
2713
|
-
const root =
|
|
2702
|
+
const root = react.createRoot({
|
|
2714
2703
|
logger: pluginManager.logger
|
|
2715
2704
|
});
|
|
2716
2705
|
root.render(
|
|
2717
|
-
/* @__PURE__ */
|
|
2706
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsxRuntime.jsx(OasType.File, { name: "oas", typeName: "Oas" }) }) })
|
|
2718
2707
|
);
|
|
2719
2708
|
return root.files;
|
|
2720
2709
|
}
|
|
2721
2710
|
async operation(operation, options) {
|
|
2722
2711
|
const { oas, pluginManager, plugin, mode } = this.context;
|
|
2723
|
-
const root =
|
|
2712
|
+
const root = react.createRoot({
|
|
2724
2713
|
logger: pluginManager.logger
|
|
2725
2714
|
});
|
|
2726
2715
|
root.render(
|
|
2727
|
-
/* @__PURE__ */
|
|
2716
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Operation, { operation, children: /* @__PURE__ */ jsxRuntime.jsx(OperationSchema.File, {}) }) }) })
|
|
2728
2717
|
);
|
|
2729
2718
|
return root.files;
|
|
2730
2719
|
}
|
|
@@ -2732,7 +2721,7 @@ var OperationGenerator = class extends _pluginoas.OperationGenerator {
|
|
|
2732
2721
|
|
|
2733
2722
|
// ../plugin-ts/src/plugin.ts
|
|
2734
2723
|
var pluginTsName = "plugin-ts";
|
|
2735
|
-
|
|
2724
|
+
core.createPlugin((options) => {
|
|
2736
2725
|
const {
|
|
2737
2726
|
output = { path: "types" },
|
|
2738
2727
|
group,
|
|
@@ -2748,7 +2737,7 @@ var pluginTs = _core.createPlugin.call(void 0, (options) => {
|
|
|
2748
2737
|
oasType = false,
|
|
2749
2738
|
mapper = {}
|
|
2750
2739
|
} = options;
|
|
2751
|
-
const template =
|
|
2740
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
2752
2741
|
return {
|
|
2753
2742
|
name: pluginTsName,
|
|
2754
2743
|
output: {
|
|
@@ -2769,31 +2758,31 @@ var pluginTs = _core.createPlugin.call(void 0, (options) => {
|
|
|
2769
2758
|
override,
|
|
2770
2759
|
mapper
|
|
2771
2760
|
},
|
|
2772
|
-
pre: [
|
|
2761
|
+
pre: [pluginOas.pluginOasName],
|
|
2773
2762
|
resolvePath(baseName, pathMode, options2) {
|
|
2774
|
-
const root =
|
|
2775
|
-
const mode =
|
|
2763
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
2764
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
2776
2765
|
if (mode === "single") {
|
|
2777
|
-
return
|
|
2766
|
+
return path__default.default.resolve(root, output.path);
|
|
2778
2767
|
}
|
|
2779
|
-
if (
|
|
2780
|
-
const tag =
|
|
2781
|
-
return
|
|
2768
|
+
if (options2?.tag && group?.type === "tag") {
|
|
2769
|
+
const tag = transformers4.camelCase(options2.tag);
|
|
2770
|
+
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
2782
2771
|
}
|
|
2783
|
-
return
|
|
2772
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
2784
2773
|
},
|
|
2785
2774
|
resolveName(name, type) {
|
|
2786
|
-
const resolvedName =
|
|
2775
|
+
const resolvedName = transformers4.pascalCase(name, { isFile: type === "file" });
|
|
2787
2776
|
if (type) {
|
|
2788
|
-
return
|
|
2777
|
+
return transformers7?.name?.(resolvedName, type) || resolvedName;
|
|
2789
2778
|
}
|
|
2790
2779
|
return resolvedName;
|
|
2791
2780
|
},
|
|
2792
2781
|
async buildStart() {
|
|
2793
|
-
const [swaggerPlugin] =
|
|
2782
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
2794
2783
|
const oas = await swaggerPlugin.context.getOas();
|
|
2795
|
-
const root =
|
|
2796
|
-
const mode =
|
|
2784
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
2785
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
2797
2786
|
const schemaGenerator = new SchemaGenerator2(this.plugin.options, {
|
|
2798
2787
|
oas,
|
|
2799
2788
|
pluginManager: this.pluginManager,
|
|
@@ -2834,15 +2823,8 @@ var pluginTs = _core.createPlugin.call(void 0, (options) => {
|
|
|
2834
2823
|
};
|
|
2835
2824
|
});
|
|
2836
2825
|
|
|
2837
|
-
// src/components/Schema.tsx
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
2826
|
// src/parser/index.ts
|
|
2843
2827
|
init_cjs_shims();
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
2828
|
var zodKeywordMapper = {
|
|
2847
2829
|
any: () => "z.any()",
|
|
2848
2830
|
unknown: () => "z.unknown()",
|
|
@@ -2866,12 +2848,12 @@ var zodKeywordMapper = {
|
|
|
2866
2848
|
null: () => "z.null()",
|
|
2867
2849
|
nullish: () => ".nullish()",
|
|
2868
2850
|
array: (items = [], min, max) => {
|
|
2869
|
-
return [`z.array(${
|
|
2851
|
+
return [`z.array(${items?.join("")})`, min !== void 0 ? `.min(${min})` : void 0, max !== void 0 ? `.max(${max})` : void 0].filter(Boolean).join("");
|
|
2870
2852
|
},
|
|
2871
|
-
tuple: (items = []) => `z.tuple([${
|
|
2872
|
-
enum: (items = []) => `z.enum([${
|
|
2873
|
-
union: (items = []) => `z.union([${
|
|
2874
|
-
const: (value) => `z.literal(${
|
|
2853
|
+
tuple: (items = []) => `z.tuple([${items?.join(", ")}])`,
|
|
2854
|
+
enum: (items = []) => `z.enum([${items?.join(", ")}])`,
|
|
2855
|
+
union: (items = []) => `z.union([${items?.join(", ")}])`,
|
|
2856
|
+
const: (value) => `z.literal(${value ?? ""})`,
|
|
2875
2857
|
/**
|
|
2876
2858
|
* ISO 8601
|
|
2877
2859
|
*/
|
|
@@ -2915,11 +2897,11 @@ var zodKeywordMapper = {
|
|
|
2915
2897
|
uuid: () => ".uuid()",
|
|
2916
2898
|
url: () => ".url()",
|
|
2917
2899
|
strict: () => ".strict()",
|
|
2918
|
-
default: (value) => `.default(${
|
|
2919
|
-
and: (items = []) =>
|
|
2900
|
+
default: (value) => `.default(${value ?? ""})`,
|
|
2901
|
+
and: (items = []) => items?.map((item) => `.and(${item})`).join(""),
|
|
2920
2902
|
describe: (value = "") => `.describe(${value})`,
|
|
2921
|
-
min: (value) => `.min(${
|
|
2922
|
-
max: (value) => `.max(${
|
|
2903
|
+
min: (value) => `.min(${value ?? ""})`,
|
|
2904
|
+
max: (value) => `.max(${value ?? ""})`,
|
|
2923
2905
|
optional: () => ".optional()",
|
|
2924
2906
|
matches: (value = "") => `.regex(${value})`,
|
|
2925
2907
|
email: () => ".email()",
|
|
@@ -2938,41 +2920,41 @@ var zodKeywordMapper = {
|
|
|
2938
2920
|
};
|
|
2939
2921
|
function sort(items) {
|
|
2940
2922
|
const order = [
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2923
|
+
pluginOas.schemaKeywords.string,
|
|
2924
|
+
pluginOas.schemaKeywords.datetime,
|
|
2925
|
+
pluginOas.schemaKeywords.date,
|
|
2926
|
+
pluginOas.schemaKeywords.time,
|
|
2927
|
+
pluginOas.schemaKeywords.tuple,
|
|
2928
|
+
pluginOas.schemaKeywords.number,
|
|
2929
|
+
pluginOas.schemaKeywords.object,
|
|
2930
|
+
pluginOas.schemaKeywords.enum,
|
|
2931
|
+
pluginOas.schemaKeywords.url,
|
|
2932
|
+
pluginOas.schemaKeywords.email,
|
|
2933
|
+
pluginOas.schemaKeywords.firstName,
|
|
2934
|
+
pluginOas.schemaKeywords.lastName,
|
|
2935
|
+
pluginOas.schemaKeywords.password,
|
|
2936
|
+
pluginOas.schemaKeywords.matches,
|
|
2937
|
+
pluginOas.schemaKeywords.uuid,
|
|
2938
|
+
pluginOas.schemaKeywords.min,
|
|
2939
|
+
pluginOas.schemaKeywords.max,
|
|
2940
|
+
pluginOas.schemaKeywords.default,
|
|
2941
|
+
pluginOas.schemaKeywords.describe,
|
|
2942
|
+
pluginOas.schemaKeywords.optional,
|
|
2943
|
+
pluginOas.schemaKeywords.nullable,
|
|
2944
|
+
pluginOas.schemaKeywords.nullish,
|
|
2945
|
+
pluginOas.schemaKeywords.null
|
|
2964
2946
|
];
|
|
2965
2947
|
if (!items) {
|
|
2966
2948
|
return [];
|
|
2967
2949
|
}
|
|
2968
|
-
return
|
|
2950
|
+
return transformers4__default.default.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
|
|
2969
2951
|
}
|
|
2970
2952
|
function parse2(parent, current, options) {
|
|
2971
2953
|
const value = zodKeywordMapper[current.keyword];
|
|
2972
2954
|
if (!value) {
|
|
2973
2955
|
return void 0;
|
|
2974
2956
|
}
|
|
2975
|
-
if (
|
|
2957
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.union)) {
|
|
2976
2958
|
if (Array.isArray(current.args) && current.args.length === 1) {
|
|
2977
2959
|
return parse2(parent, current.args[0], options);
|
|
2978
2960
|
}
|
|
@@ -2983,27 +2965,27 @@ function parse2(parent, current, options) {
|
|
|
2983
2965
|
sort(current.args).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
2984
2966
|
);
|
|
2985
2967
|
}
|
|
2986
|
-
if (
|
|
2968
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.and)) {
|
|
2987
2969
|
const items = sort(current.args).filter((schema) => {
|
|
2988
|
-
return ![
|
|
2970
|
+
return ![pluginOas.schemaKeywords.optional, pluginOas.schemaKeywords.describe].includes(schema.keyword);
|
|
2989
2971
|
}).map((schema) => parse2(current, schema, options)).filter(Boolean);
|
|
2990
2972
|
return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
|
|
2991
2973
|
}
|
|
2992
|
-
if (
|
|
2974
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.array)) {
|
|
2993
2975
|
return zodKeywordMapper.array(
|
|
2994
2976
|
sort(current.args.items).map((schemas) => parse2(current, schemas, options)).filter(Boolean),
|
|
2995
2977
|
current.args.min,
|
|
2996
2978
|
current.args.max
|
|
2997
2979
|
);
|
|
2998
2980
|
}
|
|
2999
|
-
if (
|
|
2981
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.enum)) {
|
|
3000
2982
|
if (current.args.asConst) {
|
|
3001
2983
|
return zodKeywordMapper.union(
|
|
3002
2984
|
current.args.items.map((schema) => {
|
|
3003
2985
|
return parse2(
|
|
3004
2986
|
current,
|
|
3005
2987
|
{
|
|
3006
|
-
keyword:
|
|
2988
|
+
keyword: pluginOas.schemaKeywords.const,
|
|
3007
2989
|
args: schema
|
|
3008
2990
|
},
|
|
3009
2991
|
options
|
|
@@ -3014,85 +2996,85 @@ function parse2(parent, current, options) {
|
|
|
3014
2996
|
return zodKeywordMapper.enum(
|
|
3015
2997
|
current.args.items.map((schema) => {
|
|
3016
2998
|
if (schema.format === "number") {
|
|
3017
|
-
return
|
|
2999
|
+
return transformers4__default.default.stringify(schema.value);
|
|
3018
3000
|
}
|
|
3019
|
-
return
|
|
3001
|
+
return transformers4__default.default.stringify(schema.value);
|
|
3020
3002
|
})
|
|
3021
3003
|
);
|
|
3022
3004
|
}
|
|
3023
|
-
if (
|
|
3024
|
-
return zodKeywordMapper.ref(
|
|
3005
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.ref)) {
|
|
3006
|
+
return zodKeywordMapper.ref(current.args?.name);
|
|
3025
3007
|
}
|
|
3026
|
-
if (
|
|
3027
|
-
const properties = Object.entries(
|
|
3008
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.object)) {
|
|
3009
|
+
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
3028
3010
|
const schema = item[1];
|
|
3029
3011
|
return schema && typeof schema.map === "function";
|
|
3030
3012
|
}).map(([name, schemas]) => {
|
|
3031
|
-
const nameSchema = schemas.find((schema) => schema.keyword ===
|
|
3032
|
-
const mappedName =
|
|
3033
|
-
if (
|
|
3034
|
-
return `"${name}": ${
|
|
3013
|
+
const nameSchema = schemas.find((schema) => schema.keyword === pluginOas.schemaKeywords.name);
|
|
3014
|
+
const mappedName = nameSchema?.args || name;
|
|
3015
|
+
if (options.mapper?.[mappedName]) {
|
|
3016
|
+
return `"${name}": ${options.mapper?.[mappedName]}`;
|
|
3035
3017
|
}
|
|
3036
3018
|
return `"${name}": ${sort(schemas).map((schema, array) => {
|
|
3037
3019
|
return parse2(current, schema, options);
|
|
3038
3020
|
}).filter(Boolean).join("")}`;
|
|
3039
3021
|
}).join(",");
|
|
3040
|
-
const additionalProperties =
|
|
3022
|
+
const additionalProperties = current.args?.additionalProperties?.length ? current.args.additionalProperties.map((schema) => parse2(current, schema, options)).filter(Boolean).at(0) : void 0;
|
|
3041
3023
|
const text = [
|
|
3042
3024
|
zodKeywordMapper.object(properties),
|
|
3043
|
-
|
|
3025
|
+
current.args?.strict ? zodKeywordMapper.strict() : void 0,
|
|
3044
3026
|
additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0
|
|
3045
3027
|
].filter(Boolean);
|
|
3046
3028
|
return text.join("");
|
|
3047
3029
|
}
|
|
3048
|
-
if (
|
|
3030
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.tuple)) {
|
|
3049
3031
|
return zodKeywordMapper.tuple(
|
|
3050
3032
|
sort(current.args.items).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
3051
3033
|
);
|
|
3052
3034
|
}
|
|
3053
|
-
if (
|
|
3035
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.const)) {
|
|
3054
3036
|
if (current.args.format === "number" && current.args.value !== void 0) {
|
|
3055
|
-
return zodKeywordMapper.const(Number.parseInt(
|
|
3037
|
+
return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
|
|
3056
3038
|
}
|
|
3057
|
-
return zodKeywordMapper.const(
|
|
3039
|
+
return zodKeywordMapper.const(transformers4__default.default.stringify(current.args.value));
|
|
3058
3040
|
}
|
|
3059
|
-
if (
|
|
3041
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.matches)) {
|
|
3060
3042
|
if (current.args) {
|
|
3061
|
-
return zodKeywordMapper.matches(
|
|
3043
|
+
return zodKeywordMapper.matches(transformers4__default.default.toRegExpString(current.args));
|
|
3062
3044
|
}
|
|
3063
3045
|
}
|
|
3064
|
-
if (
|
|
3046
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.default)) {
|
|
3065
3047
|
if (current.args) {
|
|
3066
3048
|
return zodKeywordMapper.default(current.args);
|
|
3067
3049
|
}
|
|
3068
3050
|
}
|
|
3069
|
-
if (
|
|
3051
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.describe)) {
|
|
3070
3052
|
if (current.args) {
|
|
3071
|
-
return zodKeywordMapper.describe(
|
|
3053
|
+
return zodKeywordMapper.describe(transformers4__default.default.stringify(current.args.toString()));
|
|
3072
3054
|
}
|
|
3073
3055
|
}
|
|
3074
|
-
if (
|
|
3056
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.string)) {
|
|
3075
3057
|
return zodKeywordMapper.string(options.coercion);
|
|
3076
3058
|
}
|
|
3077
|
-
if (
|
|
3059
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.number)) {
|
|
3078
3060
|
return zodKeywordMapper.number(options.coercion);
|
|
3079
3061
|
}
|
|
3080
|
-
if (
|
|
3062
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.integer)) {
|
|
3081
3063
|
return zodKeywordMapper.integer(options.coercion);
|
|
3082
3064
|
}
|
|
3083
|
-
if (
|
|
3065
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.min)) {
|
|
3084
3066
|
return zodKeywordMapper.min(current.args);
|
|
3085
3067
|
}
|
|
3086
|
-
if (
|
|
3068
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.max)) {
|
|
3087
3069
|
return zodKeywordMapper.max(current.args);
|
|
3088
3070
|
}
|
|
3089
|
-
if (
|
|
3071
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.datetime)) {
|
|
3090
3072
|
return zodKeywordMapper.datetime(current.args.offset, current.args.local);
|
|
3091
3073
|
}
|
|
3092
|
-
if (
|
|
3074
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.date)) {
|
|
3093
3075
|
return zodKeywordMapper.date(current.args.type, options.coercion);
|
|
3094
3076
|
}
|
|
3095
|
-
if (
|
|
3077
|
+
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.time)) {
|
|
3096
3078
|
return zodKeywordMapper.time(current.args.type, options.coercion);
|
|
3097
3079
|
}
|
|
3098
3080
|
if (current.keyword in zodKeywordMapper && "args" in current) {
|
|
@@ -3108,33 +3090,22 @@ function parse2(parent, current, options) {
|
|
|
3108
3090
|
// src/plugin.ts
|
|
3109
3091
|
init_cjs_shims();
|
|
3110
3092
|
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
3093
|
// src/SchemaGenerator.tsx
|
|
3117
3094
|
init_cjs_shims();
|
|
3118
3095
|
|
|
3119
|
-
|
|
3120
3096
|
// src/components/OperationSchema.tsx
|
|
3121
3097
|
init_cjs_shims();
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
3098
|
function OperationSchema2({ description, keysToOmit }) {
|
|
3128
|
-
return /* @__PURE__ */
|
|
3099
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
3129
3100
|
}
|
|
3130
3101
|
OperationSchema2.File = function({}) {
|
|
3131
|
-
const { pluginManager, plugin, mode } =
|
|
3132
|
-
const { getSchemas, getFile } =
|
|
3133
|
-
const oas =
|
|
3134
|
-
const operation =
|
|
3102
|
+
const { pluginManager, plugin, mode } = react.useApp();
|
|
3103
|
+
const { getSchemas, getFile } = hooks.useOperationManager();
|
|
3104
|
+
const oas = hooks.useOas();
|
|
3105
|
+
const operation = hooks.useOperation();
|
|
3135
3106
|
const file = getFile(operation);
|
|
3136
3107
|
const schemas = getSchemas(operation);
|
|
3137
|
-
const generator = new
|
|
3108
|
+
const generator = new pluginOas.SchemaGenerator(plugin.options, {
|
|
3138
3109
|
oas,
|
|
3139
3110
|
plugin,
|
|
3140
3111
|
pluginManager,
|
|
@@ -3143,28 +3114,24 @@ OperationSchema2.File = function({}) {
|
|
|
3143
3114
|
});
|
|
3144
3115
|
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
3145
3116
|
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
3146
|
-
const required = Array.isArray(
|
|
3117
|
+
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
3147
3118
|
const optional = !required && !!name.includes("Params");
|
|
3148
3119
|
const tree = generator.parse({ schema, name });
|
|
3149
|
-
return /* @__PURE__ */
|
|
3150
|
-
mode === "split" && /* @__PURE__ */
|
|
3151
|
-
/* @__PURE__ */
|
|
3120
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: pluginOas.schemaKeywords.optional } : void 0].filter(Boolean), children: [
|
|
3121
|
+
mode === "split" && /* @__PURE__ */ jsxRuntime.jsx(components.Oas.Schema.Imports, { isTypeOnly: false }),
|
|
3122
|
+
/* @__PURE__ */ jsxRuntime.jsx(OperationSchema2, { description, keysToOmit })
|
|
3152
3123
|
] }, i);
|
|
3153
3124
|
};
|
|
3154
|
-
return /* @__PURE__ */
|
|
3155
|
-
/* @__PURE__ */
|
|
3125
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3126
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
3156
3127
|
items.map(mapItem)
|
|
3157
3128
|
] });
|
|
3158
3129
|
};
|
|
3159
3130
|
|
|
3160
3131
|
// src/components/Operations.tsx
|
|
3161
3132
|
init_cjs_shims();
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
3133
|
function Template2({ operationsName, pathsName, operations }) {
|
|
3167
|
-
const { groupSchemasByName } =
|
|
3134
|
+
const { groupSchemasByName } = hooks.useOperationManager();
|
|
3168
3135
|
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
3169
3136
|
const operationsJSON = transformedOperations.reduce(
|
|
3170
3137
|
(prev, acc) => {
|
|
@@ -3183,9 +3150,9 @@ function Template2({ operationsName, pathsName, operations }) {
|
|
|
3183
3150
|
},
|
|
3184
3151
|
{}
|
|
3185
3152
|
);
|
|
3186
|
-
return /* @__PURE__ */
|
|
3187
|
-
/* @__PURE__ */
|
|
3188
|
-
/* @__PURE__ */
|
|
3153
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3154
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: operationsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Const, { export: true, name: operationsName, asConst: true, children: `{${transformers4__default.default.stringifyObject(operationsJSON)}}` }) }),
|
|
3155
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: pathsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Const, { export: true, name: pathsName, asConst: true, children: `{${transformers4__default.default.stringifyObject(pathsJSON)}}` }) })
|
|
3189
3156
|
] });
|
|
3190
3157
|
}
|
|
3191
3158
|
function RootTemplate({ children }) {
|
|
@@ -3196,55 +3163,52 @@ function RootTemplate({ children }) {
|
|
|
3196
3163
|
key: pluginKey,
|
|
3197
3164
|
options: { extName }
|
|
3198
3165
|
}
|
|
3199
|
-
} =
|
|
3200
|
-
const { getFile } =
|
|
3201
|
-
const operations =
|
|
3202
|
-
const { groupSchemasByName } =
|
|
3166
|
+
} = react.useApp();
|
|
3167
|
+
const { getFile } = hooks.useOperationManager();
|
|
3168
|
+
const operations = hooks.useOperations();
|
|
3169
|
+
const { groupSchemasByName } = hooks.useOperationManager();
|
|
3203
3170
|
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
3204
3171
|
const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
|
|
3205
3172
|
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
3206
3173
|
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
3207
|
-
return /* @__PURE__ */
|
|
3174
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
3208
3175
|
}).filter(Boolean);
|
|
3209
|
-
return /* @__PURE__ */
|
|
3176
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3210
3177
|
mode === "split" && imports,
|
|
3211
3178
|
children
|
|
3212
3179
|
] });
|
|
3213
3180
|
}
|
|
3214
3181
|
var defaultTemplates2 = { default: Template2, root: RootTemplate };
|
|
3215
3182
|
function Operations({ Template: Template3 = defaultTemplates2.default }) {
|
|
3216
|
-
const operations =
|
|
3217
|
-
return /* @__PURE__ */
|
|
3183
|
+
const operations = hooks.useOperations();
|
|
3184
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Template3, { operationsName: "operations", pathsName: "paths", operations });
|
|
3218
3185
|
}
|
|
3219
3186
|
Operations.File = function(props) {
|
|
3220
3187
|
const templates = { ...defaultTemplates2, ...props.templates };
|
|
3221
3188
|
const Template3 = templates.default;
|
|
3222
3189
|
const RootTemplate2 = templates.root;
|
|
3223
|
-
return /* @__PURE__ */
|
|
3190
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RootTemplate2, { children: /* @__PURE__ */ jsxRuntime.jsx(Operations, { Template: Template3 }) });
|
|
3224
3191
|
};
|
|
3225
3192
|
Operations.templates = defaultTemplates2;
|
|
3226
|
-
|
|
3227
|
-
// src/SchemaGenerator.tsx
|
|
3228
|
-
|
|
3229
|
-
var zodParser = _pluginoas.createReactGenerator.call(void 0, {
|
|
3193
|
+
var zodParser = pluginOas.createReactGenerator({
|
|
3230
3194
|
name: "plugin-zod",
|
|
3231
3195
|
Operations({ options }) {
|
|
3232
3196
|
if (!options.templates.operations) {
|
|
3233
3197
|
return null;
|
|
3234
3198
|
}
|
|
3235
|
-
return /* @__PURE__ */
|
|
3199
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Operations.File, { templates: options.templates.operations });
|
|
3236
3200
|
},
|
|
3237
3201
|
Operation() {
|
|
3238
|
-
return /* @__PURE__ */
|
|
3202
|
+
return /* @__PURE__ */ jsxRuntime.jsx(OperationSchema2.File, {});
|
|
3239
3203
|
},
|
|
3240
3204
|
Schema({ schema, name }) {
|
|
3241
|
-
return /* @__PURE__ */
|
|
3205
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Schema2.File, {});
|
|
3242
3206
|
}
|
|
3243
3207
|
});
|
|
3244
3208
|
|
|
3245
3209
|
// src/plugin.ts
|
|
3246
3210
|
var pluginZodName = "plugin-zod";
|
|
3247
|
-
var pluginZod =
|
|
3211
|
+
var pluginZod = core.createPlugin((options) => {
|
|
3248
3212
|
const {
|
|
3249
3213
|
output = { path: "zod" },
|
|
3250
3214
|
group,
|
|
@@ -3261,7 +3225,7 @@ var pluginZod = _core.createPlugin.call(void 0, (options) => {
|
|
|
3261
3225
|
importPath = "zod",
|
|
3262
3226
|
coercion = false
|
|
3263
3227
|
} = options;
|
|
3264
|
-
const template =
|
|
3228
|
+
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
3265
3229
|
return {
|
|
3266
3230
|
name: pluginZodName,
|
|
3267
3231
|
output: {
|
|
@@ -3286,38 +3250,38 @@ var pluginZod = _core.createPlugin.call(void 0, (options) => {
|
|
|
3286
3250
|
...templates
|
|
3287
3251
|
}
|
|
3288
3252
|
},
|
|
3289
|
-
pre: [
|
|
3253
|
+
pre: [pluginOas.pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
|
|
3290
3254
|
resolvePath(baseName, pathMode, options2) {
|
|
3291
|
-
const root =
|
|
3292
|
-
const mode =
|
|
3255
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
3256
|
+
const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
3293
3257
|
if (mode === "single") {
|
|
3294
|
-
return
|
|
3258
|
+
return path__default.default.resolve(root, output.path);
|
|
3295
3259
|
}
|
|
3296
|
-
if (
|
|
3297
|
-
const tag =
|
|
3298
|
-
return
|
|
3260
|
+
if (options2?.tag && group?.type === "tag") {
|
|
3261
|
+
const tag = transformers4.camelCase(options2.tag);
|
|
3262
|
+
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
3299
3263
|
}
|
|
3300
|
-
return
|
|
3264
|
+
return path__default.default.resolve(root, output.path, baseName);
|
|
3301
3265
|
},
|
|
3302
3266
|
resolveName(name, type) {
|
|
3303
|
-
let resolvedName =
|
|
3267
|
+
let resolvedName = transformers4.camelCase(name, {
|
|
3304
3268
|
suffix: type ? "schema" : void 0,
|
|
3305
3269
|
isFile: type === "file"
|
|
3306
3270
|
});
|
|
3307
3271
|
if (type === "type") {
|
|
3308
|
-
resolvedName =
|
|
3272
|
+
resolvedName = transformers4.pascalCase(resolvedName);
|
|
3309
3273
|
}
|
|
3310
3274
|
if (type) {
|
|
3311
|
-
return
|
|
3275
|
+
return transformers7?.name?.(resolvedName, type) || resolvedName;
|
|
3312
3276
|
}
|
|
3313
3277
|
return resolvedName;
|
|
3314
3278
|
},
|
|
3315
3279
|
async buildStart() {
|
|
3316
|
-
const [swaggerPlugin] =
|
|
3280
|
+
const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
|
|
3317
3281
|
const oas = await swaggerPlugin.context.getOas();
|
|
3318
|
-
const root =
|
|
3319
|
-
const mode =
|
|
3320
|
-
const schemaGenerator = new
|
|
3282
|
+
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
3283
|
+
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
3284
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(this.plugin.options, {
|
|
3321
3285
|
oas,
|
|
3322
3286
|
pluginManager: this.pluginManager,
|
|
3323
3287
|
plugin: this.plugin,
|
|
@@ -3329,7 +3293,7 @@ var pluginZod = _core.createPlugin.call(void 0, (options) => {
|
|
|
3329
3293
|
});
|
|
3330
3294
|
const schemaFiles = await schemaGenerator.build(zodParser);
|
|
3331
3295
|
await this.addFile(...schemaFiles);
|
|
3332
|
-
const operationGenerator = new
|
|
3296
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
3333
3297
|
oas,
|
|
3334
3298
|
pluginManager: this.pluginManager,
|
|
3335
3299
|
plugin: this.plugin,
|
|
@@ -3356,18 +3320,15 @@ var pluginZod = _core.createPlugin.call(void 0, (options) => {
|
|
|
3356
3320
|
}
|
|
3357
3321
|
};
|
|
3358
3322
|
});
|
|
3359
|
-
|
|
3360
|
-
// src/components/Schema.tsx
|
|
3361
|
-
|
|
3362
3323
|
function Schema2(props) {
|
|
3363
3324
|
const { keysToOmit, withTypeAnnotation, description } = props;
|
|
3364
|
-
const { tree, name } =
|
|
3325
|
+
const { tree, name } = hooks.useSchema();
|
|
3365
3326
|
const {
|
|
3366
3327
|
pluginManager,
|
|
3367
3328
|
plugin: {
|
|
3368
3329
|
options: { mapper, typedSchema, coercion }
|
|
3369
3330
|
}
|
|
3370
|
-
} =
|
|
3331
|
+
} = react.useApp();
|
|
3371
3332
|
const resolvedName = pluginManager.resolveName({
|
|
3372
3333
|
name,
|
|
3373
3334
|
pluginKey: [pluginZodName],
|
|
@@ -3384,43 +3345,43 @@ function Schema2(props) {
|
|
|
3384
3345
|
type: "type"
|
|
3385
3346
|
});
|
|
3386
3347
|
if (!tree.length) {
|
|
3387
|
-
return /* @__PURE__ */
|
|
3388
|
-
|
|
3348
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3349
|
+
react.Const,
|
|
3389
3350
|
{
|
|
3390
3351
|
name: resolvedName,
|
|
3391
3352
|
export: true,
|
|
3392
3353
|
JSDoc: {
|
|
3393
|
-
comments: [description ? `@description ${
|
|
3354
|
+
comments: [description ? `@description ${transformers4__default.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
3394
3355
|
},
|
|
3395
3356
|
children: "undefined"
|
|
3396
3357
|
}
|
|
3397
3358
|
) });
|
|
3398
3359
|
}
|
|
3399
|
-
const hasTuple = tree.some((item) =>
|
|
3360
|
+
const hasTuple = tree.some((item) => pluginOas.isKeyword(item, pluginOas.schemaKeywords.tuple));
|
|
3400
3361
|
const output = sort(tree).filter((item) => {
|
|
3401
|
-
if (hasTuple && (
|
|
3362
|
+
if (hasTuple && (pluginOas.isKeyword(item, pluginOas.schemaKeywords.min) || pluginOas.isKeyword(item, pluginOas.schemaKeywords.max))) {
|
|
3402
3363
|
return false;
|
|
3403
3364
|
}
|
|
3404
3365
|
return true;
|
|
3405
3366
|
}).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
|
|
3406
3367
|
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
3407
|
-
return /* @__PURE__ */
|
|
3408
|
-
/* @__PURE__ */
|
|
3409
|
-
|
|
3368
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3369
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3370
|
+
react.Const,
|
|
3410
3371
|
{
|
|
3411
3372
|
export: true,
|
|
3412
3373
|
name: resolvedName,
|
|
3413
3374
|
JSDoc: {
|
|
3414
|
-
comments: [description ? `@description ${
|
|
3375
|
+
comments: [description ? `@description ${transformers4__default.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
3415
3376
|
},
|
|
3416
3377
|
children: [
|
|
3417
3378
|
output,
|
|
3418
|
-
|
|
3379
|
+
keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(",")} }))` : void 0,
|
|
3419
3380
|
withTypeAnnotation && typeName ? ` as z.ZodType<${typeName}>` : ""
|
|
3420
3381
|
].filter(Boolean).join("") || ""
|
|
3421
3382
|
}
|
|
3422
3383
|
) }),
|
|
3423
|
-
typedSchema && /* @__PURE__ */
|
|
3384
|
+
typedSchema && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: resolvedTypeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Type, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` }) })
|
|
3424
3385
|
] });
|
|
3425
3386
|
}
|
|
3426
3387
|
Schema2.File = function({}) {
|
|
@@ -3429,12 +3390,12 @@ Schema2.File = function({}) {
|
|
|
3429
3390
|
plugin: {
|
|
3430
3391
|
options: { typed }
|
|
3431
3392
|
}
|
|
3432
|
-
} =
|
|
3433
|
-
const { schema } =
|
|
3393
|
+
} = react.useApp();
|
|
3394
|
+
const { schema } = hooks.useSchema();
|
|
3434
3395
|
const withTypeAnnotation = !!typed;
|
|
3435
|
-
return /* @__PURE__ */
|
|
3436
|
-
/* @__PURE__ */
|
|
3437
|
-
/* @__PURE__ */
|
|
3396
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
3397
|
+
/* @__PURE__ */ jsxRuntime.jsx(Schema2.Imports, {}),
|
|
3398
|
+
/* @__PURE__ */ jsxRuntime.jsx(Schema2, { withTypeAnnotation, description: schema?.description })
|
|
3438
3399
|
] });
|
|
3439
3400
|
};
|
|
3440
3401
|
Schema2.Imports = () => {
|
|
@@ -3443,9 +3404,9 @@ Schema2.Imports = () => {
|
|
|
3443
3404
|
plugin: {
|
|
3444
3405
|
options: { typed, importPath }
|
|
3445
3406
|
}
|
|
3446
|
-
} =
|
|
3447
|
-
const { path: root } =
|
|
3448
|
-
const { name, tree, schema } =
|
|
3407
|
+
} = react.useApp();
|
|
3408
|
+
const { path: root } = react.useFile();
|
|
3409
|
+
const { name, tree, schema } = hooks.useSchema();
|
|
3449
3410
|
const typeName = pluginManager.resolveName({
|
|
3450
3411
|
name,
|
|
3451
3412
|
pluginKey: [pluginTsName],
|
|
@@ -3461,20 +3422,11 @@ Schema2.Imports = () => {
|
|
|
3461
3422
|
pluginKey: [pluginTsName]
|
|
3462
3423
|
});
|
|
3463
3424
|
const withTypeAnnotation = !!typed;
|
|
3464
|
-
return /* @__PURE__ */
|
|
3465
|
-
/* @__PURE__ */
|
|
3466
|
-
withTypeAnnotation && typeName && typePath && /* @__PURE__ */
|
|
3425
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
3426
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: importPath }),
|
|
3427
|
+
withTypeAnnotation && typeName && typePath && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
3467
3428
|
] });
|
|
3468
3429
|
};
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
exports.init_cjs_shims = init_cjs_shims; exports.Schema = Schema2; exports.OperationSchema = OperationSchema2; exports.Operations = Operations; exports.pluginZodName = pluginZodName; exports.pluginZod = pluginZod;
|
|
3478
3430
|
/*! Bundled license information:
|
|
3479
3431
|
|
|
3480
3432
|
react/cjs/react.production.min.js:
|
|
@@ -3499,4 +3451,12 @@ react/cjs/react.development.js:
|
|
|
3499
3451
|
* LICENSE file in the root directory of this source tree.
|
|
3500
3452
|
*)
|
|
3501
3453
|
*/
|
|
3502
|
-
|
|
3454
|
+
|
|
3455
|
+
exports.OperationSchema = OperationSchema2;
|
|
3456
|
+
exports.Operations = Operations;
|
|
3457
|
+
exports.Schema = Schema2;
|
|
3458
|
+
exports.init_cjs_shims = init_cjs_shims;
|
|
3459
|
+
exports.pluginZod = pluginZod;
|
|
3460
|
+
exports.pluginZodName = pluginZodName;
|
|
3461
|
+
//# sourceMappingURL=chunk-WDPKVCXH.cjs.map
|
|
3462
|
+
//# sourceMappingURL=chunk-WDPKVCXH.cjs.map
|