@kubb/plugin-zod 3.0.0-alpha.15 → 3.0.0-alpha.17
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-35K4FTRK.js +367 -0
- package/dist/chunk-35K4FTRK.js.map +1 -0
- package/dist/{chunk-DL4VN2AP.cjs → chunk-HH7DZZUF.cjs} +271 -710
- package/dist/chunk-HH7DZZUF.cjs.map +1 -0
- package/dist/{chunk-BDYQNKJC.js → chunk-ORFIAMY6.js} +252 -689
- package/dist/chunk-ORFIAMY6.js.map +1 -0
- package/dist/chunk-Q7F7N57F.cjs +377 -0
- package/dist/chunk-Q7F7N57F.cjs.map +1 -0
- package/dist/components.cjs +5 -10
- package/dist/components.cjs.map +1 -1
- package/dist/components.d.cts +21 -19
- package/dist/components.d.ts +21 -19
- package/dist/components.js +1 -5
- package/dist/components.js.map +1 -1
- package/dist/generators.cjs +17 -0
- package/dist/generators.cjs.map +1 -0
- package/dist/generators.d.cts +11 -0
- package/dist/generators.d.ts +11 -0
- package/dist/generators.js +4 -0
- package/dist/generators.js.map +1 -0
- package/dist/index.cjs +5 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -137
- package/dist/index.d.ts +5 -137
- package/dist/index.js +2 -2
- package/dist/types-29VBUXHk.d.cts +126 -0
- package/dist/types-29VBUXHk.d.ts +126 -0
- package/package.json +19 -17
- package/src/components/Operations.tsx +12 -98
- package/src/components/Zod.tsx +66 -0
- package/src/components/index.ts +1 -2
- package/src/generators/__snapshots__/anyof.ts +3 -0
- package/src/generators/__snapshots__/createPet.ts +15 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeAny.ts +13 -0
- package/src/generators/__snapshots__/createPetWithUnknownTypeUnknown.ts +15 -0
- package/src/generators/__snapshots__/deletePet.ts +3 -0
- package/src/generators/__snapshots__/enumNamesType.ts +3 -0
- package/src/generators/__snapshots__/enumNullable.ts +3 -0
- package/src/generators/__snapshots__/enumVarNamesType.ts +3 -0
- package/src/generators/__snapshots__/example.ts +3 -0
- package/src/generators/__snapshots__/getPets.ts +18 -0
- package/src/generators/__snapshots__/mixedValueTypeConst.ts +6 -0
- package/src/generators/__snapshots__/nullableString.ts +3 -0
- package/src/generators/__snapshots__/nullableStringUuid.ts +3 -0
- package/src/generators/__snapshots__/nullableStringWithAnyOf.ts +3 -0
- package/src/generators/__snapshots__/numberValueConst.ts +6 -0
- package/src/generators/__snapshots__/oneof.ts +3 -0
- package/src/generators/__snapshots__/operations.ts +60 -0
- package/src/generators/__snapshots__/optionalPetInfer.ts +5 -0
- package/src/generators/__snapshots__/optionalPetTyped.ts +3 -0
- package/src/generators/__snapshots__/order.ts +10 -0
- package/src/generators/__snapshots__/orderDateTyeString.ts +10 -0
- package/src/generators/__snapshots__/orderDateTypeFalse.ts +10 -0
- package/src/generators/__snapshots__/orderDateTypeString.ts +10 -0
- package/src/generators/__snapshots__/pet.ts +3 -0
- package/src/generators/__snapshots__/petArray.ts +10 -0
- package/src/generators/__snapshots__/petCoercion.ts +8 -0
- package/src/generators/__snapshots__/petTupleObject.ts +6 -0
- package/src/generators/__snapshots__/petWithMapper.ts +3 -0
- package/src/generators/__snapshots__/pets.ts +3 -0
- package/src/generators/__snapshots__/recursive.ts +3 -0
- package/src/generators/__snapshots__/showPetById.ts +21 -0
- package/src/generators/__snapshots__/stringValueConst.ts +6 -0
- package/src/generators/__snapshots__/uuidSchema.ts +3 -0
- package/src/generators/index.ts +2 -0
- package/src/generators/operationsGenerator.tsx +34 -0
- package/src/generators/zodGenerator.tsx +114 -0
- package/src/plugin.ts +8 -11
- package/src/types.ts +33 -42
- package/dist/Operations-BG26e_MW.d.cts +0 -47
- package/dist/Operations-BG26e_MW.d.ts +0 -47
- package/dist/chunk-BDYQNKJC.js.map +0 -1
- package/dist/chunk-DL4VN2AP.cjs.map +0 -1
- package/src/SchemaGenerator.tsx +0 -22
- package/src/components/OperationSchema.tsx +0 -60
- package/src/components/Schema.tsx +0 -166
- package/src/components/__snapshots__/operations.ts +0 -53
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkQ7F7N57F_cjs = require('./chunk-Q7F7N57F.cjs');
|
|
4
|
+
var pluginOas = require('@kubb/plugin-oas');
|
|
3
5
|
var components = require('@kubb/plugin-oas/components');
|
|
4
|
-
var
|
|
6
|
+
var hooks = require('@kubb/plugin-oas/hooks');
|
|
5
7
|
var path = require('path');
|
|
6
8
|
var core = require('@kubb/core');
|
|
7
|
-
var
|
|
9
|
+
var transformers2 = require('@kubb/core/transformers');
|
|
8
10
|
var utils = require('@kubb/core/utils');
|
|
9
|
-
var
|
|
10
|
-
var hooks = require('@kubb/plugin-oas/hooks');
|
|
11
|
+
var react = require('@kubb/react');
|
|
11
12
|
var jsxRuntime = require('@kubb/react/jsx-runtime');
|
|
12
13
|
var parserTs = require('@kubb/parser-ts');
|
|
13
14
|
var factory = require('@kubb/parser-ts/factory');
|
|
@@ -33,48 +34,13 @@ function _interopNamespace(e) {
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
36
|
-
var
|
|
37
|
+
var transformers2__default = /*#__PURE__*/_interopDefault(transformers2);
|
|
37
38
|
var factory__namespace = /*#__PURE__*/_interopNamespace(factory);
|
|
38
39
|
|
|
39
|
-
var __create = Object.create;
|
|
40
|
-
var __defProp = Object.defineProperty;
|
|
41
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
42
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
43
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
44
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
45
|
-
var __esm = (fn, res) => function __init() {
|
|
46
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
47
|
-
};
|
|
48
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
49
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
50
|
-
};
|
|
51
|
-
var __copyProps = (to, from, except, desc) => {
|
|
52
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
53
|
-
for (let key of __getOwnPropNames(from))
|
|
54
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
55
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
56
|
-
}
|
|
57
|
-
return to;
|
|
58
|
-
};
|
|
59
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
60
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
61
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
62
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
63
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
64
|
-
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
65
|
-
mod
|
|
66
|
-
));
|
|
67
|
-
|
|
68
|
-
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.4__@swc+core@1.7.22_jiti@1.21.6__fpzbqwwca26qndurg5tnw6xyfi/node_modules/tsup/assets/cjs_shims.js
|
|
69
|
-
var init_cjs_shims = __esm({
|
|
70
|
-
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.4__@swc+core@1.7.22_jiti@1.21.6__fpzbqwwca26qndurg5tnw6xyfi/node_modules/tsup/assets/cjs_shims.js"() {
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
40
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
|
|
75
|
-
var require_react_production_min = __commonJS({
|
|
41
|
+
var require_react_production_min = chunkQ7F7N57F_cjs.__commonJS({
|
|
76
42
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js"(exports) {
|
|
77
|
-
init_cjs_shims();
|
|
43
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
78
44
|
var l = Symbol.for("react.element");
|
|
79
45
|
var n = Symbol.for("react.portal");
|
|
80
46
|
var p = Symbol.for("react.fragment");
|
|
@@ -345,9 +311,9 @@ var require_react_production_min = __commonJS({
|
|
|
345
311
|
});
|
|
346
312
|
|
|
347
313
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js
|
|
348
|
-
var require_react_development = __commonJS({
|
|
314
|
+
var require_react_development = chunkQ7F7N57F_cjs.__commonJS({
|
|
349
315
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js"(exports, module) {
|
|
350
|
-
init_cjs_shims();
|
|
316
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
351
317
|
if (process.env.NODE_ENV !== "production") {
|
|
352
318
|
(function() {
|
|
353
319
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
@@ -2218,9 +2184,9 @@ var require_react_development = __commonJS({
|
|
|
2218
2184
|
});
|
|
2219
2185
|
|
|
2220
2186
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js
|
|
2221
|
-
var require_react = __commonJS({
|
|
2187
|
+
var require_react = chunkQ7F7N57F_cjs.__commonJS({
|
|
2222
2188
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js"(exports, module) {
|
|
2223
|
-
init_cjs_shims();
|
|
2189
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2224
2190
|
if (process.env.NODE_ENV === "production") {
|
|
2225
2191
|
module.exports = require_react_production_min();
|
|
2226
2192
|
} else {
|
|
@@ -2229,58 +2195,43 @@ var require_react = __commonJS({
|
|
|
2229
2195
|
}
|
|
2230
2196
|
});
|
|
2231
2197
|
|
|
2232
|
-
// src/
|
|
2233
|
-
init_cjs_shims();
|
|
2198
|
+
// src/generators/index.ts
|
|
2199
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2200
|
+
|
|
2201
|
+
// src/generators/zodGenerator.tsx
|
|
2202
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2234
2203
|
|
|
2235
2204
|
// ../plugin-ts/src/index.ts
|
|
2236
|
-
init_cjs_shims();
|
|
2205
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2237
2206
|
|
|
2238
2207
|
// ../plugin-ts/src/plugin.ts
|
|
2239
|
-
init_cjs_shims();
|
|
2208
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2209
|
+
|
|
2210
|
+
// ../plugin-ts/src/generators/index.ts
|
|
2211
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2212
|
+
|
|
2213
|
+
// ../plugin-ts/src/generators/typeGenerator.tsx
|
|
2214
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2240
2215
|
|
|
2241
|
-
// ../plugin-ts/src/
|
|
2242
|
-
init_cjs_shims();
|
|
2216
|
+
// ../plugin-ts/src/components/index.ts
|
|
2217
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2243
2218
|
|
|
2244
2219
|
// ../plugin-ts/src/components/OasType.tsx
|
|
2245
|
-
init_cjs_shims();
|
|
2246
|
-
function
|
|
2220
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2221
|
+
function OasType({ name, typeName, api }) {
|
|
2247
2222
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
2248
2223
|
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2249
2224
|
/* @__PURE__ */ jsxRuntime.jsx("br", {}),
|
|
2250
2225
|
/* @__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}>` }) })
|
|
2251
2226
|
] });
|
|
2252
2227
|
}
|
|
2253
|
-
var defaultTemplates = { default: Template };
|
|
2254
|
-
function OasType({ name, typeName, Template: Template3 = defaultTemplates.default }) {
|
|
2255
|
-
const oas = hooks.useOas();
|
|
2256
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Template3, { name, typeName, api: oas.api });
|
|
2257
|
-
}
|
|
2258
|
-
OasType.File = function({ name, typeName, templates = defaultTemplates }) {
|
|
2259
|
-
const {
|
|
2260
|
-
pluginManager,
|
|
2261
|
-
plugin: { key: pluginKey }
|
|
2262
|
-
} = react.useApp();
|
|
2263
|
-
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
|
|
2264
|
-
const Template3 = templates.default;
|
|
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 })
|
|
2268
|
-
] });
|
|
2269
|
-
};
|
|
2270
|
-
OasType.templates = defaultTemplates;
|
|
2271
|
-
|
|
2272
|
-
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
2273
|
-
init_cjs_shims();
|
|
2274
|
-
|
|
2275
|
-
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
2276
|
-
init_cjs_shims();
|
|
2277
2228
|
|
|
2278
|
-
// ../plugin-ts/src/components/
|
|
2279
|
-
init_cjs_shims();
|
|
2280
|
-
var import_react3 = __toESM(require_react());
|
|
2229
|
+
// ../plugin-ts/src/components/Type.tsx
|
|
2230
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2231
|
+
var import_react3 = chunkQ7F7N57F_cjs.__toESM(require_react(), 1);
|
|
2281
2232
|
|
|
2282
2233
|
// ../plugin-ts/src/parser/index.ts
|
|
2283
|
-
init_cjs_shims();
|
|
2234
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2284
2235
|
var typeKeywordMapper = {
|
|
2285
2236
|
any: () => factory__namespace.keywordTypeNodes.any,
|
|
2286
2237
|
unknown: () => factory__namespace.keywordTypeNodes.unknown,
|
|
@@ -2447,7 +2398,7 @@ function parse(parent, current, options) {
|
|
|
2447
2398
|
return factory__namespace.appendJSDocToNode({
|
|
2448
2399
|
node: propertySignature,
|
|
2449
2400
|
comments: [
|
|
2450
|
-
describeSchema ? `@description ${
|
|
2401
|
+
describeSchema ? `@description ${transformers2__default.default.jsStringEscape(describeSchema.args)}` : void 0,
|
|
2451
2402
|
deprecatedSchema ? "@deprecated" : void 0,
|
|
2452
2403
|
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
|
2453
2404
|
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
|
@@ -2474,28 +2425,7 @@ function parse(parent, current, options) {
|
|
|
2474
2425
|
}
|
|
2475
2426
|
return void 0;
|
|
2476
2427
|
}
|
|
2477
|
-
function
|
|
2478
|
-
const { keysToOmit, description } = props;
|
|
2479
|
-
const { tree, name } = hooks.useSchema();
|
|
2480
|
-
const {
|
|
2481
|
-
pluginManager,
|
|
2482
|
-
plugin: {
|
|
2483
|
-
options: { mapper, enumType, optionalType }
|
|
2484
|
-
}
|
|
2485
|
-
} = react.useApp();
|
|
2486
|
-
if (enumType === "asPascalConst") {
|
|
2487
|
-
pluginManager.logger.emit("warning", `enumType '${enumType}' is deprecated`);
|
|
2488
|
-
}
|
|
2489
|
-
const resolvedName = pluginManager.resolveName({
|
|
2490
|
-
name,
|
|
2491
|
-
pluginKey: [pluginTsName],
|
|
2492
|
-
type: "function"
|
|
2493
|
-
});
|
|
2494
|
-
const typeName = pluginManager.resolveName({
|
|
2495
|
-
name,
|
|
2496
|
-
pluginKey: [pluginTsName],
|
|
2497
|
-
type: "type"
|
|
2498
|
-
});
|
|
2428
|
+
function Type2({ name, typedName, tree, keysToOmit, optionalType, enumType, mapper, description }) {
|
|
2499
2429
|
const typeNodes = [];
|
|
2500
2430
|
if (!tree.length) {
|
|
2501
2431
|
return "";
|
|
@@ -2505,8 +2435,8 @@ function Schema(props) {
|
|
|
2505
2435
|
const isOptional = tree.some((item) => item.keyword === pluginOas.schemaKeywords.optional);
|
|
2506
2436
|
let type = tree.map(
|
|
2507
2437
|
(schema) => parse(void 0, schema, {
|
|
2508
|
-
name
|
|
2509
|
-
typeName,
|
|
2438
|
+
name,
|
|
2439
|
+
typeName: typedName,
|
|
2510
2440
|
description,
|
|
2511
2441
|
keysToOmit,
|
|
2512
2442
|
optionalType,
|
|
@@ -2531,7 +2461,7 @@ function Schema(props) {
|
|
|
2531
2461
|
}
|
|
2532
2462
|
const node = factory__namespace.createTypeAliasDeclaration({
|
|
2533
2463
|
modifiers: [factory__namespace.modifiers.export],
|
|
2534
|
-
name
|
|
2464
|
+
name,
|
|
2535
2465
|
type: keysToOmit?.length ? factory__namespace.createOmitDeclaration({
|
|
2536
2466
|
keys: keysToOmit,
|
|
2537
2467
|
type,
|
|
@@ -2540,59 +2470,36 @@ function Schema(props) {
|
|
|
2540
2470
|
});
|
|
2541
2471
|
const enumSchemas = pluginOas.SchemaGenerator.deepSearch(tree, pluginOas.schemaKeywords.enum);
|
|
2542
2472
|
const enums = enumSchemas.map((enumSchema) => {
|
|
2543
|
-
const name2 = enumType === "asPascalConst" ?
|
|
2544
|
-
const
|
|
2473
|
+
const name2 = enumType === "asPascalConst" ? transformers2__default.default.pascalCase(enumSchema.args.name) : transformers2__default.default.camelCase(enumSchema.args.name);
|
|
2474
|
+
const typeName = enumSchema.args.typeName;
|
|
2545
2475
|
const [nameNode, typeNode] = factory__namespace.createEnumDeclaration({
|
|
2546
2476
|
name: name2,
|
|
2547
|
-
typeName
|
|
2548
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [
|
|
2477
|
+
typeName,
|
|
2478
|
+
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers2__default.default.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
|
|
2549
2479
|
type: enumType
|
|
2550
2480
|
});
|
|
2551
2481
|
return {
|
|
2552
2482
|
nameNode,
|
|
2553
2483
|
typeNode,
|
|
2554
2484
|
name: name2,
|
|
2555
|
-
typeName
|
|
2485
|
+
typeName
|
|
2556
2486
|
};
|
|
2557
2487
|
});
|
|
2558
2488
|
typeNodes.push(
|
|
2559
2489
|
factory__namespace.appendJSDocToNode({
|
|
2560
2490
|
node,
|
|
2561
|
-
comments: [description ? `@description ${
|
|
2491
|
+
comments: [description ? `@description ${transformers2__default.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
2562
2492
|
})
|
|
2563
2493
|
);
|
|
2564
2494
|
return /* @__PURE__ */ jsxRuntime.jsxs(import_react3.Fragment, { children: [
|
|
2565
|
-
enums.map(({ name: name2, nameNode, typeName
|
|
2495
|
+
enums.map(({ name: name2, nameNode, typeName, typeNode }, index) => /* @__PURE__ */ jsxRuntime.jsxs(import_react3.Fragment, { children: [
|
|
2566
2496
|
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:
|
|
2497
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typeName, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: parserTs.print([typeNode]) })
|
|
2568
2498
|
] }, [name2, nameNode].join("-"))),
|
|
2569
|
-
enums.every((item) => item.typeName !==
|
|
2499
|
+
enums.every((item) => item.typeName !== name) && /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: typedName, isTypeOnly: true, isExportable: true, isIndexable: true, children: parserTs.print(typeNodes) })
|
|
2570
2500
|
] });
|
|
2571
2501
|
}
|
|
2572
|
-
|
|
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 }) });
|
|
2576
|
-
};
|
|
2577
|
-
var SchemaGenerator2 = class extends pluginOas.SchemaGenerator {
|
|
2578
|
-
async schema(name, schema, options) {
|
|
2579
|
-
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
2580
|
-
const root = react.createRoot({
|
|
2581
|
-
logger: pluginManager.logger
|
|
2582
|
-
});
|
|
2583
|
-
const tree = this.parse({ schema, name });
|
|
2584
|
-
const Component = () => /* @__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, {}) }) }) });
|
|
2585
|
-
Component.displayName = transformers4.pascalCase(name);
|
|
2586
|
-
root.render(/* @__PURE__ */ jsxRuntime.jsx(Component, {}));
|
|
2587
|
-
return root.files;
|
|
2588
|
-
}
|
|
2589
|
-
};
|
|
2590
|
-
function printCombinedSchema({
|
|
2591
|
-
name,
|
|
2592
|
-
operation,
|
|
2593
|
-
schemas,
|
|
2594
|
-
pluginManager
|
|
2595
|
-
}) {
|
|
2502
|
+
function printCombinedSchema({ name, schemas, pluginManager }) {
|
|
2596
2503
|
const properties = {};
|
|
2597
2504
|
if (schemas.response) {
|
|
2598
2505
|
const identifier = pluginManager.resolveName({
|
|
@@ -2655,7 +2562,7 @@ function printCombinedSchema({
|
|
|
2655
2562
|
return void 0;
|
|
2656
2563
|
}
|
|
2657
2564
|
return factory__namespace.createPropertySignature({
|
|
2658
|
-
name:
|
|
2565
|
+
name: transformers2__default.default.pascalCase(key),
|
|
2659
2566
|
type
|
|
2660
2567
|
});
|
|
2661
2568
|
}).filter(Boolean)
|
|
@@ -2664,60 +2571,101 @@ function printCombinedSchema({
|
|
|
2664
2571
|
});
|
|
2665
2572
|
return parserTs.print([namespaceNode]);
|
|
2666
2573
|
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
}
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
2686
|
-
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
2687
|
-
const tree = generator.parse({ schema, name });
|
|
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 })
|
|
2691
|
-
] }, i);
|
|
2692
|
-
};
|
|
2693
|
-
const combinedSchemaName = operation.method === "get" ? `${factoryName}Query` : `${factoryName}Mutation`;
|
|
2694
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2695
|
-
items.map(mapItem),
|
|
2696
|
-
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2697
|
-
] });
|
|
2698
|
-
};
|
|
2699
|
-
var OperationGenerator = class extends pluginOas.OperationGenerator {
|
|
2700
|
-
async all(operations) {
|
|
2701
|
-
const { oas, pluginManager, plugin, mode } = this.context;
|
|
2702
|
-
const root = react.createRoot({
|
|
2703
|
-
logger: pluginManager.logger
|
|
2574
|
+
var typeGenerator = pluginOas.createReactGenerator({
|
|
2575
|
+
name: "typescript",
|
|
2576
|
+
Operation({ operation, options }) {
|
|
2577
|
+
const { mapper, enumType, optionalType } = options;
|
|
2578
|
+
const { plugin, pluginManager, mode } = react.useApp();
|
|
2579
|
+
const oas = hooks.useOas();
|
|
2580
|
+
const { getSchemas, getFile, getName } = hooks.useOperationManager();
|
|
2581
|
+
const schemaManager = hooks.useSchemaManager();
|
|
2582
|
+
const file = getFile(operation);
|
|
2583
|
+
const schemas = getSchemas(operation);
|
|
2584
|
+
const type = getName(operation, { type: "function", pluginKey: [pluginTsName] });
|
|
2585
|
+
const combinedSchemaName = operation.method === "get" ? `${type}Query` : `${type}Mutation`;
|
|
2586
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(options, {
|
|
2587
|
+
oas,
|
|
2588
|
+
plugin,
|
|
2589
|
+
pluginManager,
|
|
2590
|
+
mode,
|
|
2591
|
+
override: options.override
|
|
2704
2592
|
});
|
|
2705
|
-
const
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2593
|
+
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
2594
|
+
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options2 }, i) => {
|
|
2595
|
+
const tree = schemaGenerator.parse({ schema, name });
|
|
2596
|
+
const imports = schemaManager.getImports(tree);
|
|
2597
|
+
const type2 = {
|
|
2598
|
+
name: schemaManager.getName(name, { type: "type" }),
|
|
2599
|
+
typedName: schemaManager.getName(name, { type: "type" }),
|
|
2600
|
+
file: schemaManager.getFile(options2.operationName || name, { tag: options2.operation?.getTags()[0]?.name })
|
|
2601
|
+
};
|
|
2602
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
|
|
2603
|
+
mode === "split" && imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: file.path, path: imp.path, name: imp.name, isTypeOnly: true }, index)),
|
|
2604
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2605
|
+
Type2,
|
|
2606
|
+
{
|
|
2607
|
+
name: type2.name,
|
|
2608
|
+
typedName: type2.typedName,
|
|
2609
|
+
description,
|
|
2610
|
+
tree,
|
|
2611
|
+
mapper,
|
|
2612
|
+
enumType,
|
|
2613
|
+
optionalType,
|
|
2614
|
+
keysToOmit
|
|
2615
|
+
}
|
|
2616
|
+
)
|
|
2617
|
+
] }, i);
|
|
2618
|
+
};
|
|
2619
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2620
|
+
operationSchemas.map(mapOperationSchema),
|
|
2621
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, schemas, pluginManager }) })
|
|
2622
|
+
] });
|
|
2623
|
+
},
|
|
2624
|
+
Schema({ schema, options }) {
|
|
2625
|
+
const { mapper, enumType, optionalType } = options;
|
|
2626
|
+
const { mode } = react.useApp();
|
|
2627
|
+
const { getName, getImports, getFile } = hooks.useSchemaManager();
|
|
2628
|
+
const imports = getImports(schema.tree);
|
|
2629
|
+
if (enumType === "asPascalConst") {
|
|
2630
|
+
console.warn(`enumType '${enumType}' is deprecated`);
|
|
2631
|
+
}
|
|
2632
|
+
const type = {
|
|
2633
|
+
name: getName(schema.name, { type: "function" }),
|
|
2634
|
+
typedName: getName(schema.name, { type: "type" }),
|
|
2635
|
+
file: getFile(schema.name)
|
|
2636
|
+
};
|
|
2637
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: type.file.baseName, path: type.file.path, meta: type.file.meta, children: [
|
|
2638
|
+
mode === "split" && imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: type.file.path, path: imp.path, name: imp.name, isTypeOnly: true }, index)),
|
|
2639
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2640
|
+
Type2,
|
|
2641
|
+
{
|
|
2642
|
+
name: type.name,
|
|
2643
|
+
typedName: type.typedName,
|
|
2644
|
+
description: schema.value.description,
|
|
2645
|
+
tree: schema.tree,
|
|
2646
|
+
mapper,
|
|
2647
|
+
enumType,
|
|
2648
|
+
optionalType
|
|
2649
|
+
}
|
|
2650
|
+
)
|
|
2651
|
+
] });
|
|
2709
2652
|
}
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2653
|
+
});
|
|
2654
|
+
|
|
2655
|
+
// ../plugin-ts/src/generators/oasGenerator.tsx
|
|
2656
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2657
|
+
var oasGenerator = pluginOas.createReactGenerator({
|
|
2658
|
+
name: "oas",
|
|
2659
|
+
Operations() {
|
|
2660
|
+
const { pluginManager, plugin } = react.useApp();
|
|
2661
|
+
const oas = hooks.useOas();
|
|
2662
|
+
const file = pluginManager.getFile({ name: "oas", extName: ".ts", pluginKey: plugin.key });
|
|
2663
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2664
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
|
|
2665
|
+
/* @__PURE__ */ jsxRuntime.jsx(OasType, { name: "oas", typeName: "Oas", api: oas.api })
|
|
2666
|
+
] });
|
|
2719
2667
|
}
|
|
2720
|
-
};
|
|
2668
|
+
});
|
|
2721
2669
|
|
|
2722
2670
|
// ../plugin-ts/src/plugin.ts
|
|
2723
2671
|
var pluginTsName = "plugin-ts";
|
|
@@ -2733,7 +2681,7 @@ core.createPlugin((options) => {
|
|
|
2733
2681
|
dateType = "string",
|
|
2734
2682
|
unknownType = "any",
|
|
2735
2683
|
optionalType = "questionToken",
|
|
2736
|
-
transformers:
|
|
2684
|
+
transformers: transformers4 = {},
|
|
2737
2685
|
oasType = false,
|
|
2738
2686
|
mapper = {}
|
|
2739
2687
|
} = options;
|
|
@@ -2745,8 +2693,7 @@ core.createPlugin((options) => {
|
|
|
2745
2693
|
...output
|
|
2746
2694
|
},
|
|
2747
2695
|
options: {
|
|
2748
|
-
|
|
2749
|
-
transformers: transformers7,
|
|
2696
|
+
transformers: transformers4,
|
|
2750
2697
|
dateType,
|
|
2751
2698
|
optionalType,
|
|
2752
2699
|
oasType,
|
|
@@ -2766,15 +2713,15 @@ core.createPlugin((options) => {
|
|
|
2766
2713
|
return path__default.default.resolve(root, output.path);
|
|
2767
2714
|
}
|
|
2768
2715
|
if (options2?.tag && group?.type === "tag") {
|
|
2769
|
-
const tag =
|
|
2716
|
+
const tag = transformers2.camelCase(options2.tag);
|
|
2770
2717
|
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
2771
2718
|
}
|
|
2772
2719
|
return path__default.default.resolve(root, output.path, baseName);
|
|
2773
2720
|
},
|
|
2774
2721
|
resolveName(name, type) {
|
|
2775
|
-
const resolvedName =
|
|
2722
|
+
const resolvedName = transformers2.pascalCase(name, { isFile: type === "file" });
|
|
2776
2723
|
if (type) {
|
|
2777
|
-
return
|
|
2724
|
+
return transformers4?.name?.(resolvedName, type) || resolvedName;
|
|
2778
2725
|
}
|
|
2779
2726
|
return resolvedName;
|
|
2780
2727
|
},
|
|
@@ -2783,7 +2730,7 @@ core.createPlugin((options) => {
|
|
|
2783
2730
|
const oas = await swaggerPlugin.context.getOas();
|
|
2784
2731
|
const root = path__default.default.resolve(this.config.root, this.config.output.path);
|
|
2785
2732
|
const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
|
|
2786
|
-
const schemaGenerator = new
|
|
2733
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(this.plugin.options, {
|
|
2787
2734
|
oas,
|
|
2788
2735
|
pluginManager: this.pluginManager,
|
|
2789
2736
|
plugin: this.plugin,
|
|
@@ -2793,9 +2740,9 @@ core.createPlugin((options) => {
|
|
|
2793
2740
|
mode,
|
|
2794
2741
|
output: output.path
|
|
2795
2742
|
});
|
|
2796
|
-
const schemaFiles = await schemaGenerator.build();
|
|
2743
|
+
const schemaFiles = await schemaGenerator.build(...[typeGenerator, oasType === "infer" ? oasGenerator : void 0].filter(Boolean));
|
|
2797
2744
|
await this.addFile(...schemaFiles);
|
|
2798
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
2745
|
+
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
2799
2746
|
oas,
|
|
2800
2747
|
pluginManager: this.pluginManager,
|
|
2801
2748
|
plugin: this.plugin,
|
|
@@ -2805,7 +2752,7 @@ core.createPlugin((options) => {
|
|
|
2805
2752
|
override,
|
|
2806
2753
|
mode
|
|
2807
2754
|
});
|
|
2808
|
-
const operationFiles = await operationGenerator.build();
|
|
2755
|
+
const operationFiles = await operationGenerator.build(...[typeGenerator, oasType === "infer" ? oasGenerator : void 0].filter(Boolean));
|
|
2809
2756
|
await this.addFile(...operationFiles);
|
|
2810
2757
|
if (this.config.output.exportType) {
|
|
2811
2758
|
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
@@ -2822,391 +2769,99 @@ core.createPlugin((options) => {
|
|
|
2822
2769
|
}
|
|
2823
2770
|
};
|
|
2824
2771
|
});
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
},
|
|
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 ?? ""})`,
|
|
2857
|
-
/**
|
|
2858
|
-
* ISO 8601
|
|
2859
|
-
*/
|
|
2860
|
-
datetime: (offset = false, local = false) => {
|
|
2861
|
-
if (offset) {
|
|
2862
|
-
return `z.string().datetime({ offset: ${offset} })`;
|
|
2863
|
-
}
|
|
2864
|
-
if (local) {
|
|
2865
|
-
return `z.string().datetime({ local: ${local} })`;
|
|
2866
|
-
}
|
|
2867
|
-
return "z.string().datetime()";
|
|
2868
|
-
},
|
|
2869
|
-
/**
|
|
2870
|
-
* Type `'date'` Date
|
|
2871
|
-
* Type `'string'` ISO date format (YYYY-MM-DD)
|
|
2872
|
-
* @default ISO date format (YYYY-MM-DD)
|
|
2873
|
-
*/
|
|
2874
|
-
date: (type = "string", coercion) => {
|
|
2875
|
-
if (type === "string") {
|
|
2876
|
-
return "z.string().date()";
|
|
2877
|
-
}
|
|
2878
|
-
if (coercion) {
|
|
2879
|
-
return "z.coerce.date()";
|
|
2880
|
-
}
|
|
2881
|
-
return "z.date()";
|
|
2882
|
-
},
|
|
2883
|
-
/**
|
|
2884
|
-
* Type `'date'` Date
|
|
2885
|
-
* Type `'string'` ISO time format (HH:mm:ss[.SSSSSS])
|
|
2886
|
-
* @default ISO time format (HH:mm:ss[.SSSSSS])
|
|
2887
|
-
*/
|
|
2888
|
-
time: (type = "string", coercion) => {
|
|
2889
|
-
if (type === "string") {
|
|
2890
|
-
return "z.string().time()";
|
|
2891
|
-
}
|
|
2892
|
-
if (coercion) {
|
|
2893
|
-
return "z.coerce.date()";
|
|
2894
|
-
}
|
|
2895
|
-
return "z.date()";
|
|
2896
|
-
},
|
|
2897
|
-
uuid: () => ".uuid()",
|
|
2898
|
-
url: () => ".url()",
|
|
2899
|
-
strict: () => ".strict()",
|
|
2900
|
-
default: (value) => `.default(${value ?? ""})`,
|
|
2901
|
-
and: (items = []) => items?.map((item) => `.and(${item})`).join(""),
|
|
2902
|
-
describe: (value = "") => `.describe(${value})`,
|
|
2903
|
-
min: (value) => `.min(${value ?? ""})`,
|
|
2904
|
-
max: (value) => `.max(${value ?? ""})`,
|
|
2905
|
-
optional: () => ".optional()",
|
|
2906
|
-
matches: (value = "") => `.regex(${value})`,
|
|
2907
|
-
email: () => ".email()",
|
|
2908
|
-
firstName: void 0,
|
|
2909
|
-
lastName: void 0,
|
|
2910
|
-
password: void 0,
|
|
2911
|
-
phone: void 0,
|
|
2912
|
-
readOnly: void 0,
|
|
2913
|
-
ref: (value) => value ? `z.lazy(() => ${value})` : void 0,
|
|
2914
|
-
blob: () => "z.string()",
|
|
2915
|
-
deprecated: void 0,
|
|
2916
|
-
example: void 0,
|
|
2917
|
-
schema: void 0,
|
|
2918
|
-
catchall: (value) => value ? `.catchall(${value})` : void 0,
|
|
2919
|
-
name: void 0
|
|
2920
|
-
};
|
|
2921
|
-
function sort(items) {
|
|
2922
|
-
const order = [
|
|
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
|
|
2946
|
-
];
|
|
2947
|
-
if (!items) {
|
|
2948
|
-
return [];
|
|
2949
|
-
}
|
|
2950
|
-
return transformers4__default.default.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
|
|
2951
|
-
}
|
|
2952
|
-
function parse2(parent, current, options) {
|
|
2953
|
-
const value = zodKeywordMapper[current.keyword];
|
|
2954
|
-
if (!value) {
|
|
2955
|
-
return void 0;
|
|
2956
|
-
}
|
|
2957
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.union)) {
|
|
2958
|
-
if (Array.isArray(current.args) && current.args.length === 1) {
|
|
2959
|
-
return parse2(parent, current.args[0], options);
|
|
2960
|
-
}
|
|
2961
|
-
if (Array.isArray(current.args) && !current.args.length) {
|
|
2962
|
-
return "";
|
|
2963
|
-
}
|
|
2964
|
-
return zodKeywordMapper.union(
|
|
2965
|
-
sort(current.args).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
2966
|
-
);
|
|
2967
|
-
}
|
|
2968
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.and)) {
|
|
2969
|
-
const items = sort(current.args).filter((schema) => {
|
|
2970
|
-
return ![pluginOas.schemaKeywords.optional, pluginOas.schemaKeywords.describe].includes(schema.keyword);
|
|
2971
|
-
}).map((schema) => parse2(current, schema, options)).filter(Boolean);
|
|
2972
|
-
return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
|
|
2973
|
-
}
|
|
2974
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.array)) {
|
|
2975
|
-
return zodKeywordMapper.array(
|
|
2976
|
-
sort(current.args.items).map((schemas) => parse2(current, schemas, options)).filter(Boolean),
|
|
2977
|
-
current.args.min,
|
|
2978
|
-
current.args.max
|
|
2979
|
-
);
|
|
2980
|
-
}
|
|
2981
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.enum)) {
|
|
2982
|
-
if (current.args.asConst) {
|
|
2983
|
-
return zodKeywordMapper.union(
|
|
2984
|
-
current.args.items.map((schema) => {
|
|
2985
|
-
return parse2(
|
|
2986
|
-
current,
|
|
2987
|
-
{
|
|
2988
|
-
keyword: pluginOas.schemaKeywords.const,
|
|
2989
|
-
args: schema
|
|
2990
|
-
},
|
|
2991
|
-
options
|
|
2992
|
-
);
|
|
2993
|
-
}).filter(Boolean)
|
|
2994
|
-
);
|
|
2995
|
-
}
|
|
2996
|
-
return zodKeywordMapper.enum(
|
|
2997
|
-
current.args.items.map((schema) => {
|
|
2998
|
-
if (schema.format === "number") {
|
|
2999
|
-
return transformers4__default.default.stringify(schema.value);
|
|
3000
|
-
}
|
|
3001
|
-
return transformers4__default.default.stringify(schema.value);
|
|
3002
|
-
})
|
|
3003
|
-
);
|
|
3004
|
-
}
|
|
3005
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.ref)) {
|
|
3006
|
-
return zodKeywordMapper.ref(current.args?.name);
|
|
3007
|
-
}
|
|
3008
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.object)) {
|
|
3009
|
-
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
3010
|
-
const schema = item[1];
|
|
3011
|
-
return schema && typeof schema.map === "function";
|
|
3012
|
-
}).map(([name, schemas]) => {
|
|
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]}`;
|
|
3017
|
-
}
|
|
3018
|
-
return `"${name}": ${sort(schemas).map((schema, array) => {
|
|
3019
|
-
return parse2(current, schema, options);
|
|
3020
|
-
}).filter(Boolean).join("")}`;
|
|
3021
|
-
}).join(",");
|
|
3022
|
-
const additionalProperties = current.args?.additionalProperties?.length ? current.args.additionalProperties.map((schema) => parse2(current, schema, options)).filter(Boolean).at(0) : void 0;
|
|
3023
|
-
const text = [
|
|
3024
|
-
zodKeywordMapper.object(properties),
|
|
3025
|
-
current.args?.strict ? zodKeywordMapper.strict() : void 0,
|
|
3026
|
-
additionalProperties ? zodKeywordMapper.catchall(additionalProperties) : void 0
|
|
3027
|
-
].filter(Boolean);
|
|
3028
|
-
return text.join("");
|
|
3029
|
-
}
|
|
3030
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.tuple)) {
|
|
3031
|
-
return zodKeywordMapper.tuple(
|
|
3032
|
-
sort(current.args.items).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
3033
|
-
);
|
|
3034
|
-
}
|
|
3035
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.const)) {
|
|
3036
|
-
if (current.args.format === "number" && current.args.value !== void 0) {
|
|
3037
|
-
return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
|
|
3038
|
-
}
|
|
3039
|
-
return zodKeywordMapper.const(transformers4__default.default.stringify(current.args.value));
|
|
3040
|
-
}
|
|
3041
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.matches)) {
|
|
3042
|
-
if (current.args) {
|
|
3043
|
-
return zodKeywordMapper.matches(transformers4__default.default.toRegExpString(current.args));
|
|
3044
|
-
}
|
|
3045
|
-
}
|
|
3046
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.default)) {
|
|
3047
|
-
if (current.args) {
|
|
3048
|
-
return zodKeywordMapper.default(current.args);
|
|
3049
|
-
}
|
|
3050
|
-
}
|
|
3051
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.describe)) {
|
|
3052
|
-
if (current.args) {
|
|
3053
|
-
return zodKeywordMapper.describe(transformers4__default.default.stringify(current.args.toString()));
|
|
3054
|
-
}
|
|
3055
|
-
}
|
|
3056
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.string)) {
|
|
3057
|
-
return zodKeywordMapper.string(options.coercion);
|
|
3058
|
-
}
|
|
3059
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.number)) {
|
|
3060
|
-
return zodKeywordMapper.number(options.coercion);
|
|
3061
|
-
}
|
|
3062
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.integer)) {
|
|
3063
|
-
return zodKeywordMapper.integer(options.coercion);
|
|
3064
|
-
}
|
|
3065
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.min)) {
|
|
3066
|
-
return zodKeywordMapper.min(current.args);
|
|
3067
|
-
}
|
|
3068
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.max)) {
|
|
3069
|
-
return zodKeywordMapper.max(current.args);
|
|
3070
|
-
}
|
|
3071
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.datetime)) {
|
|
3072
|
-
return zodKeywordMapper.datetime(current.args.offset, current.args.local);
|
|
3073
|
-
}
|
|
3074
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.date)) {
|
|
3075
|
-
return zodKeywordMapper.date(current.args.type, options.coercion);
|
|
3076
|
-
}
|
|
3077
|
-
if (pluginOas.isKeyword(current, pluginOas.schemaKeywords.time)) {
|
|
3078
|
-
return zodKeywordMapper.time(current.args.type, options.coercion);
|
|
3079
|
-
}
|
|
3080
|
-
if (current.keyword in zodKeywordMapper && "args" in current) {
|
|
3081
|
-
const value2 = zodKeywordMapper[current.keyword];
|
|
3082
|
-
return value2(current.args);
|
|
3083
|
-
}
|
|
3084
|
-
if (current.keyword in zodKeywordMapper) {
|
|
3085
|
-
return value();
|
|
3086
|
-
}
|
|
3087
|
-
return void 0;
|
|
3088
|
-
}
|
|
3089
|
-
|
|
3090
|
-
// src/plugin.ts
|
|
3091
|
-
init_cjs_shims();
|
|
3092
|
-
|
|
3093
|
-
// src/SchemaGenerator.tsx
|
|
3094
|
-
init_cjs_shims();
|
|
3095
|
-
|
|
3096
|
-
// src/components/OperationSchema.tsx
|
|
3097
|
-
init_cjs_shims();
|
|
3098
|
-
function OperationSchema2({ description, keysToOmit }) {
|
|
3099
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
3100
|
-
}
|
|
3101
|
-
OperationSchema2.File = function({}) {
|
|
3102
|
-
const { pluginManager, plugin, mode } = react.useApp();
|
|
3103
|
-
const { getSchemas, getFile } = hooks.useOperationManager();
|
|
3104
|
-
const oas = hooks.useOas();
|
|
3105
|
-
const operation = hooks.useOperation();
|
|
3106
|
-
const file = getFile(operation);
|
|
3107
|
-
const schemas = getSchemas(operation);
|
|
3108
|
-
const generator = new pluginOas.SchemaGenerator(plugin.options, {
|
|
3109
|
-
oas,
|
|
3110
|
-
plugin,
|
|
3111
|
-
pluginManager,
|
|
3112
|
-
mode,
|
|
3113
|
-
override: plugin.options.override
|
|
3114
|
-
});
|
|
3115
|
-
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
3116
|
-
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
3117
|
-
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
3118
|
-
const optional = !required && !!name.includes("Params");
|
|
3119
|
-
const tree = generator.parse({ schema, name });
|
|
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 })
|
|
3123
|
-
] }, i);
|
|
3124
|
-
};
|
|
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 }),
|
|
3127
|
-
items.map(mapItem)
|
|
3128
|
-
] });
|
|
3129
|
-
};
|
|
3130
|
-
|
|
3131
|
-
// src/components/Operations.tsx
|
|
3132
|
-
init_cjs_shims();
|
|
3133
|
-
function Template2({ operationsName, pathsName, operations }) {
|
|
3134
|
-
const { groupSchemasByName } = hooks.useOperationManager();
|
|
3135
|
-
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
3136
|
-
const operationsJSON = transformedOperations.reduce(
|
|
3137
|
-
(prev, acc) => {
|
|
3138
|
-
prev[`"${acc.operation.getOperationId()}"`] = acc.data;
|
|
3139
|
-
return prev;
|
|
3140
|
-
},
|
|
3141
|
-
{}
|
|
3142
|
-
);
|
|
3143
|
-
const pathsJSON = transformedOperations.reduce(
|
|
3144
|
-
(prev, acc) => {
|
|
3145
|
-
prev[`"${acc.operation.path}"`] = {
|
|
3146
|
-
...prev[`"${acc.operation.path}"`] || {},
|
|
3147
|
-
[acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
|
|
2772
|
+
var zodGenerator = pluginOas.createReactGenerator({
|
|
2773
|
+
name: "zod",
|
|
2774
|
+
Operation({ operation, options }) {
|
|
2775
|
+
const { coercion, inferred, typed, mapper } = options;
|
|
2776
|
+
const { plugin, pluginManager, mode } = react.useApp();
|
|
2777
|
+
const oas = hooks.useOas();
|
|
2778
|
+
const { getSchemas, getFile } = hooks.useOperationManager();
|
|
2779
|
+
const schemaManager = hooks.useSchemaManager();
|
|
2780
|
+
const file = getFile(operation);
|
|
2781
|
+
const schemas = getSchemas(operation);
|
|
2782
|
+
const schemaGenerator = new pluginOas.SchemaGenerator(options, {
|
|
2783
|
+
oas,
|
|
2784
|
+
plugin,
|
|
2785
|
+
pluginManager,
|
|
2786
|
+
mode,
|
|
2787
|
+
override: options.override
|
|
2788
|
+
});
|
|
2789
|
+
const operationSchemas = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
2790
|
+
const mapOperationSchema = ({ name, schema, description, keysToOmit, ...options2 }, i) => {
|
|
2791
|
+
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
2792
|
+
const optional = !required && !!name.includes("Params");
|
|
2793
|
+
const tree = [...schemaGenerator.parse({ schema, name }), optional ? { keyword: pluginOas.schemaKeywords.optional } : void 0].filter(Boolean);
|
|
2794
|
+
const imports = schemaManager.getImports(tree);
|
|
2795
|
+
const zod = {
|
|
2796
|
+
name: schemaManager.getName(name, { type: "function" }),
|
|
2797
|
+
inferTypeName: schemaManager.getName(name, { type: "type" }),
|
|
2798
|
+
file: schemaManager.getFile(name)
|
|
3148
2799
|
};
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
}).filter(Boolean);
|
|
3176
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3177
|
-
mode === "split" && imports,
|
|
3178
|
-
children
|
|
3179
|
-
] });
|
|
3180
|
-
}
|
|
3181
|
-
var defaultTemplates2 = { default: Template2, root: RootTemplate };
|
|
3182
|
-
function Operations({ Template: Template3 = defaultTemplates2.default }) {
|
|
3183
|
-
const operations = hooks.useOperations();
|
|
3184
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Template3, { operationsName: "operations", pathsName: "paths", operations });
|
|
3185
|
-
}
|
|
3186
|
-
Operations.File = function(props) {
|
|
3187
|
-
const templates = { ...defaultTemplates2, ...props.templates };
|
|
3188
|
-
const Template3 = templates.default;
|
|
3189
|
-
const RootTemplate2 = templates.root;
|
|
3190
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RootTemplate2, { children: /* @__PURE__ */ jsxRuntime.jsx(Operations, { Template: Template3 }) });
|
|
3191
|
-
};
|
|
3192
|
-
Operations.templates = defaultTemplates2;
|
|
3193
|
-
var zodParser = pluginOas.createReactGenerator({
|
|
3194
|
-
name: "plugin-zod",
|
|
3195
|
-
Operations({ options }) {
|
|
3196
|
-
if (!options.templates.operations) {
|
|
3197
|
-
return null;
|
|
3198
|
-
}
|
|
3199
|
-
return /* @__PURE__ */ jsxRuntime.jsx(Operations.File, { templates: options.templates.operations });
|
|
3200
|
-
},
|
|
3201
|
-
Operation() {
|
|
3202
|
-
return /* @__PURE__ */ jsxRuntime.jsx(OperationSchema2.File, {});
|
|
2800
|
+
const type = {
|
|
2801
|
+
name: schemaManager.getName(name, { type: "type", pluginKey: [pluginTsName] }),
|
|
2802
|
+
file: schemaManager.getFile(options2.operationName || name, { pluginKey: [pluginTsName], tag: options2.operation?.getTags()[0]?.name })
|
|
2803
|
+
};
|
|
2804
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(components.Oas.Schema, { name, value: schema, tree, children: [
|
|
2805
|
+
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: file.path, path: type.file.path, name: [type.name] }),
|
|
2806
|
+
imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: file.path, path: imp.path, name: imp.name }, index)),
|
|
2807
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2808
|
+
chunkQ7F7N57F_cjs.Zod,
|
|
2809
|
+
{
|
|
2810
|
+
name: zod.name,
|
|
2811
|
+
typeName: typed ? type.name : void 0,
|
|
2812
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
2813
|
+
description,
|
|
2814
|
+
tree,
|
|
2815
|
+
mapper,
|
|
2816
|
+
coercion,
|
|
2817
|
+
keysToOmit
|
|
2818
|
+
}
|
|
2819
|
+
)
|
|
2820
|
+
] }, i);
|
|
2821
|
+
};
|
|
2822
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2823
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
2824
|
+
operationSchemas.map(mapOperationSchema)
|
|
2825
|
+
] });
|
|
3203
2826
|
},
|
|
3204
|
-
Schema({ schema,
|
|
3205
|
-
|
|
2827
|
+
Schema({ schema, options }) {
|
|
2828
|
+
const { coercion, inferred, typed, mapper, importPath } = options;
|
|
2829
|
+
const { getName, getFile, getImports } = hooks.useSchemaManager();
|
|
2830
|
+
const imports = getImports(schema.tree);
|
|
2831
|
+
const zod = {
|
|
2832
|
+
name: getName(schema.name, { type: "function" }),
|
|
2833
|
+
inferTypeName: getName(schema.name, { type: "type" }),
|
|
2834
|
+
file: getFile(schema.name)
|
|
2835
|
+
};
|
|
2836
|
+
const type = {
|
|
2837
|
+
name: getName(schema.name, { type: "type", pluginKey: [pluginTsName] }),
|
|
2838
|
+
file: getFile(schema.name, { pluginKey: [pluginTsName] })
|
|
2839
|
+
};
|
|
2840
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: zod.file.baseName, path: zod.file.path, meta: zod.file.meta, children: [
|
|
2841
|
+
/* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["z"], path: importPath }),
|
|
2842
|
+
typed && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { isTypeOnly: true, root: zod.file.path, path: type.file.path, name: [type.name] }),
|
|
2843
|
+
imports.map((imp, index) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { root: zod.file.path, path: imp.path, name: imp.name }, index)),
|
|
2844
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2845
|
+
chunkQ7F7N57F_cjs.Zod,
|
|
2846
|
+
{
|
|
2847
|
+
name: zod.name,
|
|
2848
|
+
typeName: typed ? type.name : void 0,
|
|
2849
|
+
inferTypeName: inferred ? zod.inferTypeName : void 0,
|
|
2850
|
+
description: schema.value.description,
|
|
2851
|
+
tree: schema.tree,
|
|
2852
|
+
mapper,
|
|
2853
|
+
coercion
|
|
2854
|
+
}
|
|
2855
|
+
)
|
|
2856
|
+
] });
|
|
3206
2857
|
}
|
|
3207
2858
|
});
|
|
3208
2859
|
|
|
2860
|
+
// src/generators/operationsGenerator.tsx
|
|
2861
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
2862
|
+
|
|
3209
2863
|
// src/plugin.ts
|
|
2864
|
+
chunkQ7F7N57F_cjs.init_cjs_shims();
|
|
3210
2865
|
var pluginZodName = "plugin-zod";
|
|
3211
2866
|
var pluginZod = core.createPlugin((options) => {
|
|
3212
2867
|
const {
|
|
@@ -3215,15 +2870,15 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
3215
2870
|
exclude = [],
|
|
3216
2871
|
include,
|
|
3217
2872
|
override = [],
|
|
3218
|
-
transformers:
|
|
2873
|
+
transformers: transformers4 = {},
|
|
3219
2874
|
dateType = "string",
|
|
3220
2875
|
unknownType = "any",
|
|
3221
2876
|
typed = false,
|
|
3222
|
-
typedSchema = false,
|
|
3223
2877
|
mapper = {},
|
|
3224
|
-
|
|
2878
|
+
operations = false,
|
|
3225
2879
|
importPath = "zod",
|
|
3226
|
-
coercion = false
|
|
2880
|
+
coercion = false,
|
|
2881
|
+
inferred = false
|
|
3227
2882
|
} = options;
|
|
3228
2883
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
3229
2884
|
return {
|
|
@@ -3234,21 +2889,18 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
3234
2889
|
},
|
|
3235
2890
|
options: {
|
|
3236
2891
|
extName: output.extName,
|
|
3237
|
-
transformers:
|
|
2892
|
+
transformers: transformers4,
|
|
3238
2893
|
include,
|
|
3239
2894
|
exclude,
|
|
3240
2895
|
override,
|
|
3241
2896
|
typed,
|
|
3242
|
-
typedSchema,
|
|
3243
2897
|
dateType,
|
|
3244
2898
|
unknownType,
|
|
3245
2899
|
mapper,
|
|
3246
2900
|
importPath,
|
|
3247
2901
|
coercion,
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
...templates
|
|
3251
|
-
}
|
|
2902
|
+
operations,
|
|
2903
|
+
inferred
|
|
3252
2904
|
},
|
|
3253
2905
|
pre: [pluginOas.pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
|
|
3254
2906
|
resolvePath(baseName, pathMode, options2) {
|
|
@@ -3258,21 +2910,21 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
3258
2910
|
return path__default.default.resolve(root, output.path);
|
|
3259
2911
|
}
|
|
3260
2912
|
if (options2?.tag && group?.type === "tag") {
|
|
3261
|
-
const tag =
|
|
2913
|
+
const tag = transformers2.camelCase(options2.tag);
|
|
3262
2914
|
return path__default.default.resolve(root, utils.renderTemplate(template, { tag }), baseName);
|
|
3263
2915
|
}
|
|
3264
2916
|
return path__default.default.resolve(root, output.path, baseName);
|
|
3265
2917
|
},
|
|
3266
2918
|
resolveName(name, type) {
|
|
3267
|
-
let resolvedName =
|
|
2919
|
+
let resolvedName = transformers2.camelCase(name, {
|
|
3268
2920
|
suffix: type ? "schema" : void 0,
|
|
3269
2921
|
isFile: type === "file"
|
|
3270
2922
|
});
|
|
3271
2923
|
if (type === "type") {
|
|
3272
|
-
resolvedName =
|
|
2924
|
+
resolvedName = transformers2.pascalCase(resolvedName);
|
|
3273
2925
|
}
|
|
3274
2926
|
if (type) {
|
|
3275
|
-
return
|
|
2927
|
+
return transformers4?.name?.(resolvedName, type) || resolvedName;
|
|
3276
2928
|
}
|
|
3277
2929
|
return resolvedName;
|
|
3278
2930
|
},
|
|
@@ -3291,7 +2943,7 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
3291
2943
|
mode,
|
|
3292
2944
|
output: output.path
|
|
3293
2945
|
});
|
|
3294
|
-
const schemaFiles = await schemaGenerator.build(
|
|
2946
|
+
const schemaFiles = await schemaGenerator.build(...[zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean));
|
|
3295
2947
|
await this.addFile(...schemaFiles);
|
|
3296
2948
|
const operationGenerator = new pluginOas.OperationGenerator(this.plugin.options, {
|
|
3297
2949
|
oas,
|
|
@@ -3303,7 +2955,7 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
3303
2955
|
override,
|
|
3304
2956
|
mode
|
|
3305
2957
|
});
|
|
3306
|
-
const operationFiles = await operationGenerator.build(
|
|
2958
|
+
const operationFiles = await operationGenerator.build(...[zodGenerator, operations ? operationsGenerator : void 0].filter(Boolean));
|
|
3307
2959
|
await this.addFile(...operationFiles);
|
|
3308
2960
|
if (this.config.output.exportType) {
|
|
3309
2961
|
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
@@ -3320,113 +2972,24 @@ var pluginZod = core.createPlugin((options) => {
|
|
|
3320
2972
|
}
|
|
3321
2973
|
};
|
|
3322
2974
|
});
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
}
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
pluginKey: [pluginZodName],
|
|
3340
|
-
type: "type"
|
|
3341
|
-
});
|
|
3342
|
-
const typeName = pluginManager.resolveName({
|
|
3343
|
-
name,
|
|
3344
|
-
pluginKey: [pluginTsName],
|
|
3345
|
-
type: "type"
|
|
3346
|
-
});
|
|
3347
|
-
if (!tree.length) {
|
|
3348
|
-
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
3349
|
-
react.Const,
|
|
3350
|
-
{
|
|
3351
|
-
name: resolvedName,
|
|
3352
|
-
export: true,
|
|
3353
|
-
JSDoc: {
|
|
3354
|
-
comments: [description ? `@description ${transformers4__default.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
3355
|
-
},
|
|
3356
|
-
children: "undefined"
|
|
3357
|
-
}
|
|
3358
|
-
) });
|
|
2975
|
+
var operationsGenerator = pluginOas.createReactGenerator({
|
|
2976
|
+
name: "operations",
|
|
2977
|
+
Operations({ operations, options }) {
|
|
2978
|
+
const { pluginManager } = react.useApp();
|
|
2979
|
+
const { getFile, groupSchemasByName } = hooks.useOperationManager();
|
|
2980
|
+
const name = "operations";
|
|
2981
|
+
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: [pluginZodName] });
|
|
2982
|
+
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
2983
|
+
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
2984
|
+
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
2985
|
+
return /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
2986
|
+
}).filter(Boolean);
|
|
2987
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2988
|
+
imports,
|
|
2989
|
+
/* @__PURE__ */ jsxRuntime.jsx(chunkQ7F7N57F_cjs.Operations, { name, operations: transformedOperations })
|
|
2990
|
+
] });
|
|
3359
2991
|
}
|
|
3360
|
-
|
|
3361
|
-
const output = sort(tree).filter((item) => {
|
|
3362
|
-
if (hasTuple && (pluginOas.isKeyword(item, pluginOas.schemaKeywords.min) || pluginOas.isKeyword(item, pluginOas.schemaKeywords.max))) {
|
|
3363
|
-
return false;
|
|
3364
|
-
}
|
|
3365
|
-
return true;
|
|
3366
|
-
}).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
|
|
3367
|
-
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
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,
|
|
3371
|
-
{
|
|
3372
|
-
export: true,
|
|
3373
|
-
name: resolvedName,
|
|
3374
|
-
JSDoc: {
|
|
3375
|
-
comments: [description ? `@description ${transformers4__default.default.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
3376
|
-
},
|
|
3377
|
-
children: [
|
|
3378
|
-
output,
|
|
3379
|
-
keysToOmit?.length ? `${suffix}(z.object({ ${keysToOmit.map((key) => `${key}: z.never()`).join(",")} }))` : void 0,
|
|
3380
|
-
withTypeAnnotation && typeName ? ` as z.ZodType<${typeName}>` : ""
|
|
3381
|
-
].filter(Boolean).join("") || ""
|
|
3382
|
-
}
|
|
3383
|
-
) }),
|
|
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}>` }) })
|
|
3385
|
-
] });
|
|
3386
|
-
}
|
|
3387
|
-
Schema2.File = function({}) {
|
|
3388
|
-
const {
|
|
3389
|
-
pluginManager,
|
|
3390
|
-
plugin: {
|
|
3391
|
-
options: { typed }
|
|
3392
|
-
}
|
|
3393
|
-
} = react.useApp();
|
|
3394
|
-
const { schema } = hooks.useSchema();
|
|
3395
|
-
const withTypeAnnotation = !!typed;
|
|
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 })
|
|
3399
|
-
] });
|
|
3400
|
-
};
|
|
3401
|
-
Schema2.Imports = () => {
|
|
3402
|
-
const {
|
|
3403
|
-
pluginManager,
|
|
3404
|
-
plugin: {
|
|
3405
|
-
options: { typed, importPath }
|
|
3406
|
-
}
|
|
3407
|
-
} = react.useApp();
|
|
3408
|
-
const { path: root } = react.useFile();
|
|
3409
|
-
const { name, tree, schema } = hooks.useSchema();
|
|
3410
|
-
const typeName = pluginManager.resolveName({
|
|
3411
|
-
name,
|
|
3412
|
-
pluginKey: [pluginTsName],
|
|
3413
|
-
type: "type"
|
|
3414
|
-
});
|
|
3415
|
-
const typeFileName = pluginManager.resolveName({
|
|
3416
|
-
name,
|
|
3417
|
-
pluginKey: [pluginTsName],
|
|
3418
|
-
type: "file"
|
|
3419
|
-
});
|
|
3420
|
-
const typePath = pluginManager.resolvePath({
|
|
3421
|
-
baseName: typeFileName,
|
|
3422
|
-
pluginKey: [pluginTsName]
|
|
3423
|
-
});
|
|
3424
|
-
const withTypeAnnotation = !!typed;
|
|
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] })
|
|
3428
|
-
] });
|
|
3429
|
-
};
|
|
2992
|
+
});
|
|
3430
2993
|
/*! Bundled license information:
|
|
3431
2994
|
|
|
3432
2995
|
react/cjs/react.production.min.js:
|
|
@@ -3452,11 +3015,9 @@ react/cjs/react.development.js:
|
|
|
3452
3015
|
*)
|
|
3453
3016
|
*/
|
|
3454
3017
|
|
|
3455
|
-
exports.
|
|
3456
|
-
exports.Operations = Operations;
|
|
3457
|
-
exports.Schema = Schema2;
|
|
3458
|
-
exports.init_cjs_shims = init_cjs_shims;
|
|
3018
|
+
exports.operationsGenerator = operationsGenerator;
|
|
3459
3019
|
exports.pluginZod = pluginZod;
|
|
3460
3020
|
exports.pluginZodName = pluginZodName;
|
|
3461
|
-
|
|
3462
|
-
//# sourceMappingURL=chunk-
|
|
3021
|
+
exports.zodGenerator = zodGenerator;
|
|
3022
|
+
//# sourceMappingURL=chunk-HH7DZZUF.cjs.map
|
|
3023
|
+
//# sourceMappingURL=chunk-HH7DZZUF.cjs.map
|