@kubb/plugin-zod 3.0.0-alpha.6 → 3.0.0-alpha.8
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-PMYJN6KG.js → chunk-CD3EZWBX.js} +162 -146
- package/dist/chunk-CD3EZWBX.js.map +1 -0
- package/dist/{chunk-INEB36EJ.cjs → chunk-TSJ74266.cjs} +121 -105
- package/dist/chunk-TSJ74266.cjs.map +1 -0
- package/dist/components.cjs +3 -3
- package/dist/components.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.js +1 -1
- package/package.json +12 -12
- package/src/components/OperationSchema.tsx +1 -1
- package/src/components/Operations.tsx +2 -2
- package/src/components/Schema.tsx +3 -3
- package/src/components/__snapshots__/operations.ts +8 -8
- package/src/plugin.ts +12 -6
- package/dist/chunk-INEB36EJ.cjs.map +0 -1
- package/dist/chunk-PMYJN6KG.js.map +0 -1
|
@@ -27,9 +27,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
mod
|
|
28
28
|
));
|
|
29
29
|
|
|
30
|
-
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
30
|
+
// ../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__jiti@1.21.6_postcss@8.4.41_typescript@5.5.4_yaml@2.4.5/node_modules/tsup/assets/esm_shims.js
|
|
31
31
|
var init_esm_shims = __esm({
|
|
32
|
-
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.
|
|
32
|
+
"../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.47.7_@types+node@20.16.2__jiti@1.21.6_postcss@8.4.41_typescript@5.5.4_yaml@2.4.5/node_modules/tsup/assets/esm_shims.js"() {
|
|
33
33
|
"use strict";
|
|
34
34
|
}
|
|
35
35
|
});
|
|
@@ -2196,73 +2196,6 @@ var require_react = __commonJS({
|
|
|
2196
2196
|
}
|
|
2197
2197
|
});
|
|
2198
2198
|
|
|
2199
|
-
// src/components/Operations.tsx
|
|
2200
|
-
init_esm_shims();
|
|
2201
|
-
import { useOperationManager, useOperations } from "@kubb/plugin-oas/hooks";
|
|
2202
|
-
import { Const, File, useApp } from "@kubb/react";
|
|
2203
|
-
import transformers from "@kubb/core/transformers";
|
|
2204
|
-
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
2205
|
-
function Template({ operationsName, pathsName, operations }) {
|
|
2206
|
-
const { groupSchemasByName } = useOperationManager();
|
|
2207
|
-
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
2208
|
-
const operationsJSON = transformedOperations.reduce(
|
|
2209
|
-
(prev, acc) => {
|
|
2210
|
-
prev[`"${acc.operation.getOperationId()}"`] = acc.data;
|
|
2211
|
-
return prev;
|
|
2212
|
-
},
|
|
2213
|
-
{}
|
|
2214
|
-
);
|
|
2215
|
-
const pathsJSON = transformedOperations.reduce(
|
|
2216
|
-
(prev, acc) => {
|
|
2217
|
-
prev[`"${acc.operation.path}"`] = {
|
|
2218
|
-
...prev[`"${acc.operation.path}"`] || {},
|
|
2219
|
-
[acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
|
|
2220
|
-
};
|
|
2221
|
-
return prev;
|
|
2222
|
-
},
|
|
2223
|
-
{}
|
|
2224
|
-
);
|
|
2225
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2226
|
-
/* @__PURE__ */ jsx(File.Source, { name: operationsName, isExportable: true, children: /* @__PURE__ */ jsx(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers.stringifyObject(operationsJSON)}}` }) }),
|
|
2227
|
-
/* @__PURE__ */ jsx(File.Source, { name: pathsName, isExportable: true, children: /* @__PURE__ */ jsx(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers.stringifyObject(pathsJSON)}}` }) })
|
|
2228
|
-
] });
|
|
2229
|
-
}
|
|
2230
|
-
function RootTemplate({ children }) {
|
|
2231
|
-
const {
|
|
2232
|
-
mode,
|
|
2233
|
-
pluginManager,
|
|
2234
|
-
plugin: {
|
|
2235
|
-
key: pluginKey,
|
|
2236
|
-
options: { extName }
|
|
2237
|
-
}
|
|
2238
|
-
} = useApp();
|
|
2239
|
-
const { getFile } = useOperationManager();
|
|
2240
|
-
const operations = useOperations();
|
|
2241
|
-
const { groupSchemasByName } = useOperationManager();
|
|
2242
|
-
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
2243
|
-
const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
|
|
2244
|
-
const imports = Object.entries(transformedOperations).map(([_key, { data, operation }], index) => {
|
|
2245
|
-
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
2246
|
-
return /* @__PURE__ */ jsx(File.Import, { name: names, root: file.path, path: getFile(operation).path }, index);
|
|
2247
|
-
}).filter(Boolean);
|
|
2248
|
-
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2249
|
-
mode === "split" && imports,
|
|
2250
|
-
children
|
|
2251
|
-
] });
|
|
2252
|
-
}
|
|
2253
|
-
var defaultTemplates = { default: Template, root: RootTemplate };
|
|
2254
|
-
function Operations({ Template: Template3 = defaultTemplates.default }) {
|
|
2255
|
-
const operations = useOperations();
|
|
2256
|
-
return /* @__PURE__ */ jsx(Template3, { operationsName: "operations", pathsName: "paths", operations });
|
|
2257
|
-
}
|
|
2258
|
-
Operations.File = function(props) {
|
|
2259
|
-
const templates = { ...defaultTemplates, ...props.templates };
|
|
2260
|
-
const Template3 = templates.default;
|
|
2261
|
-
const RootTemplate2 = templates.root;
|
|
2262
|
-
return /* @__PURE__ */ jsx(RootTemplate2, { children: /* @__PURE__ */ jsx(Operations, { Template: Template3 }) });
|
|
2263
|
-
};
|
|
2264
|
-
Operations.templates = defaultTemplates;
|
|
2265
|
-
|
|
2266
2199
|
// src/components/Schema.tsx
|
|
2267
2200
|
init_esm_shims();
|
|
2268
2201
|
import { Oas as Oas6 } from "@kubb/plugin-oas/components";
|
|
@@ -2273,7 +2206,7 @@ init_esm_shims();
|
|
|
2273
2206
|
|
|
2274
2207
|
// ../plugin-ts/src/plugin.ts
|
|
2275
2208
|
init_esm_shims();
|
|
2276
|
-
import path from "path";
|
|
2209
|
+
import path from "node:path";
|
|
2277
2210
|
import { FileManager, PluginManager, createPlugin } from "@kubb/core";
|
|
2278
2211
|
import { camelCase, pascalCase } from "@kubb/core/transformers";
|
|
2279
2212
|
import { renderTemplate } from "@kubb/core/utils";
|
|
@@ -2287,43 +2220,43 @@ import { App as App2, createRoot as createRoot2 } from "@kubb/react";
|
|
|
2287
2220
|
|
|
2288
2221
|
// ../plugin-ts/src/components/OasType.tsx
|
|
2289
2222
|
init_esm_shims();
|
|
2290
|
-
import { File as File2, Type, useApp as useApp2 } from "@kubb/react";
|
|
2291
2223
|
import { useOas } from "@kubb/plugin-oas/hooks";
|
|
2292
|
-
import {
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
/* @__PURE__ */
|
|
2297
|
-
/* @__PURE__ */
|
|
2224
|
+
import { File, Type, useApp } from "@kubb/react";
|
|
2225
|
+
import { Fragment, jsx, jsxs } from "@kubb/react/jsx-runtime";
|
|
2226
|
+
function Template({ name, typeName, api }) {
|
|
2227
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2228
|
+
/* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: `export const ${name} = ${JSON.stringify(api, void 0, 2)} as const` }),
|
|
2229
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
2230
|
+
/* @__PURE__ */ jsx(File.Source, { name: typeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx(Type, { name: typeName, export: true, children: `Infer<typeof ${name}>` }) })
|
|
2298
2231
|
] });
|
|
2299
2232
|
}
|
|
2300
|
-
var
|
|
2301
|
-
function OasType({ name, typeName, Template: Template3 =
|
|
2233
|
+
var defaultTemplates = { default: Template };
|
|
2234
|
+
function OasType({ name, typeName, Template: Template3 = defaultTemplates.default }) {
|
|
2302
2235
|
const oas = useOas();
|
|
2303
|
-
return /* @__PURE__ */
|
|
2236
|
+
return /* @__PURE__ */ jsx(Template3, { name, typeName, api: oas.api });
|
|
2304
2237
|
}
|
|
2305
|
-
OasType.File = function({ name, typeName, templates =
|
|
2238
|
+
OasType.File = function({ name, typeName, templates = defaultTemplates }) {
|
|
2306
2239
|
const {
|
|
2307
2240
|
pluginManager,
|
|
2308
2241
|
plugin: { key: pluginKey }
|
|
2309
|
-
} =
|
|
2242
|
+
} = useApp();
|
|
2310
2243
|
const file = pluginManager.getFile({ name, extName: ".ts", pluginKey });
|
|
2311
2244
|
const Template3 = templates.default;
|
|
2312
|
-
return /* @__PURE__ */
|
|
2313
|
-
/* @__PURE__ */
|
|
2314
|
-
/* @__PURE__ */
|
|
2245
|
+
return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2246
|
+
/* @__PURE__ */ jsx(File.Import, { name: ["Infer"], path: "@kubb/oas", isTypeOnly: true }),
|
|
2247
|
+
/* @__PURE__ */ jsx(OasType, { Template: Template3, name, typeName })
|
|
2315
2248
|
] });
|
|
2316
2249
|
};
|
|
2317
|
-
OasType.templates =
|
|
2250
|
+
OasType.templates = defaultTemplates;
|
|
2318
2251
|
|
|
2319
2252
|
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
2320
2253
|
init_esm_shims();
|
|
2321
|
-
import
|
|
2254
|
+
import transformers3 from "@kubb/core/transformers";
|
|
2322
2255
|
import { print as print2 } from "@kubb/parser-ts";
|
|
2323
2256
|
import * as factory3 from "@kubb/parser-ts/factory";
|
|
2324
2257
|
import { Oas as Oas3 } from "@kubb/plugin-oas/components";
|
|
2325
|
-
import { useOas as useOas2, useOperation, useOperationManager
|
|
2326
|
-
import { File as
|
|
2258
|
+
import { useOas as useOas2, useOperation, useOperationManager } from "@kubb/plugin-oas/hooks";
|
|
2259
|
+
import { File as File3, useApp as useApp3 } from "@kubb/react";
|
|
2327
2260
|
|
|
2328
2261
|
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
2329
2262
|
init_esm_shims();
|
|
@@ -2333,10 +2266,10 @@ import { App, createRoot } from "@kubb/react";
|
|
|
2333
2266
|
|
|
2334
2267
|
// ../plugin-ts/src/components/Schema.tsx
|
|
2335
2268
|
init_esm_shims();
|
|
2336
|
-
var
|
|
2269
|
+
var import_react3 = __toESM(require_react(), 1);
|
|
2337
2270
|
import { Oas } from "@kubb/plugin-oas/components";
|
|
2338
|
-
import { File as
|
|
2339
|
-
import
|
|
2271
|
+
import { File as File2, useApp as useApp2 } from "@kubb/react";
|
|
2272
|
+
import transformers2 from "@kubb/core/transformers";
|
|
2340
2273
|
import { print } from "@kubb/parser-ts";
|
|
2341
2274
|
import * as factory2 from "@kubb/parser-ts/factory";
|
|
2342
2275
|
import { SchemaGenerator, schemaKeywords as schemaKeywords2 } from "@kubb/plugin-oas";
|
|
@@ -2344,7 +2277,7 @@ import { useSchema } from "@kubb/plugin-oas/hooks";
|
|
|
2344
2277
|
|
|
2345
2278
|
// ../plugin-ts/src/parser/index.ts
|
|
2346
2279
|
init_esm_shims();
|
|
2347
|
-
import
|
|
2280
|
+
import transformers from "@kubb/core/transformers";
|
|
2348
2281
|
import * as factory from "@kubb/parser-ts/factory";
|
|
2349
2282
|
import { isKeyword, schemaKeywords } from "@kubb/plugin-oas";
|
|
2350
2283
|
var typeKeywordMapper = {
|
|
@@ -2513,7 +2446,7 @@ function parse(parent, current, options) {
|
|
|
2513
2446
|
return factory.appendJSDocToNode({
|
|
2514
2447
|
node: propertySignature,
|
|
2515
2448
|
comments: [
|
|
2516
|
-
describeSchema ? `@description ${
|
|
2449
|
+
describeSchema ? `@description ${transformers.jsStringEscape(describeSchema.args)}` : void 0,
|
|
2517
2450
|
deprecatedSchema ? "@deprecated" : void 0,
|
|
2518
2451
|
defaultSchema ? `@default ${defaultSchema.args}` : void 0,
|
|
2519
2452
|
exampleSchema ? `@example ${exampleSchema.args}` : void 0,
|
|
@@ -2542,7 +2475,7 @@ function parse(parent, current, options) {
|
|
|
2542
2475
|
}
|
|
2543
2476
|
|
|
2544
2477
|
// ../plugin-ts/src/components/Schema.tsx
|
|
2545
|
-
import { jsx as
|
|
2478
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "@kubb/react/jsx-runtime";
|
|
2546
2479
|
function Schema(props) {
|
|
2547
2480
|
const { keysToOmit, description } = props;
|
|
2548
2481
|
const { tree, name } = useSchema();
|
|
@@ -2551,7 +2484,10 @@ function Schema(props) {
|
|
|
2551
2484
|
plugin: {
|
|
2552
2485
|
options: { mapper, enumType, optionalType }
|
|
2553
2486
|
}
|
|
2554
|
-
} =
|
|
2487
|
+
} = useApp2();
|
|
2488
|
+
if (enumType === "asPascalConst") {
|
|
2489
|
+
pluginManager.logger.emit("warning", `enumType '${enumType}' is deprecated`);
|
|
2490
|
+
}
|
|
2555
2491
|
const resolvedName = pluginManager.resolveName({
|
|
2556
2492
|
name,
|
|
2557
2493
|
pluginKey: [pluginTsName],
|
|
@@ -2606,12 +2542,12 @@ function Schema(props) {
|
|
|
2606
2542
|
});
|
|
2607
2543
|
const enumSchemas = SchemaGenerator.deepSearch(tree, schemaKeywords2.enum);
|
|
2608
2544
|
const enums = enumSchemas.map((enumSchema) => {
|
|
2609
|
-
const name2 =
|
|
2545
|
+
const name2 = enumType === "asPascalConst" ? transformers2.pascalCase(enumSchema.args.name) : transformers2.camelCase(enumSchema.args.name);
|
|
2610
2546
|
const typeName2 = enumSchema.args.typeName;
|
|
2611
2547
|
const [nameNode, typeNode] = factory2.createEnumDeclaration({
|
|
2612
2548
|
name: name2,
|
|
2613
2549
|
typeName: typeName2,
|
|
2614
|
-
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [
|
|
2550
|
+
enums: enumSchema.args.items.map((item) => item.value === void 0 ? void 0 : [transformers2.trimQuotes(item.name?.toString()), item.value]).filter(Boolean),
|
|
2615
2551
|
type: enumType
|
|
2616
2552
|
});
|
|
2617
2553
|
return {
|
|
@@ -2624,25 +2560,25 @@ function Schema(props) {
|
|
|
2624
2560
|
typeNodes.push(
|
|
2625
2561
|
factory2.appendJSDocToNode({
|
|
2626
2562
|
node,
|
|
2627
|
-
comments: [description ? `@description ${
|
|
2563
|
+
comments: [description ? `@description ${transformers2.jsStringEscape(description)}` : void 0].filter(Boolean)
|
|
2628
2564
|
})
|
|
2629
2565
|
);
|
|
2630
|
-
return /* @__PURE__ */
|
|
2631
|
-
enums.map(({ name: name2, nameNode, typeName: typeName2, typeNode }, index) => /* @__PURE__ */
|
|
2632
|
-
nameNode && /* @__PURE__ */
|
|
2633
|
-
/* @__PURE__ */
|
|
2634
|
-
] },
|
|
2635
|
-
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */
|
|
2566
|
+
return /* @__PURE__ */ jsxs2(import_react3.Fragment, { children: [
|
|
2567
|
+
enums.map(({ name: name2, nameNode, typeName: typeName2, typeNode }, index) => /* @__PURE__ */ jsxs2(import_react3.Fragment, { children: [
|
|
2568
|
+
nameNode && /* @__PURE__ */ jsx2(File2.Source, { name: name2, isExportable: true, isIndexable: true, children: print(nameNode) }),
|
|
2569
|
+
/* @__PURE__ */ jsx2(File2.Source, { name: typeName2, isIndexable: true, isExportable: ["enum", "asConst", "constEnum", "literal", void 0].includes(enumType), isTypeOnly: true, children: print(typeNode) })
|
|
2570
|
+
] }, [name2, nameNode].join("-"))),
|
|
2571
|
+
enums.every((item) => item.typeName !== resolvedName) && /* @__PURE__ */ jsx2(File2.Source, { name: typeName, isTypeOnly: true, isExportable: true, isIndexable: true, children: print(typeNodes) })
|
|
2636
2572
|
] });
|
|
2637
2573
|
}
|
|
2638
2574
|
Schema.File = function({}) {
|
|
2639
|
-
const { pluginManager } =
|
|
2575
|
+
const { pluginManager } = useApp2();
|
|
2640
2576
|
const { schema } = useSchema();
|
|
2641
|
-
return /* @__PURE__ */
|
|
2577
|
+
return /* @__PURE__ */ jsx2(Oas.Schema.File, { isTypeOnly: true, output: pluginManager.config.output.path, children: /* @__PURE__ */ jsx2(Schema, { description: schema?.description }) });
|
|
2642
2578
|
};
|
|
2643
2579
|
|
|
2644
2580
|
// ../plugin-ts/src/SchemaGenerator.tsx
|
|
2645
|
-
import { jsx as
|
|
2581
|
+
import { jsx as jsx3 } from "@kubb/react/jsx-runtime";
|
|
2646
2582
|
var SchemaGenerator2 = class extends Generator {
|
|
2647
2583
|
async schema(name, schema, options) {
|
|
2648
2584
|
const { oas, pluginManager, plugin, mode, output } = this.context;
|
|
@@ -2651,14 +2587,14 @@ var SchemaGenerator2 = class extends Generator {
|
|
|
2651
2587
|
});
|
|
2652
2588
|
const tree = this.parse({ schema, name });
|
|
2653
2589
|
root.render(
|
|
2654
|
-
/* @__PURE__ */
|
|
2590
|
+
/* @__PURE__ */ jsx3(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx3(Oas2, { oas, children: /* @__PURE__ */ jsx3(Oas2.Schema, { name, value: schema, tree, children: /* @__PURE__ */ jsx3(Schema.File, {}) }) }) })
|
|
2655
2591
|
);
|
|
2656
2592
|
return root.files;
|
|
2657
2593
|
}
|
|
2658
2594
|
};
|
|
2659
2595
|
|
|
2660
2596
|
// ../plugin-ts/src/components/OperationSchema.tsx
|
|
2661
|
-
import { jsx as
|
|
2597
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "@kubb/react/jsx-runtime";
|
|
2662
2598
|
function printCombinedSchema({
|
|
2663
2599
|
name,
|
|
2664
2600
|
operation,
|
|
@@ -2719,7 +2655,7 @@ function printCombinedSchema({
|
|
|
2719
2655
|
});
|
|
2720
2656
|
}
|
|
2721
2657
|
const namespaceNode = factory3.createTypeAliasDeclaration({
|
|
2722
|
-
name
|
|
2658
|
+
name,
|
|
2723
2659
|
type: factory3.createTypeLiteralNode(
|
|
2724
2660
|
Object.keys(properties).map((key) => {
|
|
2725
2661
|
const type = properties[key];
|
|
@@ -2727,7 +2663,7 @@ function printCombinedSchema({
|
|
|
2727
2663
|
return void 0;
|
|
2728
2664
|
}
|
|
2729
2665
|
return factory3.createPropertySignature({
|
|
2730
|
-
name:
|
|
2666
|
+
name: transformers3.pascalCase(key),
|
|
2731
2667
|
type
|
|
2732
2668
|
});
|
|
2733
2669
|
}).filter(Boolean)
|
|
@@ -2737,12 +2673,12 @@ function printCombinedSchema({
|
|
|
2737
2673
|
return print2(namespaceNode);
|
|
2738
2674
|
}
|
|
2739
2675
|
function OperationSchema({ keysToOmit, description }) {
|
|
2740
|
-
return /* @__PURE__ */
|
|
2676
|
+
return /* @__PURE__ */ jsx4(Schema, { keysToOmit, description });
|
|
2741
2677
|
}
|
|
2742
2678
|
OperationSchema.File = function({}) {
|
|
2743
|
-
const { pluginManager, plugin, mode } =
|
|
2679
|
+
const { pluginManager, plugin, mode } = useApp3();
|
|
2744
2680
|
const oas = useOas2();
|
|
2745
|
-
const { getSchemas, getFile, getName } =
|
|
2681
|
+
const { getSchemas, getFile, getName } = useOperationManager();
|
|
2746
2682
|
const operation = useOperation();
|
|
2747
2683
|
const file = getFile(operation);
|
|
2748
2684
|
const schemas = getSchemas(operation);
|
|
@@ -2757,19 +2693,20 @@ OperationSchema.File = function({}) {
|
|
|
2757
2693
|
const items = [schemas.pathParams, schemas.queryParams, schemas.headerParams, schemas.statusCodes, schemas.request, schemas.response].flat().filter(Boolean);
|
|
2758
2694
|
const mapItem = ({ name, schema, description, keysToOmit, ...options }, i) => {
|
|
2759
2695
|
const tree = generator.parse({ schema, name });
|
|
2760
|
-
return /* @__PURE__ */
|
|
2761
|
-
mode === "split" && /* @__PURE__ */
|
|
2762
|
-
/* @__PURE__ */
|
|
2696
|
+
return /* @__PURE__ */ jsxs3(Oas3.Schema, { name, value: schema, tree, children: [
|
|
2697
|
+
mode === "split" && /* @__PURE__ */ jsx4(Oas3.Schema.Imports, { isTypeOnly: true }),
|
|
2698
|
+
/* @__PURE__ */ jsx4(OperationSchema, { description, keysToOmit })
|
|
2763
2699
|
] }, i);
|
|
2764
2700
|
};
|
|
2765
|
-
|
|
2701
|
+
const combinedSchemaName = operation.method === "get" ? `${factoryName}Query` : `${factoryName}Mutation`;
|
|
2702
|
+
return /* @__PURE__ */ jsxs3(File3, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
2766
2703
|
items.map(mapItem),
|
|
2767
|
-
/* @__PURE__ */
|
|
2704
|
+
/* @__PURE__ */ jsx4(File3.Source, { name: combinedSchemaName, isExportable: true, isIndexable: true, isTypeOnly: true, children: printCombinedSchema({ name: combinedSchemaName, operation, schemas, pluginManager }) })
|
|
2768
2705
|
] });
|
|
2769
2706
|
};
|
|
2770
2707
|
|
|
2771
2708
|
// ../plugin-ts/src/OperationGenerator.tsx
|
|
2772
|
-
import { jsx as
|
|
2709
|
+
import { jsx as jsx5 } from "@kubb/react/jsx-runtime";
|
|
2773
2710
|
var OperationGenerator = class extends Generator2 {
|
|
2774
2711
|
async all(operations) {
|
|
2775
2712
|
const { oas, pluginManager, plugin, mode } = this.context;
|
|
@@ -2777,7 +2714,7 @@ var OperationGenerator = class extends Generator2 {
|
|
|
2777
2714
|
logger: pluginManager.logger
|
|
2778
2715
|
});
|
|
2779
2716
|
root.render(
|
|
2780
|
-
/* @__PURE__ */
|
|
2717
|
+
/* @__PURE__ */ jsx5(App2, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx5(Oas4, { oas, operations, generator: this, children: plugin.options.oasType && /* @__PURE__ */ jsx5(OasType.File, { name: "oas", typeName: "Oas" }) }) })
|
|
2781
2718
|
);
|
|
2782
2719
|
return root.files;
|
|
2783
2720
|
}
|
|
@@ -2787,7 +2724,7 @@ var OperationGenerator = class extends Generator2 {
|
|
|
2787
2724
|
logger: pluginManager.logger
|
|
2788
2725
|
});
|
|
2789
2726
|
root.render(
|
|
2790
|
-
/* @__PURE__ */
|
|
2727
|
+
/* @__PURE__ */ jsx5(App2, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx5(Oas4, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx5(Oas4.Operation, { operation, children: /* @__PURE__ */ jsx5(OperationSchema.File, {}) }) }) })
|
|
2791
2728
|
);
|
|
2792
2729
|
return root.files;
|
|
2793
2730
|
}
|
|
@@ -2814,6 +2751,10 @@ var pluginTs = createPlugin((options) => {
|
|
|
2814
2751
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
2815
2752
|
return {
|
|
2816
2753
|
name: pluginTsName,
|
|
2754
|
+
output: {
|
|
2755
|
+
exportType: "barrelNamed",
|
|
2756
|
+
...output
|
|
2757
|
+
},
|
|
2817
2758
|
options: {
|
|
2818
2759
|
extName: output.extName,
|
|
2819
2760
|
transformers: transformers7,
|
|
@@ -2877,15 +2818,17 @@ var pluginTs = createPlugin((options) => {
|
|
|
2877
2818
|
});
|
|
2878
2819
|
const operationFiles = await operationGenerator.build();
|
|
2879
2820
|
await this.addFile(...operationFiles);
|
|
2880
|
-
if (this.config.output.
|
|
2881
|
-
const
|
|
2821
|
+
if (this.config.output.exportType) {
|
|
2822
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
2882
2823
|
root,
|
|
2883
2824
|
output,
|
|
2884
2825
|
files: this.fileManager.files,
|
|
2885
|
-
|
|
2826
|
+
meta: {
|
|
2827
|
+
pluginKey: this.plugin.key
|
|
2828
|
+
},
|
|
2886
2829
|
logger: this.logger
|
|
2887
2830
|
});
|
|
2888
|
-
await this.addFile(...
|
|
2831
|
+
await this.addFile(...barrelFiles);
|
|
2889
2832
|
}
|
|
2890
2833
|
}
|
|
2891
2834
|
};
|
|
@@ -2898,7 +2841,7 @@ import { useSchema as useSchema2 } from "@kubb/plugin-oas/hooks";
|
|
|
2898
2841
|
|
|
2899
2842
|
// src/parser/index.ts
|
|
2900
2843
|
init_esm_shims();
|
|
2901
|
-
import
|
|
2844
|
+
import transformers4 from "@kubb/core/transformers";
|
|
2902
2845
|
import { isKeyword as isKeyword2, schemaKeywords as schemaKeywords3 } from "@kubb/plugin-oas";
|
|
2903
2846
|
var zodKeywordMapper = {
|
|
2904
2847
|
any: () => "z.any()",
|
|
@@ -3018,7 +2961,7 @@ function sort(items) {
|
|
|
3018
2961
|
if (!items) {
|
|
3019
2962
|
return [];
|
|
3020
2963
|
}
|
|
3021
|
-
return
|
|
2964
|
+
return transformers4.orderBy(items, [(v) => order.indexOf(v.keyword)], ["asc"]);
|
|
3022
2965
|
}
|
|
3023
2966
|
function parse2(parent, current, options) {
|
|
3024
2967
|
const value = zodKeywordMapper[current.keyword];
|
|
@@ -3067,9 +3010,9 @@ function parse2(parent, current, options) {
|
|
|
3067
3010
|
return zodKeywordMapper.enum(
|
|
3068
3011
|
current.args.items.map((schema) => {
|
|
3069
3012
|
if (schema.format === "number") {
|
|
3070
|
-
return
|
|
3013
|
+
return transformers4.stringify(schema.value);
|
|
3071
3014
|
}
|
|
3072
|
-
return
|
|
3015
|
+
return transformers4.stringify(schema.value);
|
|
3073
3016
|
})
|
|
3074
3017
|
);
|
|
3075
3018
|
}
|
|
@@ -3107,11 +3050,11 @@ function parse2(parent, current, options) {
|
|
|
3107
3050
|
if (current.args.format === "number" && current.args.value !== void 0) {
|
|
3108
3051
|
return zodKeywordMapper.const(Number.parseInt(current.args.value?.toString()));
|
|
3109
3052
|
}
|
|
3110
|
-
return zodKeywordMapper.const(
|
|
3053
|
+
return zodKeywordMapper.const(transformers4.stringify(current.args.value));
|
|
3111
3054
|
}
|
|
3112
3055
|
if (isKeyword2(current, schemaKeywords3.matches)) {
|
|
3113
3056
|
if (current.args) {
|
|
3114
|
-
return zodKeywordMapper.matches(
|
|
3057
|
+
return zodKeywordMapper.matches(transformers4.toRegExpString(current.args));
|
|
3115
3058
|
}
|
|
3116
3059
|
}
|
|
3117
3060
|
if (isKeyword2(current, schemaKeywords3.default)) {
|
|
@@ -3121,7 +3064,7 @@ function parse2(parent, current, options) {
|
|
|
3121
3064
|
}
|
|
3122
3065
|
if (isKeyword2(current, schemaKeywords3.describe)) {
|
|
3123
3066
|
if (current.args) {
|
|
3124
|
-
return zodKeywordMapper.describe(
|
|
3067
|
+
return zodKeywordMapper.describe(transformers4.stringify(current.args.toString()));
|
|
3125
3068
|
}
|
|
3126
3069
|
}
|
|
3127
3070
|
if (isKeyword2(current, schemaKeywords3.string)) {
|
|
@@ -3157,16 +3100,83 @@ function parse2(parent, current, options) {
|
|
|
3157
3100
|
|
|
3158
3101
|
// src/plugin.ts
|
|
3159
3102
|
init_esm_shims();
|
|
3160
|
-
import path2 from "path";
|
|
3103
|
+
import path2 from "node:path";
|
|
3161
3104
|
import { FileManager as FileManager2, PluginManager as PluginManager2, createPlugin as createPlugin2 } from "@kubb/core";
|
|
3162
3105
|
import { camelCase as camelCase2, pascalCase as pascalCase2 } from "@kubb/core/transformers";
|
|
3163
3106
|
import { renderTemplate as renderTemplate2 } from "@kubb/core/utils";
|
|
3164
|
-
import { OperationGenerator as OperationGenerator2,
|
|
3107
|
+
import { OperationGenerator as OperationGenerator2, SchemaGenerator as SchemaGenerator4, pluginOasName as pluginOasName2 } from "@kubb/plugin-oas";
|
|
3165
3108
|
|
|
3166
3109
|
// src/SchemaGenerator.tsx
|
|
3167
3110
|
init_esm_shims();
|
|
3168
3111
|
import { createReactParser } from "@kubb/plugin-oas";
|
|
3169
3112
|
|
|
3113
|
+
// src/components/Operations.tsx
|
|
3114
|
+
init_esm_shims();
|
|
3115
|
+
import { useOperationManager as useOperationManager2, useOperations } from "@kubb/plugin-oas/hooks";
|
|
3116
|
+
import { Const, File as File4, useApp as useApp4 } from "@kubb/react";
|
|
3117
|
+
import transformers5 from "@kubb/core/transformers";
|
|
3118
|
+
import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs4 } from "@kubb/react/jsx-runtime";
|
|
3119
|
+
function Template2({ operationsName, pathsName, operations }) {
|
|
3120
|
+
const { groupSchemasByName } = useOperationManager2();
|
|
3121
|
+
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
3122
|
+
const operationsJSON = transformedOperations.reduce(
|
|
3123
|
+
(prev, acc) => {
|
|
3124
|
+
prev[`"${acc.operation.getOperationId()}"`] = acc.data;
|
|
3125
|
+
return prev;
|
|
3126
|
+
},
|
|
3127
|
+
{}
|
|
3128
|
+
);
|
|
3129
|
+
const pathsJSON = transformedOperations.reduce(
|
|
3130
|
+
(prev, acc) => {
|
|
3131
|
+
prev[`"${acc.operation.path}"`] = {
|
|
3132
|
+
...prev[`"${acc.operation.path}"`] || {},
|
|
3133
|
+
[acc.operation.method]: `operations["${acc.operation.getOperationId()}"]`
|
|
3134
|
+
};
|
|
3135
|
+
return prev;
|
|
3136
|
+
},
|
|
3137
|
+
{}
|
|
3138
|
+
);
|
|
3139
|
+
return /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
3140
|
+
/* @__PURE__ */ jsx6(File4.Source, { name: operationsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx6(Const, { export: true, name: operationsName, asConst: true, children: `{${transformers5.stringifyObject(operationsJSON)}}` }) }),
|
|
3141
|
+
/* @__PURE__ */ jsx6(File4.Source, { name: pathsName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx6(Const, { export: true, name: pathsName, asConst: true, children: `{${transformers5.stringifyObject(pathsJSON)}}` }) })
|
|
3142
|
+
] });
|
|
3143
|
+
}
|
|
3144
|
+
function RootTemplate({ children }) {
|
|
3145
|
+
const {
|
|
3146
|
+
mode,
|
|
3147
|
+
pluginManager,
|
|
3148
|
+
plugin: {
|
|
3149
|
+
key: pluginKey,
|
|
3150
|
+
options: { extName }
|
|
3151
|
+
}
|
|
3152
|
+
} = useApp4();
|
|
3153
|
+
const { getFile } = useOperationManager2();
|
|
3154
|
+
const operations = useOperations();
|
|
3155
|
+
const { groupSchemasByName } = useOperationManager2();
|
|
3156
|
+
const transformedOperations = operations.map((operation) => ({ operation, data: groupSchemasByName(operation, { type: "function" }) }));
|
|
3157
|
+
const file = pluginManager.getFile({ name: "operations", extName: ".ts", pluginKey });
|
|
3158
|
+
const imports = Object.entries(transformedOperations).map(([_key, { data, operation }], index) => {
|
|
3159
|
+
const names = [data.request, ...Object.values(data.responses), ...Object.values(data.parameters)].filter(Boolean);
|
|
3160
|
+
return /* @__PURE__ */ jsx6(File4.Import, { name: names, root: file.path, path: getFile(operation).path }, index);
|
|
3161
|
+
}).filter(Boolean);
|
|
3162
|
+
return /* @__PURE__ */ jsxs4(File4, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
|
|
3163
|
+
mode === "split" && imports,
|
|
3164
|
+
children
|
|
3165
|
+
] });
|
|
3166
|
+
}
|
|
3167
|
+
var defaultTemplates2 = { default: Template2, root: RootTemplate };
|
|
3168
|
+
function Operations({ Template: Template3 = defaultTemplates2.default }) {
|
|
3169
|
+
const operations = useOperations();
|
|
3170
|
+
return /* @__PURE__ */ jsx6(Template3, { operationsName: "operations", pathsName: "paths", operations });
|
|
3171
|
+
}
|
|
3172
|
+
Operations.File = function(props) {
|
|
3173
|
+
const templates = { ...defaultTemplates2, ...props.templates };
|
|
3174
|
+
const Template3 = templates.default;
|
|
3175
|
+
const RootTemplate2 = templates.root;
|
|
3176
|
+
return /* @__PURE__ */ jsx6(RootTemplate2, { children: /* @__PURE__ */ jsx6(Operations, { Template: Template3 }) });
|
|
3177
|
+
};
|
|
3178
|
+
Operations.templates = defaultTemplates2;
|
|
3179
|
+
|
|
3170
3180
|
// src/components/OperationSchema.tsx
|
|
3171
3181
|
init_esm_shims();
|
|
3172
3182
|
import { SchemaGenerator as SchemaGenerator3, schemaKeywords as schemaKeywords4 } from "@kubb/plugin-oas";
|
|
@@ -3197,7 +3207,7 @@ OperationSchema2.File = function({}) {
|
|
|
3197
3207
|
const optional = !required && !!name.includes("Params");
|
|
3198
3208
|
const tree = generator.parse({ schema, name });
|
|
3199
3209
|
return /* @__PURE__ */ jsxs5(Oas5.Schema, { name, value: schema, tree: [...tree, optional ? { keyword: schemaKeywords4.optional } : void 0].filter(Boolean), children: [
|
|
3200
|
-
mode === "split" && /* @__PURE__ */ jsx7(Oas5.Schema.Imports, {}),
|
|
3210
|
+
mode === "split" && /* @__PURE__ */ jsx7(Oas5.Schema.Imports, { isTypeOnly: false }),
|
|
3201
3211
|
/* @__PURE__ */ jsx7(OperationSchema2, { description, keysToOmit })
|
|
3202
3212
|
] }, i);
|
|
3203
3213
|
};
|
|
@@ -3247,6 +3257,10 @@ var pluginZod = createPlugin2((options) => {
|
|
|
3247
3257
|
const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
|
|
3248
3258
|
return {
|
|
3249
3259
|
name: pluginZodName,
|
|
3260
|
+
output: {
|
|
3261
|
+
exportType: "barrelNamed",
|
|
3262
|
+
...output
|
|
3263
|
+
},
|
|
3250
3264
|
options: {
|
|
3251
3265
|
extName: output.extName,
|
|
3252
3266
|
transformers: transformers7,
|
|
@@ -3320,15 +3334,17 @@ var pluginZod = createPlugin2((options) => {
|
|
|
3320
3334
|
});
|
|
3321
3335
|
const operationFiles = await operationGenerator.build(zodParser);
|
|
3322
3336
|
await this.addFile(...operationFiles);
|
|
3323
|
-
if (this.config.output.
|
|
3324
|
-
const
|
|
3337
|
+
if (this.config.output.exportType) {
|
|
3338
|
+
const barrelFiles = await this.fileManager.getBarrelFiles({
|
|
3325
3339
|
root,
|
|
3326
3340
|
output,
|
|
3327
3341
|
files: this.fileManager.files,
|
|
3328
|
-
|
|
3342
|
+
meta: {
|
|
3343
|
+
pluginKey: this.plugin.key
|
|
3344
|
+
},
|
|
3329
3345
|
logger: this.logger
|
|
3330
3346
|
});
|
|
3331
|
-
await this.addFile(...
|
|
3347
|
+
await this.addFile(...barrelFiles);
|
|
3332
3348
|
}
|
|
3333
3349
|
}
|
|
3334
3350
|
};
|
|
@@ -3361,7 +3377,7 @@ function Schema2(props) {
|
|
|
3361
3377
|
type: "type"
|
|
3362
3378
|
});
|
|
3363
3379
|
if (!tree.length) {
|
|
3364
|
-
return /* @__PURE__ */ jsx9(File6.Source, { name: resolvedName, isExportable: true, children: /* @__PURE__ */ jsx9(
|
|
3380
|
+
return /* @__PURE__ */ jsx9(File6.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx9(
|
|
3365
3381
|
Const2,
|
|
3366
3382
|
{
|
|
3367
3383
|
name: resolvedName,
|
|
@@ -3382,7 +3398,7 @@ function Schema2(props) {
|
|
|
3382
3398
|
}).map((item) => parse2(void 0, item, { name, typeName, description, mapper, coercion, keysToOmit })).filter(Boolean).join("");
|
|
3383
3399
|
const suffix = output.endsWith(".nullable()") ? ".unwrap().and" : ".and";
|
|
3384
3400
|
return /* @__PURE__ */ jsxs6(Fragment4, { children: [
|
|
3385
|
-
/* @__PURE__ */ jsx9(File6.Source, { name: resolvedName, isExportable: true, children: /* @__PURE__ */ jsx9(
|
|
3401
|
+
/* @__PURE__ */ jsx9(File6.Source, { name: resolvedName, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx9(
|
|
3386
3402
|
Const2,
|
|
3387
3403
|
{
|
|
3388
3404
|
export: true,
|
|
@@ -3397,7 +3413,7 @@ function Schema2(props) {
|
|
|
3397
3413
|
].filter(Boolean).join("") || ""
|
|
3398
3414
|
}
|
|
3399
3415
|
) }),
|
|
3400
|
-
typedSchema && /* @__PURE__ */ jsx9(File6.Source, { name: resolvedTypeName, isExportable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx9(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` }) })
|
|
3416
|
+
typedSchema && /* @__PURE__ */ jsx9(File6.Source, { name: resolvedTypeName, isExportable: true, isIndexable: true, isTypeOnly: true, children: /* @__PURE__ */ jsx9(Type2, { export: true, name: resolvedTypeName, children: `z.infer<typeof ${resolvedName}>` }) })
|
|
3401
3417
|
] });
|
|
3402
3418
|
}
|
|
3403
3419
|
Schema2.File = function({}) {
|
|
@@ -3446,8 +3462,8 @@ Schema2.Imports = () => {
|
|
|
3446
3462
|
|
|
3447
3463
|
export {
|
|
3448
3464
|
init_esm_shims,
|
|
3449
|
-
Operations,
|
|
3450
3465
|
Schema2 as Schema,
|
|
3466
|
+
Operations,
|
|
3451
3467
|
OperationSchema2 as OperationSchema,
|
|
3452
3468
|
pluginZodName,
|
|
3453
3469
|
pluginZod
|
|
@@ -3476,4 +3492,4 @@ react/cjs/react.development.js:
|
|
|
3476
3492
|
* LICENSE file in the root directory of this source tree.
|
|
3477
3493
|
*)
|
|
3478
3494
|
*/
|
|
3479
|
-
//# sourceMappingURL=chunk-
|
|
3495
|
+
//# sourceMappingURL=chunk-CD3EZWBX.js.map
|