@kubb/plugin-zod 3.0.0-alpha.10 → 3.0.0-alpha.12
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-CUPQVLRZ.js → chunk-BWE5OHCP.js} +189 -260
- package/dist/chunk-BWE5OHCP.js.map +1 -0
- package/dist/{chunk-57AHBVYK.cjs → chunk-N2VGLM33.cjs} +340 -380
- package/dist/chunk-N2VGLM33.cjs.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,3 +1,15 @@
|
|
|
1
|
+
import { Oas } from '@kubb/plugin-oas/components';
|
|
2
|
+
import { useApp, File, Const, Type, useFile, createRoot, App } from '@kubb/react';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
|
+
import transformers4, { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
6
|
+
import { renderTemplate } from '@kubb/core/utils';
|
|
7
|
+
import { pluginOasName, createReactGenerator, SchemaGenerator, OperationGenerator as OperationGenerator$1, isKeyword, schemaKeywords } from '@kubb/plugin-oas';
|
|
8
|
+
import { useSchema, useOperationManager, useOas, useOperation, useOperations } from '@kubb/plugin-oas/hooks';
|
|
9
|
+
import { jsx, jsxs, Fragment } from '@kubb/react/jsx-runtime';
|
|
10
|
+
import { print } from '@kubb/parser-ts';
|
|
11
|
+
import * as factory from '@kubb/parser-ts/factory';
|
|
12
|
+
|
|
1
13
|
var __create = Object.create;
|
|
2
14
|
var __defProp = Object.defineProperty;
|
|
3
15
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -23,21 +35,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
35
|
// file that has been converted to a CommonJS file using a Babel-
|
|
24
36
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
37
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
|
|
38
|
+
__defProp(target, "default", { value: mod, enumerable: true }) ,
|
|
27
39
|
mod
|
|
28
40
|
));
|
|
29
41
|
|
|
30
|
-
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
42
|
+
// ../../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/esm_shims.js
|
|
31
43
|
var init_esm_shims = __esm({
|
|
32
|
-
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
33
|
-
"use strict";
|
|
44
|
+
"../../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/esm_shims.js"() {
|
|
34
45
|
}
|
|
35
46
|
});
|
|
36
47
|
|
|
37
48
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
|
|
38
49
|
var require_react_production_min = __commonJS({
|
|
39
50
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js"(exports) {
|
|
40
|
-
"use strict";
|
|
41
51
|
init_esm_shims();
|
|
42
52
|
var l = Symbol.for("react.element");
|
|
43
53
|
var n = Symbol.for("react.portal");
|
|
@@ -311,11 +321,9 @@ var require_react_production_min = __commonJS({
|
|
|
311
321
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js
|
|
312
322
|
var require_react_development = __commonJS({
|
|
313
323
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.development.js"(exports, module) {
|
|
314
|
-
"use strict";
|
|
315
324
|
init_esm_shims();
|
|
316
325
|
if (process.env.NODE_ENV !== "production") {
|
|
317
326
|
(function() {
|
|
318
|
-
"use strict";
|
|
319
327
|
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== "undefined" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === "function") {
|
|
320
328
|
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
321
329
|
}
|
|
@@ -2186,7 +2194,6 @@ var require_react_development = __commonJS({
|
|
|
2186
2194
|
// ../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js
|
|
2187
2195
|
var require_react = __commonJS({
|
|
2188
2196
|
"../../node_modules/.pnpm/react@18.3.1/node_modules/react/index.js"(exports, module) {
|
|
2189
|
-
"use strict";
|
|
2190
2197
|
init_esm_shims();
|
|
2191
2198
|
if (process.env.NODE_ENV === "production") {
|
|
2192
2199
|
module.exports = require_react_production_min();
|
|
@@ -2198,31 +2205,18 @@ var require_react = __commonJS({
|
|
|
2198
2205
|
|
|
2199
2206
|
// src/components/Schema.tsx
|
|
2200
2207
|
init_esm_shims();
|
|
2201
|
-
import { Oas as Oas6 } from "@kubb/plugin-oas/components";
|
|
2202
|
-
import { Const as Const2, File as File6, Type as Type2, useApp as useApp6, useFile } from "@kubb/react";
|
|
2203
2208
|
|
|
2204
2209
|
// ../plugin-ts/src/index.ts
|
|
2205
2210
|
init_esm_shims();
|
|
2206
2211
|
|
|
2207
2212
|
// ../plugin-ts/src/plugin.ts
|
|
2208
2213
|
init_esm_shims();
|
|
2209
|
-
import path from "node:path";
|
|
2210
|
-
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
2211
|
-
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
2212
|
-
import { renderTemplate } from "@kubb/core/utils";
|
|
2213
|
-
import { pluginOasName } from "@kubb/plugin-oas";
|
|
2214
2214
|
|
|
2215
2215
|
// ../plugin-ts/src/OperationGenerator.tsx
|
|
2216
2216
|
init_esm_shims();
|
|
2217
|
-
import { OperationGenerator as Generator2 } from "@kubb/plugin-oas";
|
|
2218
|
-
import { Oas as Oas4 } from "@kubb/plugin-oas/components";
|
|
2219
|
-
import { App as App2, createRoot as createRoot2 } from "@kubb/react";
|
|
2220
2217
|
|
|
2221
2218
|
// ../plugin-ts/src/components/OasType.tsx
|
|
2222
2219
|
init_esm_shims();
|
|
2223
|
-
import { useOas } from "@kubb/plugin-oas/hooks";
|
|
2224
|
-
import { File, Type, useApp } from "@kubb/react";
|
|
2225
|
-
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
2226
2220
|
function Template({ name, typeName, api }) {
|
|
2227
2221
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2228
2222
|
/* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
@@ -2251,35 +2245,16 @@ OasType.templates = defaultTemplates;
|
|
|
2251
2245
|
|
|
2252
2246
|
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
2253
2247
|
init_esm_shims();
|
|
2254
|
-
import transformers3 from "@kubb/core/transformers";
|
|
2255
|
-
import { print as print2 } from "@kubb/parser-ts";
|
|
2256
|
-
import * as factory3 from "@kubb/parser-ts/factory";
|
|
2257
|
-
import { Oas as Oas3 } from "@kubb/plugin-oas/components";
|
|
2258
|
-
import { useOas as useOas2, useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
2259
|
-
import { File as File3, useApp as useApp3 } from "@kubb/react";
|
|
2260
2248
|
|
|
2261
2249
|
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
2262
2250
|
init_esm_shims();
|
|
2263
|
-
import { SchemaGenerator as Generator } from "@kubb/plugin-oas";
|
|
2264
|
-
import { Oas as Oas2 } from "@kubb/plugin-oas/components";
|
|
2265
|
-
import { App, createRoot } from "@kubb/react";
|
|
2266
2251
|
|
|
2267
2252
|
// ../plugin-ts/src/components/Schema.tsx
|
|
2268
2253
|
init_esm_shims();
|
|
2269
|
-
var import_react3 = __toESM(require_react()
|
|
2270
|
-
import { Oas } from "@kubb/plugin-oas/components";
|
|
2271
|
-
import { File as File2, useApp as useApp2 } from "@kubb/react";
|
|
2272
|
-
import transformers2 from "@kubb/core/transformers";
|
|
2273
|
-
import { print } from "@kubb/parser-ts";
|
|
2274
|
-
import * as factory2 from "@kubb/parser-ts/factory";
|
|
2275
|
-
import { SchemaGenerator, schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
|
|
2276
|
-
import { useSchema } from "@kubb/plugin-oas/hooks";
|
|
2254
|
+
var import_react3 = __toESM(require_react());
|
|
2277
2255
|
|
|
2278
2256
|
// ../plugin-ts/src/parser/index.ts
|
|
2279
2257
|
init_esm_shims();
|
|
2280
|
-
import transformers from "@kubb/core/transformers";
|
|
2281
|
-
import * as factory from "@kubb/parser-ts/factory";
|
|
2282
|
-
import { isKeyword, schemaKeywords } from "@kubb/plugin-oas";
|
|
2283
2258
|
var typeKeywordMapper = {
|
|
2284
2259
|
any: () => factory.keywordTypeNodes.any,
|
|
2285
2260
|
unknown: () => factory.keywordTypeNodes.unknown,
|
|
@@ -2446,7 +2421,7 @@ function parse(parent, current, options) {
|
|
|
2446
2421
|
return factory.appendJSDocToNode({
|
|
2447
2422
|
node: propertySignature,
|
|
2448
2423
|
comments: [
|
|
2449
|
-
describeSchema ? `@description ${
|
|
2424
|
+
describeSchema ? `@description ${transformers4.jsStringEscape(describeSchema.args)}` : void 0,
|
|
2450
2425
|
deprecatedSchema ? "@deprecated" : void 0,
|
|
2451
2426
|
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
|
2452
2427
|
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
|
@@ -2473,9 +2448,6 @@ function parse(parent, current, options) {
|
|
|
2473
2448
|
}
|
|
2474
2449
|
return void 0;
|
|
2475
2450
|
}
|
|
2476
|
-
|
|
2477
|
-
// ../plugin-ts/src/components/Schema.tsx
|
|
2478
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
|
|
2479
2451
|
function Schema(props) {
|
|
2480
2452
|
const { keysToOmit, description } = props;
|
|
2481
2453
|
const { tree, name } = useSchema();
|
|
@@ -2484,7 +2456,7 @@ function Schema(props) {
|
|
|
2484
2456
|
plugin: {
|
|
2485
2457
|
options: { mapper, enumType, optionalType }
|
|
2486
2458
|
}
|
|
2487
|
-
} =
|
|
2459
|
+
} = useApp();
|
|
2488
2460
|
if (enumType === "asPascalConst") {
|
|
2489
2461
|
pluginManager.logger.emit("warning", `enumType '${enumType}' is deprecated`);
|
|
2490
2462
|
}
|
|
@@ -2502,9 +2474,9 @@ function Schema(props) {
|
|
|
2502
2474
|
if (!tree.length) {
|
|
2503
2475
|
return "";
|
|
2504
2476
|
}
|
|
2505
|
-
const isNullish = tree.some((item) => item.keyword ===
|
|
2506
|
-
const isNullable = tree.some((item) => item.keyword ===
|
|
2507
|
-
const isOptional = tree.some((item) => item.keyword ===
|
|
2477
|
+
const isNullish = tree.some((item) => item.keyword === schemaKeywords.nullish);
|
|
2478
|
+
const isNullable = tree.some((item) => item.keyword === schemaKeywords.nullable);
|
|
2479
|
+
const isOptional = tree.some((item) => item.keyword === schemaKeywords.optional);
|
|
2508
2480
|
let type = tree.map(
|
|
2509
2481
|
(schema) => parse(void 0, schema, {
|
|
2510
2482
|
name: resolvedName,
|
|
@@ -2517,37 +2489,37 @@ function Schema(props) {
|
|
|
2517
2489
|
})
|
|
2518
2490
|
).filter(Boolean).at(0) || typeKeywordMapper.undefined();
|
|
2519
2491
|
if (isNullable) {
|
|
2520
|
-
type =
|
|
2521
|
-
nodes: [type,
|
|
2492
|
+
type = factory.createUnionDeclaration({
|
|
2493
|
+
nodes: [type, factory.keywordTypeNodes.null]
|
|
2522
2494
|
});
|
|
2523
2495
|
}
|
|
2524
2496
|
if (isNullish && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
2525
|
-
type =
|
|
2526
|
-
nodes: [type,
|
|
2497
|
+
type = factory.createUnionDeclaration({
|
|
2498
|
+
nodes: [type, factory.keywordTypeNodes.undefined]
|
|
2527
2499
|
});
|
|
2528
2500
|
}
|
|
2529
2501
|
if (isOptional && ["undefined", "questionTokenAndUndefined"].includes(optionalType)) {
|
|
2530
|
-
type =
|
|
2531
|
-
nodes: [type,
|
|
2502
|
+
type = factory.createUnionDeclaration({
|
|
2503
|
+
nodes: [type, factory.keywordTypeNodes.undefined]
|
|
2532
2504
|
});
|
|
2533
2505
|
}
|
|
2534
|
-
const node =
|
|
2535
|
-
modifiers: [
|
|
2506
|
+
const node = factory.createTypeAliasDeclaration({
|
|
2507
|
+
modifiers: [factory.modifiers.export],
|
|
2536
2508
|
name: resolvedName,
|
|
2537
|
-
type: keysToOmit?.length ?
|
|
2509
|
+
type: keysToOmit?.length ? factory.createOmitDeclaration({
|
|
2538
2510
|
keys: keysToOmit,
|
|
2539
2511
|
type,
|
|
2540
2512
|
nonNullable: true
|
|
2541
2513
|
}) : type
|
|
2542
2514
|
});
|
|
2543
|
-
const enumSchemas = SchemaGenerator.deepSearch(tree,
|
|
2515
|
+
const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords.enum);
|
|
2544
2516
|
const enums = enumSchemas.map((enumSchema) => {
|
|
2545
|
-
const name2 = enumType === "asPascalConst" ?
|
|
2517
|
+
const name2 = enumType === "asPascalConst" ? transformers4.pascalCase(enumSchema.args.name) : transformers4.camelCase(enumSchema.args.name);
|
|
2546
2518
|
const typeName2 = enumSchema.args.typeName;
|
|
2547
|
-
const [nameNode, typeNode] =
|
|
2519
|
+
const [nameNode, typeNode] = factory.createEnumDeclaration({
|
|
2548
2520
|
name: name2,
|
|
2549
2521
|
typeName: typeName2,
|
|
2550
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [
|
|
2522
|
+
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers4.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
|
|
2551
2523
|
type: enumType
|
|
2552
2524
|
});
|
|
2553
2525
|
return {
|
|
@@ -2558,43 +2530,37 @@ function Schema(props) {
|
|
|
2558
2530
|
};
|
|
2559
2531
|
});
|
|
2560
2532
|
typeNodes.push(
|
|
2561
|
-
|
|
2533
|
+
factory.appendJSDocToNode({
|
|
2562
2534
|
node,
|
|
2563
|
-
comments: [description ? `@description ${
|
|
2535
|
+
comments: [description ? `@description ${transformers4.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
2564
2536
|
})
|
|
2565
2537
|
);
|
|
2566
|
-
return /* @__PURE__ */
|
|
2567
|
-
enums.map(({ name: name2, nameNode, typeName: typeName2, typeNode }, index) => /* @__PURE__ */
|
|
2568
|
-
nameNode && /* @__PURE__ */
|
|
2569
|
-
/* @__PURE__ */
|
|
2538
|
+
return /* @__PURE__ */ jsxs(import_react3.Fragment, { children: [
|
|
2539
|
+
enums.map(({ name: name2, nameNode, typeName: typeName2, typeNode }, index) => /* @__PURE__ */ jsxs(import_react3.Fragment, { children: [
|
|
2540
|
+
nameNode && /* @__PURE__ */ jsx(File.Source, { name: name2, isExportable: true, isIndexable: true, children: print(nameNode) }),
|
|
2541
|
+
/* @__PURE__ */ jsx(File.Source, { name: typeName2, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: print(typeNode) })
|
|
2570
2542
|
] }, [name2, nameNode].join("-"))),
|
|
2571
|
-
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */
|
|
2543
|
+
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */ jsx(File.Source, { name: typeName, isTypeOnly: true, isExportable: true, isIndexable: true, children: print(typeNodes) })
|
|
2572
2544
|
] });
|
|
2573
2545
|
}
|
|
2574
2546
|
Schema.File = function({}) {
|
|
2575
|
-
const { pluginManager } =
|
|
2547
|
+
const { pluginManager } = useApp();
|
|
2576
2548
|
const { schema } = useSchema();
|
|
2577
|
-
return /* @__PURE__ */
|
|
2549
|
+
return /* @__PURE__ */ jsx(Oas.Schema.File, { isTypeOnly: true, output: pluginManager.config.output.path, children: /* @__PURE__ */ jsx(Schema, { description: schema?.description }) });
|
|
2578
2550
|
};
|
|
2579
|
-
|
|
2580
|
-
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
2581
|
-
import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
|
|
2582
|
-
var SchemaGenerator2 = class extends Generator {
|
|
2551
|
+
var SchemaGenerator2 = class extends SchemaGenerator {
|
|
2583
2552
|
async schema(name, schema, options) {
|
|
2584
2553
|
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
2585
2554
|
const root = createRoot({
|
|
2586
2555
|
logger: pluginManager.logger
|
|
2587
2556
|
});
|
|
2588
2557
|
const tree = this.parse({ schema, name });
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
);
|
|
2558
|
+
const Component = () => /* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, children: /* @__PURE__ */ jsx(Oas.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx(Schema.File, {}) }) }) });
|
|
2559
|
+
Component.displayName = pascalCase(name);
|
|
2560
|
+
root.render(/* @__PURE__ */ jsx(Component, {}));
|
|
2592
2561
|
return root.files;
|
|
2593
2562
|
}
|
|
2594
2563
|
};
|
|
2595
|
-
|
|
2596
|
-
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
2597
|
-
import { jsx as jsx4, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
|
|
2598
2564
|
function printCombinedSchema({
|
|
2599
2565
|
name,
|
|
2600
2566
|
operation,
|
|
@@ -2608,7 +2574,7 @@ function printCombinedSchema({
|
|
|
2608
2574
|
pluginKey: [pluginTsName],
|
|
2609
2575
|
type: "function"
|
|
2610
2576
|
});
|
|
2611
|
-
properties["response"] =
|
|
2577
|
+
properties["response"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
2612
2578
|
}
|
|
2613
2579
|
if (schemas.request) {
|
|
2614
2580
|
const identifier = pluginManager.resolveName({
|
|
@@ -2616,7 +2582,7 @@ function printCombinedSchema({
|
|
|
2616
2582
|
pluginKey: [pluginTsName],
|
|
2617
2583
|
type: "function"
|
|
2618
2584
|
});
|
|
2619
|
-
properties["request"] =
|
|
2585
|
+
properties["request"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
2620
2586
|
}
|
|
2621
2587
|
if (schemas.pathParams) {
|
|
2622
2588
|
const identifier = pluginManager.resolveName({
|
|
@@ -2624,7 +2590,7 @@ function printCombinedSchema({
|
|
|
2624
2590
|
pluginKey: [pluginTsName],
|
|
2625
2591
|
type: "function"
|
|
2626
2592
|
});
|
|
2627
|
-
properties["pathParams"] =
|
|
2593
|
+
properties["pathParams"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
2628
2594
|
}
|
|
2629
2595
|
if (schemas.queryParams) {
|
|
2630
2596
|
const identifier = pluginManager.resolveName({
|
|
@@ -2632,7 +2598,7 @@ function printCombinedSchema({
|
|
|
2632
2598
|
pluginKey: [pluginTsName],
|
|
2633
2599
|
type: "function"
|
|
2634
2600
|
});
|
|
2635
|
-
properties["queryParams"] =
|
|
2601
|
+
properties["queryParams"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
2636
2602
|
}
|
|
2637
2603
|
if (schemas.headerParams) {
|
|
2638
2604
|
const identifier = pluginManager.resolveName({
|
|
@@ -2640,44 +2606,44 @@ function printCombinedSchema({
|
|
|
2640
2606
|
pluginKey: [pluginTsName],
|
|
2641
2607
|
type: "function"
|
|
2642
2608
|
});
|
|
2643
|
-
properties["headerParams"] =
|
|
2609
|
+
properties["headerParams"] = factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
2644
2610
|
}
|
|
2645
2611
|
if (schemas.errors) {
|
|
2646
|
-
properties["errors"] =
|
|
2612
|
+
properties["errors"] = factory.createUnionDeclaration({
|
|
2647
2613
|
nodes: schemas.errors.map((error) => {
|
|
2648
2614
|
const identifier = pluginManager.resolveName({
|
|
2649
2615
|
name: error.name,
|
|
2650
2616
|
pluginKey: [pluginTsName],
|
|
2651
2617
|
type: "function"
|
|
2652
2618
|
});
|
|
2653
|
-
return
|
|
2619
|
+
return factory.createTypeReferenceNode(factory.createIdentifier(identifier), void 0);
|
|
2654
2620
|
})
|
|
2655
2621
|
});
|
|
2656
2622
|
}
|
|
2657
|
-
const namespaceNode =
|
|
2623
|
+
const namespaceNode = factory.createTypeAliasDeclaration({
|
|
2658
2624
|
name,
|
|
2659
|
-
type:
|
|
2625
|
+
type: factory.createTypeLiteralNode(
|
|
2660
2626
|
Object.keys(properties).map((key) => {
|
|
2661
2627
|
const type = properties[key];
|
|
2662
2628
|
if (!type) {
|
|
2663
2629
|
return void 0;
|
|
2664
2630
|
}
|
|
2665
|
-
return
|
|
2666
|
-
name:
|
|
2631
|
+
return factory.createPropertySignature({
|
|
2632
|
+
name: transformers4.pascalCase(key),
|
|
2667
2633
|
type
|
|
2668
2634
|
});
|
|
2669
2635
|
}).filter(Boolean)
|
|
2670
2636
|
),
|
|
2671
|
-
modifiers: [
|
|
2637
|
+
modifiers: [factory.modifiers.export]
|
|
2672
2638
|
});
|
|
2673
|
-
return
|
|
2639
|
+
return print(namespaceNode);
|
|
2674
2640
|
}
|
|
2675
2641
|
function OperationSchema({ keysToOmit, description }) {
|
|
2676
|
-
return /* @__PURE__ */
|
|
2642
|
+
return /* @__PURE__ */ jsx(Schema, { keysToOmit, description });
|
|
2677
2643
|
}
|
|
2678
2644
|
OperationSchema.File = function({}) {
|
|
2679
|
-
const { pluginManager, plugin, mode } =
|
|
2680
|
-
const oas =
|
|
2645
|
+
const { pluginManager, plugin, mode } = useApp();
|
|
2646
|
+
const oas = useOas();
|
|
2681
2647
|
const { getSchemas, getFile, getName } = useOperationManager();
|
|
2682
2648
|
const operation = useOperation();
|
|
2683
2649
|
const file = getFile(operation);
|
|
@@ -2693,46 +2659,43 @@ OperationSchema.File = function({}) {
|
|
|
2693
2659
|
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
2694
2660
|
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
2695
2661
|
const tree = generator.parse({ schema, name });
|
|
2696
|
-
return /* @__PURE__ */
|
|
2697
|
-
mode === "split" && /* @__PURE__ */
|
|
2698
|
-
/* @__PURE__ */
|
|
2662
|
+
return /* @__PURE__ */ jsxs(Oas.Schema, { name, value: schema, tree, children: [
|
|
2663
|
+
mode === "split" && /* @__PURE__ */ jsx(Oas.Schema.Imports, { isTypeOnly: true }),
|
|
2664
|
+
/* @__PURE__ */ jsx(OperationSchema, { description, keysToOmit })
|
|
2699
2665
|
] }, i);
|
|
2700
2666
|
};
|
|
2701
2667
|
const combinedSchemaName = operation.method === "get" ? `${factoryName}Query` : `${factoryName}Mutation`;
|
|
2702
|
-
return /* @__PURE__ */
|
|
2668
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2703
2669
|
items.map(mapItem),
|
|
2704
|
-
/* @__PURE__ */
|
|
2670
|
+
/* @__PURE__ */ jsx(File.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2705
2671
|
] });
|
|
2706
2672
|
};
|
|
2707
|
-
|
|
2708
|
-
// ../plugin-ts/src/OperationGenerator.tsx
|
|
2709
|
-
import { jsx as jsx5 } from "@kubb/react/jsx-runtime";
|
|
2710
|
-
var OperationGenerator = class extends Generator2 {
|
|
2673
|
+
var OperationGenerator = class extends OperationGenerator$1 {
|
|
2711
2674
|
async all(operations) {
|
|
2712
2675
|
const { oas, pluginManager, plugin, mode } = this.context;
|
|
2713
|
-
const root =
|
|
2676
|
+
const root = createRoot({
|
|
2714
2677
|
logger: pluginManager.logger
|
|
2715
2678
|
});
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
);
|
|
2679
|
+
const Component = () => /* @__PURE__ */ jsx(App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsx(OasType.File, { name: "oas", typeName: "Oas" }) }) });
|
|
2680
|
+
Component.displayName = pascalCase("operations");
|
|
2681
|
+
root.render(/* @__PURE__ */ jsx(Component, {}));
|
|
2719
2682
|
return root.files;
|
|
2720
2683
|
}
|
|
2721
2684
|
async operation(operation, options) {
|
|
2722
2685
|
const { oas, pluginManager, plugin, mode } = this.context;
|
|
2723
|
-
const root =
|
|
2686
|
+
const root = createRoot({
|
|
2724
2687
|
logger: pluginManager.logger
|
|
2725
2688
|
});
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
);
|
|
2689
|
+
const Component = () => /* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx(Oas.Operation, { operation, children: /* @__PURE__ */ jsx(OperationSchema.File, {}) }) }) });
|
|
2690
|
+
Component.displayName = pascalCase(operation.getOperationId());
|
|
2691
|
+
root.render(/* @__PURE__ */ jsx(Component, {}));
|
|
2729
2692
|
return root.files;
|
|
2730
2693
|
}
|
|
2731
2694
|
};
|
|
2732
2695
|
|
|
2733
2696
|
// ../plugin-ts/src/plugin.ts
|
|
2734
2697
|
var pluginTsName = "plugin-ts";
|
|
2735
|
-
|
|
2698
|
+
createPlugin((options) => {
|
|
2736
2699
|
const {
|
|
2737
2700
|
output = { path: "types" },
|
|
2738
2701
|
group,
|
|
@@ -2834,15 +2797,8 @@ var pluginTs = createPlugin((options) => {
|
|
|
2834
2797
|
};
|
|
2835
2798
|
});
|
|
2836
2799
|
|
|
2837
|
-
// src/components/Schema.tsx
|
|
2838
|
-
import transformers6 from "@kubb/core/transformers";
|
|
2839
|
-
import { isKeyword as isKeyword3, schemaKeywords as schemaKeywords5 } from "@kubb/plugin-oas";
|
|
2840
|
-
import { useSchema as useSchema2 } from "@kubb/plugin-oas/hooks";
|
|
2841
|
-
|
|
2842
2800
|
// src/parser/index.ts
|
|
2843
2801
|
init_esm_shims();
|
|
2844
|
-
import transformers4 from "@kubb/core/transformers";
|
|
2845
|
-
import { isKeyword as isKeyword2, schemaKeywords as schemaKeywords3 } from "@kubb/plugin-oas";
|
|
2846
2802
|
var zodKeywordMapper = {
|
|
2847
2803
|
any: () => "z.any()",
|
|
2848
2804
|
unknown: () => "z.unknown()",
|
|
@@ -2938,29 +2894,29 @@ var zodKeywordMapper = {
|
|
|
2938
2894
|
};
|
|
2939
2895
|
function sort(items) {
|
|
2940
2896
|
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
|
-
|
|
2897
|
+
schemaKeywords.string,
|
|
2898
|
+
schemaKeywords.datetime,
|
|
2899
|
+
schemaKeywords.date,
|
|
2900
|
+
schemaKeywords.time,
|
|
2901
|
+
schemaKeywords.tuple,
|
|
2902
|
+
schemaKeywords.number,
|
|
2903
|
+
schemaKeywords.object,
|
|
2904
|
+
schemaKeywords.enum,
|
|
2905
|
+
schemaKeywords.url,
|
|
2906
|
+
schemaKeywords.email,
|
|
2907
|
+
schemaKeywords.firstName,
|
|
2908
|
+
schemaKeywords.lastName,
|
|
2909
|
+
schemaKeywords.password,
|
|
2910
|
+
schemaKeywords.matches,
|
|
2911
|
+
schemaKeywords.uuid,
|
|
2912
|
+
schemaKeywords.min,
|
|
2913
|
+
schemaKeywords.max,
|
|
2914
|
+
schemaKeywords.default,
|
|
2915
|
+
schemaKeywords.describe,
|
|
2916
|
+
schemaKeywords.optional,
|
|
2917
|
+
schemaKeywords.nullable,
|
|
2918
|
+
schemaKeywords.nullish,
|
|
2919
|
+
schemaKeywords.null
|
|
2964
2920
|
];
|
|
2965
2921
|
if (!items) {
|
|
2966
2922
|
return [];
|
|
@@ -2972,7 +2928,7 @@ function parse2(parent, current, options) {
|
|
|
2972
2928
|
if (!value) {
|
|
2973
2929
|
return void 0;
|
|
2974
2930
|
}
|
|
2975
|
-
if (
|
|
2931
|
+
if (isKeyword(current, schemaKeywords.union)) {
|
|
2976
2932
|
if (Array.isArray(current.args) && current.args.length === 1) {
|
|
2977
2933
|
return parse2(parent, current.args[0], options);
|
|
2978
2934
|
}
|
|
@@ -2983,27 +2939,27 @@ function parse2(parent, current, options) {
|
|
|
2983
2939
|
sort(current.args).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
2984
2940
|
);
|
|
2985
2941
|
}
|
|
2986
|
-
if (
|
|
2942
|
+
if (isKeyword(current, schemaKeywords.and)) {
|
|
2987
2943
|
const items = sort(current.args).filter((schema) => {
|
|
2988
|
-
return ![
|
|
2944
|
+
return ![schemaKeywords.optional, schemaKeywords.describe].includes(schema.keyword);
|
|
2989
2945
|
}).map((schema) => parse2(current, schema, options)).filter(Boolean);
|
|
2990
2946
|
return `${items.slice(0, 1)}${zodKeywordMapper.and(items.slice(1))}`;
|
|
2991
2947
|
}
|
|
2992
|
-
if (
|
|
2948
|
+
if (isKeyword(current, schemaKeywords.array)) {
|
|
2993
2949
|
return zodKeywordMapper.array(
|
|
2994
2950
|
sort(current.args.items).map((schemas) => parse2(current, schemas, options)).filter(Boolean),
|
|
2995
2951
|
current.args.min,
|
|
2996
2952
|
current.args.max
|
|
2997
2953
|
);
|
|
2998
2954
|
}
|
|
2999
|
-
if (
|
|
2955
|
+
if (isKeyword(current, schemaKeywords.enum)) {
|
|
3000
2956
|
if (current.args.asConst) {
|
|
3001
2957
|
return zodKeywordMapper.union(
|
|
3002
2958
|
current.args.items.map((schema) => {
|
|
3003
2959
|
return parse2(
|
|
3004
2960
|
current,
|
|
3005
2961
|
{
|
|
3006
|
-
keyword:
|
|
2962
|
+
keyword: schemaKeywords.const,
|
|
3007
2963
|
args: schema
|
|
3008
2964
|
},
|
|
3009
2965
|
options
|
|
@@ -3020,15 +2976,15 @@ function parse2(parent, current, options) {
|
|
|
3020
2976
|
})
|
|
3021
2977
|
);
|
|
3022
2978
|
}
|
|
3023
|
-
if (
|
|
2979
|
+
if (isKeyword(current, schemaKeywords.ref)) {
|
|
3024
2980
|
return zodKeywordMapper.ref(current.args?.name);
|
|
3025
2981
|
}
|
|
3026
|
-
if (
|
|
2982
|
+
if (isKeyword(current, schemaKeywords.object)) {
|
|
3027
2983
|
const properties = Object.entries(current.args?.properties || {}).filter((item) => {
|
|
3028
2984
|
const schema = item[1];
|
|
3029
2985
|
return schema && typeof schema.map === "function";
|
|
3030
2986
|
}).map(([name, schemas]) => {
|
|
3031
|
-
const nameSchema = schemas.find((schema) => schema.keyword ===
|
|
2987
|
+
const nameSchema = schemas.find((schema) => schema.keyword === schemaKeywords.name);
|
|
3032
2988
|
const mappedName = nameSchema?.args || name;
|
|
3033
2989
|
if (options.mapper?.[mappedName]) {
|
|
3034
2990
|
return `"${name}": ${options.mapper?.[mappedName]}`;
|
|
@@ -3045,54 +3001,54 @@ function parse2(parent, current, options) {
|
|
|
3045
3001
|
].filter(Boolean);
|
|
3046
3002
|
return text.join("");
|
|
3047
3003
|
}
|
|
3048
|
-
if (
|
|
3004
|
+
if (isKeyword(current, schemaKeywords.tuple)) {
|
|
3049
3005
|
return zodKeywordMapper.tuple(
|
|
3050
3006
|
sort(current.args.items).map((schema) => parse2(current, schema, options)).filter(Boolean)
|
|
3051
3007
|
);
|
|
3052
3008
|
}
|
|
3053
|
-
if (
|
|
3009
|
+
if (isKeyword(current, schemaKeywords.const)) {
|
|
3054
3010
|
if (current.args.format === "number" && current.args.value !== void 0) {
|
|
3055
3011
|
return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
|
|
3056
3012
|
}
|
|
3057
3013
|
return zodKeywordMapper.const(transformers4.stringify(current.args.value));
|
|
3058
3014
|
}
|
|
3059
|
-
if (
|
|
3015
|
+
if (isKeyword(current, schemaKeywords.matches)) {
|
|
3060
3016
|
if (current.args) {
|
|
3061
3017
|
return zodKeywordMapper.matches(transformers4.toRegExpString(current.args));
|
|
3062
3018
|
}
|
|
3063
3019
|
}
|
|
3064
|
-
if (
|
|
3020
|
+
if (isKeyword(current, schemaKeywords.default)) {
|
|
3065
3021
|
if (current.args) {
|
|
3066
3022
|
return zodKeywordMapper.default(current.args);
|
|
3067
3023
|
}
|
|
3068
3024
|
}
|
|
3069
|
-
if (
|
|
3025
|
+
if (isKeyword(current, schemaKeywords.describe)) {
|
|
3070
3026
|
if (current.args) {
|
|
3071
3027
|
return zodKeywordMapper.describe(transformers4.stringify(current.args.toString()));
|
|
3072
3028
|
}
|
|
3073
3029
|
}
|
|
3074
|
-
if (
|
|
3030
|
+
if (isKeyword(current, schemaKeywords.string)) {
|
|
3075
3031
|
return zodKeywordMapper.string(options.coercion);
|
|
3076
3032
|
}
|
|
3077
|
-
if (
|
|
3033
|
+
if (isKeyword(current, schemaKeywords.number)) {
|
|
3078
3034
|
return zodKeywordMapper.number(options.coercion);
|
|
3079
3035
|
}
|
|
3080
|
-
if (
|
|
3036
|
+
if (isKeyword(current, schemaKeywords.integer)) {
|
|
3081
3037
|
return zodKeywordMapper.integer(options.coercion);
|
|
3082
3038
|
}
|
|
3083
|
-
if (
|
|
3039
|
+
if (isKeyword(current, schemaKeywords.min)) {
|
|
3084
3040
|
return zodKeywordMapper.min(current.args);
|
|
3085
3041
|
}
|
|
3086
|
-
if (
|
|
3042
|
+
if (isKeyword(current, schemaKeywords.max)) {
|
|
3087
3043
|
return zodKeywordMapper.max(current.args);
|
|
3088
3044
|
}
|
|
3089
|
-
if (
|
|
3045
|
+
if (isKeyword(current, schemaKeywords.datetime)) {
|
|
3090
3046
|
return zodKeywordMapper.datetime(current.args.offset, current.args.local);
|
|
3091
3047
|
}
|
|
3092
|
-
if (
|
|
3048
|
+
if (isKeyword(current, schemaKeywords.date)) {
|
|
3093
3049
|
return zodKeywordMapper.date(current.args.type, options.coercion);
|
|
3094
3050
|
}
|
|
3095
|
-
if (
|
|
3051
|
+
if (isKeyword(current, schemaKeywords.time)) {
|
|
3096
3052
|
return zodKeywordMapper.time(current.args.type, options.coercion);
|
|
3097
3053
|
}
|
|
3098
3054
|
if (current.keyword in zodKeywordMapper && "args" in current) {
|
|
@@ -3107,34 +3063,23 @@ function parse2(parent, current, options) {
|
|
|
3107
3063
|
|
|
3108
3064
|
// src/plugin.ts
|
|
3109
3065
|
init_esm_shims();
|
|
3110
|
-
import path2 from "node:path";
|
|
3111
|
-
import { FileManager as FileManager2, PluginManager as PluginManager2, createPlugin as createPlugin2 } from "@kubb/core";
|
|
3112
|
-
import { camelCase as camelCase2, pascalCase as pascalCase2 } from "@kubb/core/transformers";
|
|
3113
|
-
import { renderTemplate as renderTemplate2 } from "@kubb/core/utils";
|
|
3114
|
-
import { OperationGenerator as OperationGenerator2, SchemaGenerator as SchemaGenerator4, pluginOasName as pluginOasName2 } from "@kubb/plugin-oas";
|
|
3115
3066
|
|
|
3116
3067
|
// src/SchemaGenerator.tsx
|
|
3117
3068
|
init_esm_shims();
|
|
3118
|
-
import { createReactGenerator } from "@kubb/plugin-oas";
|
|
3119
3069
|
|
|
3120
3070
|
// src/components/OperationSchema.tsx
|
|
3121
3071
|
init_esm_shims();
|
|
3122
|
-
import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
|
|
3123
|
-
import { Oas as Oas5 } from "@kubb/plugin-oas/components";
|
|
3124
|
-
import { useOas as useOas3, useOperation as useOperation2, useOperationManager as useOperationManager2 } from "@kubb/plugin-oas/hooks";
|
|
3125
|
-
import { File as File4, useApp as useApp4 } from "@kubb/react";
|
|
3126
|
-
import { jsx as jsx6, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
|
|
3127
3072
|
function OperationSchema2({ description, keysToOmit }) {
|
|
3128
|
-
return /* @__PURE__ */
|
|
3073
|
+
return /* @__PURE__ */ jsx(Schema2, { keysToOmit, withTypeAnnotation: false, description });
|
|
3129
3074
|
}
|
|
3130
3075
|
OperationSchema2.File = function({}) {
|
|
3131
|
-
const { pluginManager, plugin, mode } =
|
|
3132
|
-
const { getSchemas, getFile } =
|
|
3133
|
-
const oas =
|
|
3134
|
-
const operation =
|
|
3076
|
+
const { pluginManager, plugin, mode } = useApp();
|
|
3077
|
+
const { getSchemas, getFile } = useOperationManager();
|
|
3078
|
+
const oas = useOas();
|
|
3079
|
+
const operation = useOperation();
|
|
3135
3080
|
const file = getFile(operation);
|
|
3136
3081
|
const schemas = getSchemas(operation);
|
|
3137
|
-
const generator = new
|
|
3082
|
+
const generator = new SchemaGenerator(plugin.options, {
|
|
3138
3083
|
oas,
|
|
3139
3084
|
plugin,
|
|
3140
3085
|
pluginManager,
|
|
@@ -3146,25 +3091,21 @@ OperationSchema2.File = function({}) {
|
|
|
3146
3091
|
const required = Array.isArray(schema?.required) ? !!schema.required.length : !!schema?.required;
|
|
3147
3092
|
const optional = !required && !!name.includes("Params");
|
|
3148
3093
|
const tree = generator.parse({ schema, name });
|
|
3149
|
-
return /* @__PURE__ */
|
|
3150
|
-
mode === "split" && /* @__PURE__ */
|
|
3151
|
-
/* @__PURE__ */
|
|
3094
|
+
return /* @__PURE__ */ jsxs(Oas.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords.optional } : void 0].filter(Boolean), children: [
|
|
3095
|
+
mode === "split" && /* @__PURE__ */ jsx(Oas.Schema.Imports, { isTypeOnly: false }),
|
|
3096
|
+
/* @__PURE__ */ jsx(OperationSchema2, { description, keysToOmit })
|
|
3152
3097
|
] }, i);
|
|
3153
3098
|
};
|
|
3154
|
-
return /* @__PURE__ */
|
|
3155
|
-
/* @__PURE__ */
|
|
3099
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3100
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: plugin.options.importPath }),
|
|
3156
3101
|
items.map(mapItem)
|
|
3157
3102
|
] });
|
|
3158
3103
|
};
|
|
3159
3104
|
|
|
3160
3105
|
// src/components/Operations.tsx
|
|
3161
3106
|
init_esm_shims();
|
|
3162
|
-
import { useOperationManager as useOperationManager3, useOperations } from "@kubb/plugin-oas/hooks";
|
|
3163
|
-
import { Const, File as File5, useApp as useApp5 } from "@kubb/react";
|
|
3164
|
-
import transformers5 from "@kubb/core/transformers";
|
|
3165
|
-
import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs5 } from "@kubb/react/jsx-runtime";
|
|
3166
3107
|
function Template2({ operationsName, pathsName, operations }) {
|
|
3167
|
-
const { groupSchemasByName } =
|
|
3108
|
+
const { groupSchemasByName } = useOperationManager();
|
|
3168
3109
|
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
3169
3110
|
const operationsJSON = transformedOperations.reduce(
|
|
3170
3111
|
(prev, acc) => {
|
|
@@ -3183,9 +3124,9 @@ function Template2({ operationsName, pathsName, operations }) {
|
|
|
3183
3124
|
},
|
|
3184
3125
|
{}
|
|
3185
3126
|
);
|
|
3186
|
-
return /* @__PURE__ */
|
|
3187
|
-
/* @__PURE__ */
|
|
3188
|
-
/* @__PURE__ */
|
|
3127
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3128
|
+
/* @__PURE__ */ jsx(File.Source, { name: operationsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers4.stringifyObject(operationsJSON)}}` }) }),
|
|
3129
|
+
/* @__PURE__ */ jsx(File.Source, { name: pathsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers4.stringifyObject(pathsJSON)}}` }) })
|
|
3189
3130
|
] });
|
|
3190
3131
|
}
|
|
3191
3132
|
function RootTemplate({ children }) {
|
|
@@ -3196,17 +3137,17 @@ function RootTemplate({ children }) {
|
|
|
3196
3137
|
key: pluginKey,
|
|
3197
3138
|
options: { extName }
|
|
3198
3139
|
}
|
|
3199
|
-
} =
|
|
3200
|
-
const { getFile } =
|
|
3140
|
+
} = useApp();
|
|
3141
|
+
const { getFile } = useOperationManager();
|
|
3201
3142
|
const operations = useOperations();
|
|
3202
|
-
const { groupSchemasByName } =
|
|
3143
|
+
const { groupSchemasByName } = useOperationManager();
|
|
3203
3144
|
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
3204
3145
|
const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
|
|
3205
3146
|
const imports = Object.entries(transformedOperations).map(([key, { data, operation }]) => {
|
|
3206
3147
|
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
3207
|
-
return /* @__PURE__ */
|
|
3148
|
+
return /* @__PURE__ */ jsx(File.Import, { name: names, root: file.path, path: getFile(operation).path }, key);
|
|
3208
3149
|
}).filter(Boolean);
|
|
3209
|
-
return /* @__PURE__ */
|
|
3150
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3210
3151
|
mode === "split" && imports,
|
|
3211
3152
|
children
|
|
3212
3153
|
] });
|
|
@@ -3214,37 +3155,34 @@ function RootTemplate({ children }) {
|
|
|
3214
3155
|
var defaultTemplates2 = { default: Template2, root: RootTemplate };
|
|
3215
3156
|
function Operations({ Template: Template3 = defaultTemplates2.default }) {
|
|
3216
3157
|
const operations = useOperations();
|
|
3217
|
-
return /* @__PURE__ */
|
|
3158
|
+
return /* @__PURE__ */ jsx(Template3, { operationsName: "operations", pathsName: "paths", operations });
|
|
3218
3159
|
}
|
|
3219
3160
|
Operations.File = function(props) {
|
|
3220
3161
|
const templates = { ...defaultTemplates2, ...props.templates };
|
|
3221
3162
|
const Template3 = templates.default;
|
|
3222
3163
|
const RootTemplate2 = templates.root;
|
|
3223
|
-
return /* @__PURE__ */
|
|
3164
|
+
return /* @__PURE__ */ jsx(RootTemplate2, { children: /* @__PURE__ */ jsx(Operations, { Template: Template3 }) });
|
|
3224
3165
|
};
|
|
3225
3166
|
Operations.templates = defaultTemplates2;
|
|
3226
|
-
|
|
3227
|
-
// src/SchemaGenerator.tsx
|
|
3228
|
-
import { jsx as jsx8 } from "@kubb/react/jsx-runtime";
|
|
3229
3167
|
var zodParser = createReactGenerator({
|
|
3230
3168
|
name: "plugin-zod",
|
|
3231
3169
|
Operations({ options }) {
|
|
3232
3170
|
if (!options.templates.operations) {
|
|
3233
3171
|
return null;
|
|
3234
3172
|
}
|
|
3235
|
-
return /* @__PURE__ */
|
|
3173
|
+
return /* @__PURE__ */ jsx(Operations.File, { templates: options.templates.operations });
|
|
3236
3174
|
},
|
|
3237
3175
|
Operation() {
|
|
3238
|
-
return /* @__PURE__ */
|
|
3176
|
+
return /* @__PURE__ */ jsx(OperationSchema2.File, {});
|
|
3239
3177
|
},
|
|
3240
3178
|
Schema({ schema, name }) {
|
|
3241
|
-
return /* @__PURE__ */
|
|
3179
|
+
return /* @__PURE__ */ jsx(Schema2.File, {});
|
|
3242
3180
|
}
|
|
3243
3181
|
});
|
|
3244
3182
|
|
|
3245
3183
|
// src/plugin.ts
|
|
3246
3184
|
var pluginZodName = "plugin-zod";
|
|
3247
|
-
var pluginZod =
|
|
3185
|
+
var pluginZod = createPlugin((options) => {
|
|
3248
3186
|
const {
|
|
3249
3187
|
output = { path: "zod" },
|
|
3250
3188
|
group,
|
|
@@ -3286,26 +3224,26 @@ var pluginZod = createPlugin2((options) => {
|
|
|
3286
3224
|
...templates
|
|
3287
3225
|
}
|
|
3288
3226
|
},
|
|
3289
|
-
pre: [
|
|
3227
|
+
pre: [pluginOasName, typed ? pluginTsName : void 0].filter(Boolean),
|
|
3290
3228
|
resolvePath(baseName, pathMode, options2) {
|
|
3291
|
-
const root =
|
|
3292
|
-
const mode = pathMode ??
|
|
3229
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
3230
|
+
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
3293
3231
|
if (mode === "single") {
|
|
3294
|
-
return
|
|
3232
|
+
return path.resolve(root, output.path);
|
|
3295
3233
|
}
|
|
3296
3234
|
if (options2?.tag && group?.type === "tag") {
|
|
3297
|
-
const tag =
|
|
3298
|
-
return
|
|
3235
|
+
const tag = camelCase(options2.tag);
|
|
3236
|
+
return path.resolve(root, renderTemplate(template, { tag }), baseName);
|
|
3299
3237
|
}
|
|
3300
|
-
return
|
|
3238
|
+
return path.resolve(root, output.path, baseName);
|
|
3301
3239
|
},
|
|
3302
3240
|
resolveName(name, type) {
|
|
3303
|
-
let resolvedName =
|
|
3241
|
+
let resolvedName = camelCase(name, {
|
|
3304
3242
|
suffix: type ? "schema" : void 0,
|
|
3305
3243
|
isFile: type === "file"
|
|
3306
3244
|
});
|
|
3307
3245
|
if (type === "type") {
|
|
3308
|
-
resolvedName =
|
|
3246
|
+
resolvedName = pascalCase(resolvedName);
|
|
3309
3247
|
}
|
|
3310
3248
|
if (type) {
|
|
3311
3249
|
return transformers7?.name?.(resolvedName, type) || resolvedName;
|
|
@@ -3313,11 +3251,11 @@ var pluginZod = createPlugin2((options) => {
|
|
|
3313
3251
|
return resolvedName;
|
|
3314
3252
|
},
|
|
3315
3253
|
async buildStart() {
|
|
3316
|
-
const [swaggerPlugin] =
|
|
3254
|
+
const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
|
|
3317
3255
|
const oas = await swaggerPlugin.context.getOas();
|
|
3318
|
-
const root =
|
|
3319
|
-
const mode =
|
|
3320
|
-
const schemaGenerator = new
|
|
3256
|
+
const root = path.resolve(this.config.root, this.config.output.path);
|
|
3257
|
+
const mode = FileManager.getMode(path.resolve(root, output.path));
|
|
3258
|
+
const schemaGenerator = new SchemaGenerator(this.plugin.options, {
|
|
3321
3259
|
oas,
|
|
3322
3260
|
pluginManager: this.pluginManager,
|
|
3323
3261
|
plugin: this.plugin,
|
|
@@ -3329,7 +3267,7 @@ var pluginZod = createPlugin2((options) => {
|
|
|
3329
3267
|
});
|
|
3330
3268
|
const schemaFiles = await schemaGenerator.build(zodParser);
|
|
3331
3269
|
await this.addFile(...schemaFiles);
|
|
3332
|
-
const operationGenerator = new
|
|
3270
|
+
const operationGenerator = new OperationGenerator$1(this.plugin.options, {
|
|
3333
3271
|
oas,
|
|
3334
3272
|
pluginManager: this.pluginManager,
|
|
3335
3273
|
plugin: this.plugin,
|
|
@@ -3356,18 +3294,15 @@ var pluginZod = createPlugin2((options) => {
|
|
|
3356
3294
|
}
|
|
3357
3295
|
};
|
|
3358
3296
|
});
|
|
3359
|
-
|
|
3360
|
-
// src/components/Schema.tsx
|
|
3361
|
-
import { Fragment as Fragment4, jsx as jsx9, jsxs as jsxs6 } from "@kubb/react/jsx-runtime";
|
|
3362
3297
|
function Schema2(props) {
|
|
3363
3298
|
const { keysToOmit, withTypeAnnotation, description } = props;
|
|
3364
|
-
const { tree, name } =
|
|
3299
|
+
const { tree, name } = useSchema();
|
|
3365
3300
|
const {
|
|
3366
3301
|
pluginManager,
|
|
3367
3302
|
plugin: {
|
|
3368
3303
|
options: { mapper, typedSchema, coercion }
|
|
3369
3304
|
}
|
|
3370
|
-
} =
|
|
3305
|
+
} = useApp();
|
|
3371
3306
|
const resolvedName = pluginManager.resolveName({
|
|
3372
3307
|
name,
|
|
3373
3308
|
pluginKey: [pluginZodName],
|
|
@@ -3384,34 +3319,34 @@ function Schema2(props) {
|
|
|
3384
3319
|
type: "type"
|
|
3385
3320
|
});
|
|
3386
3321
|
if (!tree.length) {
|
|
3387
|
-
return /* @__PURE__ */
|
|
3388
|
-
|
|
3322
|
+
return /* @__PURE__ */ jsx(File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
|
|
3323
|
+
Const,
|
|
3389
3324
|
{
|
|
3390
3325
|
name: resolvedName,
|
|
3391
3326
|
export: true,
|
|
3392
3327
|
JSDoc: {
|
|
3393
|
-
comments: [description ? `@description ${
|
|
3328
|
+
comments: [description ? `@description ${transformers4.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
3394
3329
|
},
|
|
3395
3330
|
children: "undefined"
|
|
3396
3331
|
}
|
|
3397
3332
|
) });
|
|
3398
3333
|
}
|
|
3399
|
-
const hasTuple = tree.some((item) =>
|
|
3334
|
+
const hasTuple = tree.some((item) => isKeyword(item, schemaKeywords.tuple));
|
|
3400
3335
|
const output = sort(tree).filter((item) => {
|
|
3401
|
-
if (hasTuple && (
|
|
3336
|
+
if (hasTuple && (isKeyword(item, schemaKeywords.min) || isKeyword(item, schemaKeywords.max))) {
|
|
3402
3337
|
return false;
|
|
3403
3338
|
}
|
|
3404
3339
|
return true;
|
|
3405
3340
|
}).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
|
|
3406
3341
|
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
3407
|
-
return /* @__PURE__ */
|
|
3408
|
-
/* @__PURE__ */
|
|
3409
|
-
|
|
3342
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3343
|
+
/* @__PURE__ */ jsx(File.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(
|
|
3344
|
+
Const,
|
|
3410
3345
|
{
|
|
3411
3346
|
export: true,
|
|
3412
3347
|
name: resolvedName,
|
|
3413
3348
|
JSDoc: {
|
|
3414
|
-
comments: [description ? `@description ${
|
|
3349
|
+
comments: [description ? `@description ${transformers4.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
3415
3350
|
},
|
|
3416
3351
|
children: [
|
|
3417
3352
|
output,
|
|
@@ -3420,7 +3355,7 @@ function Schema2(props) {
|
|
|
3420
3355
|
].filter(Boolean).join("") || ""
|
|
3421
3356
|
}
|
|
3422
3357
|
) }),
|
|
3423
|
-
typedSchema && /* @__PURE__ */
|
|
3358
|
+
typedSchema && /* @__PURE__ */ jsx(File.Source, { name: resolvedTypeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx(Type, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` }) })
|
|
3424
3359
|
] });
|
|
3425
3360
|
}
|
|
3426
3361
|
Schema2.File = function({}) {
|
|
@@ -3429,12 +3364,12 @@ Schema2.File = function({}) {
|
|
|
3429
3364
|
plugin: {
|
|
3430
3365
|
options: { typed }
|
|
3431
3366
|
}
|
|
3432
|
-
} =
|
|
3433
|
-
const { schema } =
|
|
3367
|
+
} = useApp();
|
|
3368
|
+
const { schema } = useSchema();
|
|
3434
3369
|
const withTypeAnnotation = !!typed;
|
|
3435
|
-
return /* @__PURE__ */
|
|
3436
|
-
/* @__PURE__ */
|
|
3437
|
-
/* @__PURE__ */
|
|
3370
|
+
return /* @__PURE__ */ jsxs(Oas.Schema.File, { output: pluginManager.config.output.path, children: [
|
|
3371
|
+
/* @__PURE__ */ jsx(Schema2.Imports, {}),
|
|
3372
|
+
/* @__PURE__ */ jsx(Schema2, { withTypeAnnotation, description: schema?.description })
|
|
3438
3373
|
] });
|
|
3439
3374
|
};
|
|
3440
3375
|
Schema2.Imports = () => {
|
|
@@ -3443,9 +3378,9 @@ Schema2.Imports = () => {
|
|
|
3443
3378
|
plugin: {
|
|
3444
3379
|
options: { typed, importPath }
|
|
3445
3380
|
}
|
|
3446
|
-
} =
|
|
3381
|
+
} = useApp();
|
|
3447
3382
|
const { path: root } = useFile();
|
|
3448
|
-
const { name, tree, schema } =
|
|
3383
|
+
const { name, tree, schema } = useSchema();
|
|
3449
3384
|
const typeName = pluginManager.resolveName({
|
|
3450
3385
|
name,
|
|
3451
3386
|
pluginKey: [pluginTsName],
|
|
@@ -3461,20 +3396,11 @@ Schema2.Imports = () => {
|
|
|
3461
3396
|
pluginKey: [pluginTsName]
|
|
3462
3397
|
});
|
|
3463
3398
|
const withTypeAnnotation = !!typed;
|
|
3464
|
-
return /* @__PURE__ */
|
|
3465
|
-
/* @__PURE__ */
|
|
3466
|
-
withTypeAnnotation && typeName && typePath && /* @__PURE__ */
|
|
3399
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3400
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["z"], path: importPath }),
|
|
3401
|
+
withTypeAnnotation && typeName && typePath && /* @__PURE__ */ jsx(File.Import, { isTypeOnly: true, root, path: typePath, name: [typeName] })
|
|
3467
3402
|
] });
|
|
3468
3403
|
};
|
|
3469
|
-
|
|
3470
|
-
export {
|
|
3471
|
-
init_esm_shims,
|
|
3472
|
-
Schema2 as Schema,
|
|
3473
|
-
OperationSchema2 as OperationSchema,
|
|
3474
|
-
Operations,
|
|
3475
|
-
pluginZodName,
|
|
3476
|
-
pluginZod
|
|
3477
|
-
};
|
|
3478
3404
|
/*! Bundled license information:
|
|
3479
3405
|
|
|
3480
3406
|
react/cjs/react.production.min.js:
|
|
@@ -3499,4 +3425,7 @@ react/cjs/react.development.js:
|
|
|
3499
3425
|
* LICENSE file in the root directory of this source tree.
|
|
3500
3426
|
*)
|
|
3501
3427
|
*/
|
|
3502
|
-
|
|
3428
|
+
|
|
3429
|
+
export { OperationSchema2 as OperationSchema, Operations, Schema2 as Schema, init_esm_shims, pluginZod, pluginZodName };
|
|
3430
|
+
//# sourceMappingURL=chunk-BWE5OHCP.js.map
|
|
3431
|
+
//# sourceMappingURL=chunk-BWE5OHCP.js.map
|