@kubb/plugin-oas 5.0.0-alpha.6 → 5.0.0-alpha.7
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/{createGenerator-B_7cgcmg.d.ts → createGenerator-BnX0BloB.d.ts} +4 -4
- package/dist/{generators-D_7I5QrN.cjs → generators-BfTTScuN.cjs} +4 -4
- package/dist/{generators-D_7I5QrN.cjs.map → generators-BfTTScuN.cjs.map} +1 -1
- package/dist/{generators-DxN9Dqyi.js → generators-BjsINk-u.js} +4 -4
- package/dist/{generators-DxN9Dqyi.js.map → generators-BjsINk-u.js.map} +1 -1
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +1 -1
- package/dist/hooks.cjs +14 -14
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.js +15 -15
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/{requestBody-BWo89xcg.cjs → requestBody-DyTNWJql.cjs} +17 -17
- package/dist/requestBody-DyTNWJql.cjs.map +1 -0
- package/dist/{requestBody-Cs-1vKOq.js → requestBody-gV_d8sCu.js} +17 -17
- package/dist/requestBody-gV_d8sCu.js.map +1 -0
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +3 -3
- package/src/OperationGenerator.ts +6 -6
- package/src/SchemaGenerator.ts +8 -8
- package/src/generators/jsonGenerator.ts +3 -3
- package/src/hooks/useOperationManager.ts +12 -12
- package/src/hooks/useSchemaManager.ts +4 -4
- package/src/plugin.ts +2 -2
- package/src/utils.tsx +14 -14
- package/dist/requestBody-BWo89xcg.cjs.map +0 -1
- package/dist/requestBody-Cs-1vKOq.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
2
|
import { i as SchemaKeywordMapper, t as Schema } from "./SchemaMapper-SneuY1wg.js";
|
|
3
3
|
import { HttpMethod, Oas, Operation, SchemaObject, contentType } from "@kubb/oas";
|
|
4
|
-
import { AsyncEventEmitter, Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin,
|
|
4
|
+
import { AsyncEventEmitter, Config, FileMetaBase, Generator, Group, KubbEvents, Output, Plugin, PluginDriver, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
|
|
5
5
|
import { Fabric, KubbFile } from "@kubb/fabric-core/types";
|
|
6
6
|
import { FabricReactNode } from "@kubb/react-fabric/types";
|
|
7
7
|
|
|
@@ -227,7 +227,7 @@ type Context$1<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
|
227
227
|
include: Array<Include> | undefined;
|
|
228
228
|
override: Array<Override<TOptions>> | undefined;
|
|
229
229
|
contentType: contentType | undefined;
|
|
230
|
-
|
|
230
|
+
driver: PluginDriver;
|
|
231
231
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
232
232
|
/**
|
|
233
233
|
* Current plugin
|
|
@@ -262,7 +262,7 @@ type SchemaMethodResult<TFileMeta extends FileMetaBase> = Promise<KubbFile.File<
|
|
|
262
262
|
type Context<TOptions, TPluginOptions extends PluginFactoryOptions> = {
|
|
263
263
|
fabric: Fabric;
|
|
264
264
|
oas: Oas;
|
|
265
|
-
|
|
265
|
+
driver: PluginDriver;
|
|
266
266
|
events?: AsyncEventEmitter<KubbEvents>;
|
|
267
267
|
/**
|
|
268
268
|
* Current plugin
|
|
@@ -395,4 +395,4 @@ type CoreGenerator<TOptions extends PluginFactoryOptions> = {
|
|
|
395
395
|
declare function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions>;
|
|
396
396
|
//#endregion
|
|
397
397
|
export { Resolver as C, ResolvePathOptions as S, Options as _, createReactGenerator as a, Ref as b, SchemaGeneratorBuildOptions as c, OperationGenerator as d, OperationMethodResult as f, OperationSchemas as g, OperationSchema as h, ReactGenerator as i, SchemaGeneratorOptions as l, Include as m, createGenerator as n, GetSchemaGeneratorOptions as o, Exclude as p, Generator$1 as r, SchemaGenerator as s, CoreGenerator as t, SchemaMethodResult as u, Override as v, Refs as x, PluginOas as y };
|
|
398
|
-
//# sourceMappingURL=createGenerator-
|
|
398
|
+
//# sourceMappingURL=createGenerator-BnX0BloB.d.ts.map
|
|
@@ -47,9 +47,9 @@ function createReactGenerator(generator) {
|
|
|
47
47
|
const jsonGenerator = createGenerator({
|
|
48
48
|
name: "plugin-oas",
|
|
49
49
|
async schema({ schema, generator }) {
|
|
50
|
-
const {
|
|
50
|
+
const { driver, plugin } = generator.context;
|
|
51
51
|
return [{
|
|
52
|
-
...
|
|
52
|
+
...driver.getFile({
|
|
53
53
|
name: require_getFooter.camelCase(schema.name),
|
|
54
54
|
extname: ".json",
|
|
55
55
|
mode: "split",
|
|
@@ -64,7 +64,7 @@ const jsonGenerator = createGenerator({
|
|
|
64
64
|
banner: require_getFooter.getBanner({
|
|
65
65
|
oas: generator.context.oas,
|
|
66
66
|
output: plugin.options.output,
|
|
67
|
-
config:
|
|
67
|
+
config: driver.config
|
|
68
68
|
}),
|
|
69
69
|
format: require_getFooter.getFooter({
|
|
70
70
|
oas: generator.context.oas,
|
|
@@ -93,4 +93,4 @@ Object.defineProperty(exports, "jsonGenerator", {
|
|
|
93
93
|
}
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
//# sourceMappingURL=generators-
|
|
96
|
+
//# sourceMappingURL=generators-BfTTScuN.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators-
|
|
1
|
+
{"version":3,"file":"generators-BfTTScuN.cjs","names":["camelCase","getBanner","getFooter"],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'core'\n version: '1'\n operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions> {\n return {\n type: 'core',\n version: '1',\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n Operations?: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'react'\n version: '1'\n Operations: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation: (props: OperationProps<TOptions>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): ReactGenerator<TOptions> {\n return {\n type: 'react',\n version: '1',\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { driver, plugin } = generator.context\n const file = driver.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginName: plugin.name,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: driver.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAoBA,SAAgB,gBAAuD,WAA6D;AAClI,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACPH,SAAgB,qBAA4D,WAA8D;AACxI,QAAO;EACL,MAAM;EACN,SAAS;EACT,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACnCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,QAAQ,WAAW,UAAU;AAQrC,SAAO,CACL;GACE,GATS,OAAO,QAAQ;IAC1B,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,YAAY,OAAO;IACpB,CAAC;GAKE,SAAS,CACP;IACE,MAAMA,kBAAAA,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQC,kBAAAA,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,OAAO;IAChB,CAAC;GACF,QAAQC,kBAAAA,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}
|
|
@@ -47,9 +47,9 @@ function createReactGenerator(generator) {
|
|
|
47
47
|
const jsonGenerator = createGenerator({
|
|
48
48
|
name: "plugin-oas",
|
|
49
49
|
async schema({ schema, generator }) {
|
|
50
|
-
const {
|
|
50
|
+
const { driver, plugin } = generator.context;
|
|
51
51
|
return [{
|
|
52
|
-
...
|
|
52
|
+
...driver.getFile({
|
|
53
53
|
name: camelCase(schema.name),
|
|
54
54
|
extname: ".json",
|
|
55
55
|
mode: "split",
|
|
@@ -64,7 +64,7 @@ const jsonGenerator = createGenerator({
|
|
|
64
64
|
banner: getBanner({
|
|
65
65
|
oas: generator.context.oas,
|
|
66
66
|
output: plugin.options.output,
|
|
67
|
-
config:
|
|
67
|
+
config: driver.config
|
|
68
68
|
}),
|
|
69
69
|
format: getFooter({
|
|
70
70
|
oas: generator.context.oas,
|
|
@@ -76,4 +76,4 @@ const jsonGenerator = createGenerator({
|
|
|
76
76
|
//#endregion
|
|
77
77
|
export { createReactGenerator as n, createGenerator as r, jsonGenerator as t };
|
|
78
78
|
|
|
79
|
-
//# sourceMappingURL=generators-
|
|
79
|
+
//# sourceMappingURL=generators-BjsINk-u.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generators-
|
|
1
|
+
{"version":3,"file":"generators-BjsINk-u.js","names":[],"sources":["../src/generators/createGenerator.ts","../src/generators/createReactGenerator.ts","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n operations?: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation?: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema?: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport type CoreGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'core'\n version: '1'\n operations: (props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation: (props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema: (props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport function createGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): CoreGenerator<TOptions> {\n return {\n type: 'core',\n version: '1',\n async operations() {\n return []\n },\n async operation() {\n return []\n },\n async schema() {\n return []\n },\n ...generator,\n }\n}\n","import type { PluginFactoryOptions } from '@kubb/core'\nimport type { FabricReactNode } from '@kubb/react-fabric/types'\nimport type { OperationProps, OperationsProps, SchemaProps } from './types.ts'\n\ntype UserGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n Operations?: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation?: (props: OperationProps<TOptions>) => FabricReactNode\n Schema?: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\nexport type ReactGenerator<TOptions extends PluginFactoryOptions> = {\n name: string\n type: 'react'\n version: '1'\n Operations: (props: OperationsProps<TOptions>) => FabricReactNode\n Operation: (props: OperationProps<TOptions>) => FabricReactNode\n Schema: (props: SchemaProps<TOptions>) => FabricReactNode\n}\n\n/****\n * Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.\n *\n * The returned generator exposes async methods for generating files from operations, a single operation, or a schema, using the corresponding React components if provided. If a component is not defined, the method returns an empty array.\n *\n * @returns A generator object with async methods for operations, operation, and schema file generation.\n */\nexport function createReactGenerator<TOptions extends PluginFactoryOptions>(generator: UserGenerator<TOptions>): ReactGenerator<TOptions> {\n return {\n type: 'react',\n version: '1',\n Operations() {\n return null\n },\n Operation() {\n return null\n },\n Schema() {\n return null\n },\n ...generator,\n }\n}\n","import { camelCase } from '@internals/utils'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\nimport { createGenerator } from './createGenerator.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, generator }) {\n const { driver, plugin } = generator.context\n const file = driver.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginName: plugin.name,\n })\n\n return [\n {\n ...file,\n sources: [\n {\n name: camelCase(schema.name),\n isExportable: false,\n isIndexable: false,\n value: JSON.stringify(schema.value),\n },\n ],\n banner: getBanner({\n oas: generator.context.oas,\n output: plugin.options.output,\n config: driver.config,\n }),\n format: getFooter({ oas: generator.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;AAoBA,SAAgB,gBAAuD,WAA6D;AAClI,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,aAAa;AACjB,UAAO,EAAE;;EAEX,MAAM,YAAY;AAChB,UAAO,EAAE;;EAEX,MAAM,SAAS;AACb,UAAO,EAAE;;EAEX,GAAG;EACJ;;;;;;;;;;;ACPH,SAAgB,qBAA4D,WAA8D;AACxI,QAAO;EACL,MAAM;EACN,SAAS;EACT,aAAa;AACX,UAAO;;EAET,YAAY;AACV,UAAO;;EAET,SAAS;AACP,UAAO;;EAET,GAAG;EACJ;;;;ACnCH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,aAAa;EAClC,MAAM,EAAE,QAAQ,WAAW,UAAU;AAQrC,SAAO,CACL;GACE,GATS,OAAO,QAAQ;IAC1B,MAAM,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,YAAY,OAAO;IACpB,CAAC;GAKE,SAAS,CACP;IACE,MAAM,UAAU,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQ,UAAU;IAChB,KAAK,UAAU,QAAQ;IACvB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,OAAO;IAChB,CAAC;GACF,QAAQ,UAAU;IAAE,KAAK,UAAU,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GACjF,CACF;;CAEJ,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_generators = require("./generators-
|
|
2
|
+
const require_generators = require("./generators-BfTTScuN.cjs");
|
|
3
3
|
exports.createGenerator = require_generators.createGenerator;
|
|
4
4
|
exports.createReactGenerator = require_generators.createReactGenerator;
|
|
5
5
|
exports.jsonGenerator = require_generators.jsonGenerator;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-
|
|
2
|
+
import { a as createReactGenerator, n as createGenerator, r as Generator, t as CoreGenerator, y as PluginOas } from "./createGenerator-BnX0BloB.js";
|
|
3
3
|
//#region src/generators/jsonGenerator.d.ts
|
|
4
4
|
declare const jsonGenerator: CoreGenerator<PluginOas>;
|
|
5
5
|
//#endregion
|
package/dist/generators.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as createReactGenerator, r as createGenerator, t as jsonGenerator } from "./generators-
|
|
1
|
+
import { n as createReactGenerator, r as createGenerator, t as jsonGenerator } from "./generators-BjsINk-u.js";
|
|
2
2
|
export { createGenerator, createReactGenerator, jsonGenerator };
|
package/dist/hooks.cjs
CHANGED
|
@@ -17,9 +17,9 @@ function useOas() {
|
|
|
17
17
|
*/
|
|
18
18
|
function useOperationManager(generator) {
|
|
19
19
|
const plugin = (0, _kubb_core_hooks.usePlugin)();
|
|
20
|
-
const
|
|
20
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
21
21
|
const getName = (operation, { prefix = "", suffix = "", pluginName = plugin.name, type }) => {
|
|
22
|
-
return
|
|
22
|
+
return driver.resolveName({
|
|
23
23
|
name: `${prefix} ${operation.getOperationId()} ${suffix}`,
|
|
24
24
|
pluginName,
|
|
25
25
|
type
|
|
@@ -33,7 +33,7 @@ function useOperationManager(generator) {
|
|
|
33
33
|
};
|
|
34
34
|
const getSchemas = (operation, params) => {
|
|
35
35
|
if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
|
|
36
|
-
return generator.getSchemas(operation, { resolveName: (name) =>
|
|
36
|
+
return generator.getSchemas(operation, { resolveName: (name) => driver.resolveName({
|
|
37
37
|
name,
|
|
38
38
|
pluginName: params?.pluginName,
|
|
39
39
|
type: params?.type
|
|
@@ -47,7 +47,7 @@ function useOperationManager(generator) {
|
|
|
47
47
|
suffix
|
|
48
48
|
});
|
|
49
49
|
const group = getGroup(operation);
|
|
50
|
-
const file =
|
|
50
|
+
const file = driver.getFile({
|
|
51
51
|
name,
|
|
52
52
|
extname,
|
|
53
53
|
pluginName,
|
|
@@ -72,7 +72,7 @@ function useOperationManager(generator) {
|
|
|
72
72
|
const schemas = generator.getSchemas(operation);
|
|
73
73
|
const errors = (schemas.errors || []).reduce((prev, acc) => {
|
|
74
74
|
if (!acc.statusCode) return prev;
|
|
75
|
-
prev[acc.statusCode] =
|
|
75
|
+
prev[acc.statusCode] = driver.resolveName({
|
|
76
76
|
name: acc.name,
|
|
77
77
|
pluginName,
|
|
78
78
|
type
|
|
@@ -81,7 +81,7 @@ function useOperationManager(generator) {
|
|
|
81
81
|
}, {});
|
|
82
82
|
const responses = (schemas.responses || []).reduce((prev, acc) => {
|
|
83
83
|
if (!acc.statusCode) return prev;
|
|
84
|
-
prev[acc.statusCode] =
|
|
84
|
+
prev[acc.statusCode] = driver.resolveName({
|
|
85
85
|
name: acc.name,
|
|
86
86
|
pluginName,
|
|
87
87
|
type
|
|
@@ -89,23 +89,23 @@ function useOperationManager(generator) {
|
|
|
89
89
|
return prev;
|
|
90
90
|
}, {});
|
|
91
91
|
return {
|
|
92
|
-
request: schemas.request?.name ?
|
|
92
|
+
request: schemas.request?.name ? driver.resolveName({
|
|
93
93
|
name: schemas.request.name,
|
|
94
94
|
pluginName,
|
|
95
95
|
type
|
|
96
96
|
}) : void 0,
|
|
97
97
|
parameters: {
|
|
98
|
-
path: schemas.pathParams?.name ?
|
|
98
|
+
path: schemas.pathParams?.name ? driver.resolveName({
|
|
99
99
|
name: schemas.pathParams.name,
|
|
100
100
|
pluginName,
|
|
101
101
|
type
|
|
102
102
|
}) : void 0,
|
|
103
|
-
query: schemas.queryParams?.name ?
|
|
103
|
+
query: schemas.queryParams?.name ? driver.resolveName({
|
|
104
104
|
name: schemas.queryParams.name,
|
|
105
105
|
pluginName,
|
|
106
106
|
type
|
|
107
107
|
}) : void 0,
|
|
108
|
-
header: schemas.headerParams?.name ?
|
|
108
|
+
header: schemas.headerParams?.name ? driver.resolveName({
|
|
109
109
|
name: schemas.headerParams.name,
|
|
110
110
|
pluginName,
|
|
111
111
|
type
|
|
@@ -113,7 +113,7 @@ function useOperationManager(generator) {
|
|
|
113
113
|
},
|
|
114
114
|
responses: {
|
|
115
115
|
...responses,
|
|
116
|
-
["default"]:
|
|
116
|
+
["default"]: driver.resolveName({
|
|
117
117
|
name: schemas.response.name,
|
|
118
118
|
pluginName,
|
|
119
119
|
type
|
|
@@ -139,9 +139,9 @@ function useOperationManager(generator) {
|
|
|
139
139
|
*/
|
|
140
140
|
function useSchemaManager() {
|
|
141
141
|
const plugin = (0, _kubb_core_hooks.usePlugin)();
|
|
142
|
-
const
|
|
142
|
+
const driver = (0, _kubb_core_hooks.usePluginDriver)();
|
|
143
143
|
const getName = (name, { pluginName = plugin.name, type }) => {
|
|
144
|
-
return
|
|
144
|
+
return driver.resolveName({
|
|
145
145
|
name,
|
|
146
146
|
pluginName,
|
|
147
147
|
type
|
|
@@ -152,7 +152,7 @@ function useSchemaManager() {
|
|
|
152
152
|
type: "file",
|
|
153
153
|
pluginName
|
|
154
154
|
});
|
|
155
|
-
const file =
|
|
155
|
+
const file = driver.getFile({
|
|
156
156
|
name: resolvedName,
|
|
157
157
|
extname,
|
|
158
158
|
pluginName,
|
package/dist/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":[],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperationManager.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use schemaNode or operationNode instead\n */\nexport function useOas(): Oas {\n const { meta } = useFabric<{ oas: Oas }>()\n\n return meta.oas\n}\n","import type { FileMetaBase, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationGenerator } from '../OperationGenerator.ts'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginName: string\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginName?: string\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginName?: string\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginName?: string\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginName?: string; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` returns helper functions to get the operation file and operation name.\n */\nexport function useOperationManager<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions>(\n generator: Omit<OperationGenerator<TPluginOptions>, 'build'>,\n): UseOperationManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginName = plugin.name, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginName,\n type,\n })\n }\n\n const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {\n return {\n tag: operation.getTags().at(0)?.name,\n path: operation.path,\n }\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginName: params?.pluginName,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginName = plugin.name, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginName, prefix, suffix })\n const group = getGroup(operation)\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginName,\n options: { type: 'file', pluginName, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginName,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginName = plugin.name, type }) => {\n if (!generator) {\n throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginName,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n const responses = (schemas.responses || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginName,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginName,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginName,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginName,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginName,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginName,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n getGroup,\n }\n}\n","import type { FileMetaBase, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\n\ntype FileMeta = FileMetaBase & {\n pluginName: string\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginName?: string; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginName?: string\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n}\n\n/**\n * `useSchemaManager` returns helper functions to get the schema file and schema name.\n * @deprecated\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginName = plugin.name, type }) => {\n return pluginManager.resolveName({\n name,\n pluginName,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginName = plugin.name, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginName })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginName,\n options: { type: 'file', pluginName, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginName,\n },\n }\n }\n\n return {\n getName,\n getFile,\n }\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,SAAc;CAC5B,MAAM,EAAE,UAAA,GAAA,mBAAA,YAAkC;AAE1C,QAAO,KAAK;;;;;;;ACsDd,SAAgB,oBACd,WAC2B;CAC3B,MAAM,UAAA,GAAA,iBAAA,YAAoB;CAC1B,MAAM,iBAAA,GAAA,iBAAA,mBAAkC;CAExC,MAAM,WAAiD,WAAW,EAAE,SAAS,IAAI,SAAS,IAAI,aAAa,OAAO,MAAM,WAAW;AACjI,SAAO,cAAc,YAAY;GAC/B,MAAM,GAAG,OAAO,GAAG,UAAU,gBAAgB,CAAC,GAAG;GACjD;GACA;GACD,CAAC;;CAGJ,MAAM,YAAmD,cAAc;AACrE,SAAO;GACL,KAAK,UAAU,SAAS,CAAC,GAAG,EAAE,EAAE;GAChC,MAAM,UAAU;GACjB;;CAGH,MAAM,cAAuD,WAAW,WAAW;AACjF,MAAI,CAAC,UACH,OAAM,IAAI,MAAM,8EAA8E;AAGhG,SAAO,UAAU,WAAW,WAAW,EACrC,cAAc,SACZ,cAAc,YAAY;GACxB;GACA,YAAY,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,YAAY;KACxB,MAAM,QAAQ,YAAY;KAC1B;KACA;KACD,CAAC,GACF,KAAA;IACJ,QAAQ,QAAQ,cAAc,OAC1B,cAAc,YAAY;KACxB,MAAM,QAAQ,aAAa;KAC3B;KACA;KACD,CAAC,GACF,KAAA;IACL;GACD,WAAW;IACT,GAAG;KACF,YAAY,cAAc,YAAY;KACrC,MAAM,QAAQ,SAAS;KACvB;KACA;KACD,CAAC;IACF,GAAG;IACJ;GACD;GACD;;AAGH,QAAO;EACL;EACA;EACA;EACA;EACA;EACD;;;;;;;;ACpLH,SAAgB,mBAA2C;CACzD,MAAM,UAAA,GAAA,iBAAA,YAAoB;CAC1B,MAAM,iBAAA,GAAA,iBAAA,mBAAkC;CAExC,MAAM,WAA8C,MAAM,EAAE,aAAa,OAAO,MAAM,WAAW;AAC/F,SAAO,cAAc,YAAY;GAC/B;GACA;GACA;GACD,CAAC;;CAGJ,MAAM,WAA8C,MAAM,EAAE,OAAO,SAAS,aAAa,OAAO,MAAM,UAAU,OAAO,UAAU,EAAE,KAAK;EACtI,MAAM,eAAe,SAAS,WAAW,KAAK,QAAQ,MAAM;GAAE,MAAM;GAAQ;GAAY,CAAC;EAEzF,MAAM,OAAO,cAAc,QAAQ;GACjC,MAAM;GACN;GACA;GACA,SAAS;IAAE,MAAM;IAAQ;IAAY;IAAO;GAC7C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR,MAAM;IACN;IACD;GACF;;AAGH,QAAO;EACL;EACA;EACD"}
|
|
1
|
+
{"version":3,"file":"hooks.cjs","names":[],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperationManager.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use schemaNode or operationNode instead\n */\nexport function useOas(): Oas {\n const { meta } = useFabric<{ oas: Oas }>()\n\n return meta.oas\n}\n","import type { FileMetaBase, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginDriver } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationGenerator } from '../OperationGenerator.ts'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginName: string\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginName?: string\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginName?: string\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginName?: string\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginName?: string; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` returns helper functions to get the operation file and operation name.\n */\nexport function useOperationManager<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions>(\n generator: Omit<OperationGenerator<TPluginOptions>, 'build'>,\n): UseOperationManagerResult {\n const plugin = usePlugin()\n const driver = usePluginDriver()\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginName = plugin.name, type }) => {\n return driver.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginName,\n type,\n })\n }\n\n const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {\n return {\n tag: operation.getTags().at(0)?.name,\n path: operation.path,\n }\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n driver.resolveName({\n name,\n pluginName: params?.pluginName,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginName = plugin.name, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginName, prefix, suffix })\n const group = getGroup(operation)\n\n const file = driver.getFile({\n name,\n extname,\n pluginName,\n options: { type: 'file', pluginName, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginName,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginName = plugin.name, type }) => {\n if (!generator) {\n throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = driver.resolveName({\n name: acc.name,\n pluginName,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n const responses = (schemas.responses || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = driver.resolveName({\n name: acc.name,\n pluginName,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? driver.resolveName({\n name: schemas.request.name,\n pluginName,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? driver.resolveName({\n name: schemas.pathParams.name,\n pluginName,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? driver.resolveName({\n name: schemas.queryParams.name,\n pluginName,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? driver.resolveName({\n name: schemas.headerParams.name,\n pluginName,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: driver.resolveName({\n name: schemas.response.name,\n pluginName,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n getGroup,\n }\n}\n","import type { FileMetaBase, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginDriver } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\n\ntype FileMeta = FileMetaBase & {\n pluginName: string\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginName?: string; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginName?: string\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n}\n\n/**\n * `useSchemaManager` returns helper functions to get the schema file and schema name.\n * @deprecated\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const plugin = usePlugin()\n const driver = usePluginDriver()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginName = plugin.name, type }) => {\n return driver.resolveName({\n name,\n pluginName,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginName = plugin.name, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginName })\n\n const file = driver.getFile({\n name: resolvedName,\n extname,\n pluginName,\n options: { type: 'file', pluginName, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginName,\n },\n }\n }\n\n return {\n getName,\n getFile,\n }\n}\n"],"mappings":";;;;;;;;AAOA,SAAgB,SAAc;CAC5B,MAAM,EAAE,UAAA,GAAA,mBAAA,YAAkC;AAE1C,QAAO,KAAK;;;;;;;ACsDd,SAAgB,oBACd,WAC2B;CAC3B,MAAM,UAAA,GAAA,iBAAA,YAAoB;CAC1B,MAAM,UAAA,GAAA,iBAAA,kBAA0B;CAEhC,MAAM,WAAiD,W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,MAAM;IAAQ;IAAY;IAAO;GAC7C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR,MAAM;IACN;IACD;GACF;;AAGH,QAAO;EACL;EACA;EACD"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-
|
|
2
|
+
import { d as OperationGenerator, g as OperationSchemas } from "./createGenerator-BnX0BloB.js";
|
|
3
3
|
import { Oas, Operation } from "@kubb/oas";
|
|
4
4
|
import { FileMetaBase, PluginFactoryOptions, ResolveNameParams } from "@kubb/core";
|
|
5
5
|
import { KubbFile } from "@kubb/fabric-core/types";
|
package/dist/hooks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
2
|
import { useFabric } from "@kubb/react-fabric";
|
|
3
|
-
import { usePlugin,
|
|
3
|
+
import { usePlugin, usePluginDriver } from "@kubb/core/hooks";
|
|
4
4
|
//#region src/hooks/useOas.ts
|
|
5
5
|
/**
|
|
6
6
|
* @deprecated use schemaNode or operationNode instead
|
|
@@ -16,9 +16,9 @@ function useOas() {
|
|
|
16
16
|
*/
|
|
17
17
|
function useOperationManager(generator) {
|
|
18
18
|
const plugin = usePlugin();
|
|
19
|
-
const
|
|
19
|
+
const driver = usePluginDriver();
|
|
20
20
|
const getName = (operation, { prefix = "", suffix = "", pluginName = plugin.name, type }) => {
|
|
21
|
-
return
|
|
21
|
+
return driver.resolveName({
|
|
22
22
|
name: `${prefix} ${operation.getOperationId()} ${suffix}`,
|
|
23
23
|
pluginName,
|
|
24
24
|
type
|
|
@@ -32,7 +32,7 @@ function useOperationManager(generator) {
|
|
|
32
32
|
};
|
|
33
33
|
const getSchemas = (operation, params) => {
|
|
34
34
|
if (!generator) throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`);
|
|
35
|
-
return generator.getSchemas(operation, { resolveName: (name) =>
|
|
35
|
+
return generator.getSchemas(operation, { resolveName: (name) => driver.resolveName({
|
|
36
36
|
name,
|
|
37
37
|
pluginName: params?.pluginName,
|
|
38
38
|
type: params?.type
|
|
@@ -46,7 +46,7 @@ function useOperationManager(generator) {
|
|
|
46
46
|
suffix
|
|
47
47
|
});
|
|
48
48
|
const group = getGroup(operation);
|
|
49
|
-
const file =
|
|
49
|
+
const file = driver.getFile({
|
|
50
50
|
name,
|
|
51
51
|
extname,
|
|
52
52
|
pluginName,
|
|
@@ -71,7 +71,7 @@ function useOperationManager(generator) {
|
|
|
71
71
|
const schemas = generator.getSchemas(operation);
|
|
72
72
|
const errors = (schemas.errors || []).reduce((prev, acc) => {
|
|
73
73
|
if (!acc.statusCode) return prev;
|
|
74
|
-
prev[acc.statusCode] =
|
|
74
|
+
prev[acc.statusCode] = driver.resolveName({
|
|
75
75
|
name: acc.name,
|
|
76
76
|
pluginName,
|
|
77
77
|
type
|
|
@@ -80,7 +80,7 @@ function useOperationManager(generator) {
|
|
|
80
80
|
}, {});
|
|
81
81
|
const responses = (schemas.responses || []).reduce((prev, acc) => {
|
|
82
82
|
if (!acc.statusCode) return prev;
|
|
83
|
-
prev[acc.statusCode] =
|
|
83
|
+
prev[acc.statusCode] = driver.resolveName({
|
|
84
84
|
name: acc.name,
|
|
85
85
|
pluginName,
|
|
86
86
|
type
|
|
@@ -88,23 +88,23 @@ function useOperationManager(generator) {
|
|
|
88
88
|
return prev;
|
|
89
89
|
}, {});
|
|
90
90
|
return {
|
|
91
|
-
request: schemas.request?.name ?
|
|
91
|
+
request: schemas.request?.name ? driver.resolveName({
|
|
92
92
|
name: schemas.request.name,
|
|
93
93
|
pluginName,
|
|
94
94
|
type
|
|
95
95
|
}) : void 0,
|
|
96
96
|
parameters: {
|
|
97
|
-
path: schemas.pathParams?.name ?
|
|
97
|
+
path: schemas.pathParams?.name ? driver.resolveName({
|
|
98
98
|
name: schemas.pathParams.name,
|
|
99
99
|
pluginName,
|
|
100
100
|
type
|
|
101
101
|
}) : void 0,
|
|
102
|
-
query: schemas.queryParams?.name ?
|
|
102
|
+
query: schemas.queryParams?.name ? driver.resolveName({
|
|
103
103
|
name: schemas.queryParams.name,
|
|
104
104
|
pluginName,
|
|
105
105
|
type
|
|
106
106
|
}) : void 0,
|
|
107
|
-
header: schemas.headerParams?.name ?
|
|
107
|
+
header: schemas.headerParams?.name ? driver.resolveName({
|
|
108
108
|
name: schemas.headerParams.name,
|
|
109
109
|
pluginName,
|
|
110
110
|
type
|
|
@@ -112,7 +112,7 @@ function useOperationManager(generator) {
|
|
|
112
112
|
},
|
|
113
113
|
responses: {
|
|
114
114
|
...responses,
|
|
115
|
-
["default"]:
|
|
115
|
+
["default"]: driver.resolveName({
|
|
116
116
|
name: schemas.response.name,
|
|
117
117
|
pluginName,
|
|
118
118
|
type
|
|
@@ -138,9 +138,9 @@ function useOperationManager(generator) {
|
|
|
138
138
|
*/
|
|
139
139
|
function useSchemaManager() {
|
|
140
140
|
const plugin = usePlugin();
|
|
141
|
-
const
|
|
141
|
+
const driver = usePluginDriver();
|
|
142
142
|
const getName = (name, { pluginName = plugin.name, type }) => {
|
|
143
|
-
return
|
|
143
|
+
return driver.resolveName({
|
|
144
144
|
name,
|
|
145
145
|
pluginName,
|
|
146
146
|
type
|
|
@@ -151,7 +151,7 @@ function useSchemaManager() {
|
|
|
151
151
|
type: "file",
|
|
152
152
|
pluginName
|
|
153
153
|
});
|
|
154
|
-
const file =
|
|
154
|
+
const file = driver.getFile({
|
|
155
155
|
name: resolvedName,
|
|
156
156
|
extname,
|
|
157
157
|
pluginName,
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperationManager.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use schemaNode or operationNode instead\n */\nexport function useOas(): Oas {\n const { meta } = useFabric<{ oas: Oas }>()\n\n return meta.oas\n}\n","import type { FileMetaBase, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationGenerator } from '../OperationGenerator.ts'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginName: string\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginName?: string\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginName?: string\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginName?: string\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginName?: string; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` returns helper functions to get the operation file and operation name.\n */\nexport function useOperationManager<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions>(\n generator: Omit<OperationGenerator<TPluginOptions>, 'build'>,\n): UseOperationManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginName = plugin.name, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginName,\n type,\n })\n }\n\n const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {\n return {\n tag: operation.getTags().at(0)?.name,\n path: operation.path,\n }\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginName: params?.pluginName,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginName = plugin.name, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginName, prefix, suffix })\n const group = getGroup(operation)\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginName,\n options: { type: 'file', pluginName, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginName,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginName = plugin.name, type }) => {\n if (!generator) {\n throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginName,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n const responses = (schemas.responses || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = pluginManager.resolveName({\n name: acc.name,\n pluginName,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? pluginManager.resolveName({\n name: schemas.request.name,\n pluginName,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginName,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginName,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginName,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginName,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n getGroup,\n }\n}\n","import type { FileMetaBase, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\n\ntype FileMeta = FileMetaBase & {\n pluginName: string\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginName?: string; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginName?: string\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n}\n\n/**\n * `useSchemaManager` returns helper functions to get the schema file and schema name.\n * @deprecated\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginName = plugin.name, type }) => {\n return pluginManager.resolveName({\n name,\n pluginName,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginName = plugin.name, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginName })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginName,\n options: { type: 'file', pluginName, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginName,\n },\n }\n }\n\n return {\n getName,\n getFile,\n }\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,SAAc;CAC5B,MAAM,EAAE,SAAS,WAAyB;AA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;GAAE,MAAM;GAAQ;GAAY,CAAC;EAEzF,MAAM,OAAO,cAAc,QAAQ;GACjC,MAAM;GACN;GACA;GACA,SAAS;IAAE,MAAM;IAAQ;IAAY;IAAO;GAC7C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR,MAAM;IACN;IACD;GACF;;AAGH,QAAO;EACL;EACA;EACD"}
|
|
1
|
+
{"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperationManager.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import type { Oas } from '@kubb/oas'\n\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use schemaNode or operationNode instead\n */\nexport function useOas(): Oas {\n const { meta } = useFabric<{ oas: Oas }>()\n\n return meta.oas\n}\n","import type { FileMetaBase, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginDriver } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationGenerator } from '../OperationGenerator.ts'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginName: string\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\nexport type SchemaNames = {\n request: string | undefined\n parameters: {\n path: string | undefined\n query: string | undefined\n header: string | undefined\n }\n responses: { default?: string } & Record<number | string, string>\n errors: Record<number | string, string>\n}\n\ntype UseOperationManagerResult = {\n getName: (\n operation: OperationType,\n params: {\n prefix?: string\n suffix?: string\n pluginName?: string\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginName?: string\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n groupSchemasByName: (\n operation: OperationType,\n params: {\n pluginName?: string\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginName?: string; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` returns helper functions to get the operation file and operation name.\n */\nexport function useOperationManager<TPluginOptions extends PluginFactoryOptions = PluginFactoryOptions>(\n generator: Omit<OperationGenerator<TPluginOptions>, 'build'>,\n): UseOperationManagerResult {\n const plugin = usePlugin()\n const driver = usePluginDriver()\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginName = plugin.name, type }) => {\n return driver.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginName,\n type,\n })\n }\n\n const getGroup: UseOperationManagerResult['getGroup'] = (operation) => {\n return {\n tag: operation.getTags().at(0)?.name,\n path: operation.path,\n }\n }\n\n const getSchemas: UseOperationManagerResult['getSchemas'] = (operation, params) => {\n if (!generator) {\n throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n driver.resolveName({\n name,\n pluginName: params?.pluginName,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginName = plugin.name, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginName, prefix, suffix })\n const group = getGroup(operation)\n\n const file = driver.getFile({\n name,\n extname,\n pluginName,\n options: { type: 'file', pluginName, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginName,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginName = plugin.name, type }) => {\n if (!generator) {\n throw new Error(`useOperationManager: 'generator' parameter is required but was not provided`)\n }\n\n const schemas = generator.getSchemas(operation)\n\n const errors = (schemas.errors || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = driver.resolveName({\n name: acc.name,\n pluginName,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n const responses = (schemas.responses || []).reduce(\n (prev, acc) => {\n if (!acc.statusCode) {\n return prev\n }\n\n prev[acc.statusCode] = driver.resolveName({\n name: acc.name,\n pluginName,\n type,\n })\n\n return prev\n },\n {} as Record<number, string>,\n )\n\n return {\n request: schemas.request?.name\n ? driver.resolveName({\n name: schemas.request.name,\n pluginName,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? driver.resolveName({\n name: schemas.pathParams.name,\n pluginName,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? driver.resolveName({\n name: schemas.queryParams.name,\n pluginName,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? driver.resolveName({\n name: schemas.headerParams.name,\n pluginName,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: driver.resolveName({\n name: schemas.response.name,\n pluginName,\n type,\n }),\n ...errors,\n },\n errors,\n }\n }\n\n return {\n getName,\n getFile,\n getSchemas,\n groupSchemasByName,\n getGroup,\n }\n}\n","import type { FileMetaBase, ResolveNameParams } from '@kubb/core'\nimport { usePlugin, usePluginDriver } from '@kubb/core/hooks'\nimport type { KubbFile } from '@kubb/fabric-core/types'\n\ntype FileMeta = FileMetaBase & {\n pluginName: string\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginName?: string; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginName?: string\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n}\n\n/**\n * `useSchemaManager` returns helper functions to get the schema file and schema name.\n * @deprecated\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const plugin = usePlugin()\n const driver = usePluginDriver()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginName = plugin.name, type }) => {\n return driver.resolveName({\n name,\n pluginName,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginName = plugin.name, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginName })\n\n const file = driver.getFile({\n name: resolvedName,\n extname,\n pluginName,\n options: { type: 'file', pluginName, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginName,\n },\n }\n }\n\n return {\n getName,\n getFile,\n }\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,SAAc;CAC5B,MAAM,EAAE,SAAS,WAAyB;AAE1C,QAAO,KAAK;;;;;;;ACsDd,SAAgB,oBACd,WAC2B;CAC3B,MAAM,SAAS,WAAW;CAC1B,MAAM,SAAS,iBAAiB;CAEhC,MAAM,WAAiD,WAAW,EAAE,SAAS,IAAI,SAAS,IAAI,aAAa,OAAO,MAAM,WAAW;AACjI,SAAO,OAAO,YAAY;GACxB,MAAM,GAAG,OAAO,GAAG,UAAU,gBAAgB,CAAC,GAAG;GACjD;GACA;GACD,CAAC;;CAGJ,MAAM,YAAmD,cAAc;AACrE,SAAO;GACL,KAAK,UAAU,SAAS,CAAC,GAAG,EAAE,EAAE;GAChC,MAAM,UAAU;GACjB;;CAGH,MAAM,cAAuD,WAAW,WAAW;AACjF,MAAI,CAAC,UACH,OAAM,IAAI,MAAM,8EAA8E;AAGhG,SAAO,UAAU,WAAW,WAAW,EACrC,cAAc,SACZ,OAAO,YAAY;GACjB;GACA,YAAY,QAAQ;GACpB,MAAM,QAAQ;GACf,CAAC,EACL,CAAC;;CAGJ,MAAM,WAAiD,WAAW,EAAE,QAAQ,QAAQ,aAAa,OAAO,MAAM,UAAU,UAAU,EAAE,KAAK;EACvI,MAAM,OAAO,QAAQ,WAAW;GAAE,MAAM;GAAQ;GAAY;GAAQ;GAAQ,CAAC;EAC7E,MAAM,QAAQ,SAAS,UAAU;EAEjC,MAAM,OAAO,OAAO,QAAQ;GAC1B;GACA;GACA;GACA,SAAS;IA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;EACA;EACA;EACA;EACA;EACD;;;;;;;;ACpLH,SAAgB,mBAA2C;CACzD,MAAM,SAAS,WAAW;CAC1B,MAAM,SAAS,iBAAiB;CAEhC,MAAM,WAA8C,MAAM,EAAE,aAAa,OAAO,MAAM,WAAW;AAC/F,SAAO,OAAO,YAAY;GACxB;GACA;GACA;GACD,CAAC;;CAGJ,MAAM,WAA8C,MAAM,EAAE,OAAO,SAAS,aAAa,OAAO,MAAM,UAAU,OAAO,UAAU,EAAE,KAAK;EACtI,MAAM,eAAe,SAAS,WAAW,KAAK,QAAQ,MAAM;GAAE,MAAM;GAAQ;GAAY,CAAC;EAEzF,MAAM,OAAO,OAAO,QAAQ;GAC1B,MAAM;GACN;GACA;GACA,SAAS;IAAE,MAAM;IAAQ;IAAY;IAAO;GAC7C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR,MAAM;IACN;IACD;GACF;;AAGH,QAAO;EACL;EACA;EACD"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
3
|
-
const require_generators = require("./generators-
|
|
3
|
+
const require_generators = require("./generators-BfTTScuN.cjs");
|
|
4
4
|
const require_getFooter = require("./getFooter-BBzsC616.cjs");
|
|
5
|
-
const require_requestBody = require("./requestBody-
|
|
5
|
+
const require_requestBody = require("./requestBody-DyTNWJql.cjs");
|
|
6
6
|
const require_SchemaMapper = require("./SchemaMapper-CeavHZlp.cjs");
|
|
7
7
|
let node_path = require("node:path");
|
|
8
8
|
node_path = require_chunk.__toESM(node_path);
|
|
@@ -229,7 +229,7 @@ var OperationGenerator = class {
|
|
|
229
229
|
const options = this.getOptions(operation, method);
|
|
230
230
|
if (v1Generator.type === "react") {
|
|
231
231
|
await require_requestBody.buildOperation(operation, {
|
|
232
|
-
config: this.context.
|
|
232
|
+
config: this.context.driver.config,
|
|
233
233
|
fabric: this.context.fabric,
|
|
234
234
|
Component: v1Generator.Operation,
|
|
235
235
|
generator: this,
|
|
@@ -245,7 +245,7 @@ var OperationGenerator = class {
|
|
|
245
245
|
}
|
|
246
246
|
return await v1Generator.operation?.({
|
|
247
247
|
generator: this,
|
|
248
|
-
config: this.context.
|
|
248
|
+
config: this.context.driver.config,
|
|
249
249
|
operation,
|
|
250
250
|
plugin: {
|
|
251
251
|
...this.context.plugin,
|
|
@@ -260,7 +260,7 @@ var OperationGenerator = class {
|
|
|
260
260
|
if (v1Generator.type === "react") {
|
|
261
261
|
await require_requestBody.buildOperations(operations.map((op) => op.operation), {
|
|
262
262
|
fabric: this.context.fabric,
|
|
263
|
-
config: this.context.
|
|
263
|
+
config: this.context.driver.config,
|
|
264
264
|
Component: v1Generator.Operations,
|
|
265
265
|
generator: this,
|
|
266
266
|
plugin: this.context.plugin
|
|
@@ -269,7 +269,7 @@ var OperationGenerator = class {
|
|
|
269
269
|
}
|
|
270
270
|
const operationsResult = await v1Generator.operations?.({
|
|
271
271
|
generator: this,
|
|
272
|
-
config: this.context.
|
|
272
|
+
config: this.context.driver.config,
|
|
273
273
|
operations: operations.map((op) => op.operation),
|
|
274
274
|
plugin: this.context.plugin
|
|
275
275
|
});
|
|
@@ -368,7 +368,7 @@ const pluginOas = (0, _kubb_core.definePlugin)((options) => {
|
|
|
368
368
|
}, {
|
|
369
369
|
fabric: this.fabric,
|
|
370
370
|
oas,
|
|
371
|
-
|
|
371
|
+
driver: this.driver,
|
|
372
372
|
events: this.events,
|
|
373
373
|
plugin: this.plugin,
|
|
374
374
|
contentType,
|
|
@@ -381,7 +381,7 @@ const pluginOas = (0, _kubb_core.definePlugin)((options) => {
|
|
|
381
381
|
const operationFiles = await new OperationGenerator(this.plugin.options, {
|
|
382
382
|
fabric: this.fabric,
|
|
383
383
|
oas,
|
|
384
|
-
|
|
384
|
+
driver: this.driver,
|
|
385
385
|
events: this.events,
|
|
386
386
|
plugin: this.plugin,
|
|
387
387
|
contentType,
|