@kubb/plugin-oas 4.1.4 → 4.2.1
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/{Oas-CuqAnIw-.js → Oas-DoN76W2_.js} +2 -2
- package/dist/{Oas-CuqAnIw-.js.map → Oas-DoN76W2_.js.map} +1 -1
- package/dist/{OperationGenerator-B3oFps4I.d.ts → OperationGenerator-BeVo1_b1.d.cts} +87 -157
- package/dist/{OperationGenerator-aKcfGbOt.d.cts → OperationGenerator-CUE372Ht.d.ts} +87 -157
- package/dist/{Schema-DxWT5L8_.d.ts → Schema-BPvUCUWJ.d.ts} +7 -8
- package/dist/{Schema-CEmdFRTN.d.cts → Schema-D-wz873C.d.cts} +7 -8
- package/dist/{SchemaGenerator-Dnllsi8M.cjs → SchemaGenerator-BQUPa5AD.cjs} +2 -3
- package/dist/{SchemaGenerator-Dnllsi8M.cjs.map → SchemaGenerator-BQUPa5AD.cjs.map} +1 -1
- package/dist/{SchemaGenerator-TL2a9FN6.js → SchemaGenerator-DYOXlswO.js} +5 -6
- package/dist/{SchemaGenerator-TL2a9FN6.js.map → SchemaGenerator-DYOXlswO.js.map} +1 -1
- package/dist/{SchemaMapper-BiagBQN4.d.cts → SchemaMapper-BWDIvdP9.d.ts} +2 -2
- package/dist/{SchemaMapper-C2J2d3o4.d.ts → SchemaMapper-BvE5JflR.d.cts} +2 -2
- package/dist/{SchemaMapper-BaZQKrQB.js → SchemaMapper-CqOUibvI.js} +2 -2
- package/dist/{SchemaMapper-BaZQKrQB.js.map → SchemaMapper-CqOUibvI.js.map} +1 -1
- package/dist/components.d.cts +7 -19
- package/dist/components.d.ts +7 -19
- package/dist/components.js +1 -1
- package/dist/{generators-L3av7_7B.cjs → generators-BIyNritE.cjs} +76 -61
- package/dist/generators-BIyNritE.cjs.map +1 -0
- package/dist/{generators-CW7v1RgJ.js → generators-CJBwMPUb.js} +79 -64
- package/dist/generators-CJBwMPUb.js.map +1 -0
- package/dist/generators.cjs +2 -2
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/generators.js +3 -3
- package/dist/getFooter-CvTKkK7-.js +58 -0
- package/dist/getFooter-CvTKkK7-.js.map +1 -0
- package/dist/getFooter-pQXwqM81.cjs +72 -0
- package/dist/getFooter-pQXwqM81.cjs.map +1 -0
- package/dist/{getSchemas-WoSBIxG8.js → getSchemas-CvUX0jWa.js} +2 -2
- package/dist/{getSchemas-WoSBIxG8.js.map → getSchemas-CvUX0jWa.js.map} +1 -1
- package/dist/hooks.cjs +7 -3
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +3 -3
- package/dist/hooks.d.ts +3 -3
- package/dist/hooks.js +10 -7
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +1 -1
- package/dist/{parseFromConfig-yAiFK03V.js → parseFromConfig-DSI6Meg0.js} +5 -10
- package/dist/parseFromConfig-DSI6Meg0.js.map +1 -0
- package/dist/{parseFromConfig-CFzprC8B.cjs → parseFromConfig-o3tU1XJt.cjs} +4 -9
- package/dist/parseFromConfig-o3tU1XJt.cjs.map +1 -0
- package/dist/utils.cjs +2 -2
- package/dist/utils.d.cts +6 -9
- package/dist/utils.d.ts +6 -9
- package/dist/utils.js +3 -3
- package/package.json +5 -7
- package/src/generator.tsx +50 -43
- package/src/hooks/useOperationManager.ts +5 -6
- package/src/hooks/useSchemaManager.ts +3 -3
- package/src/plugin.ts +2 -3
- package/src/utils/getBanner.ts +47 -1
- package/dist/generators-CW7v1RgJ.js.map +0 -1
- package/dist/generators-L3av7_7B.cjs.map +0 -1
- package/dist/getFooter-B_nmsoeK.cjs +0 -45
- package/dist/getFooter-B_nmsoeK.cjs.map +0 -1
- package/dist/getFooter-DM8B8cnC.js +0 -31
- package/dist/getFooter-DM8B8cnC.js.map +0 -1
- package/dist/parseFromConfig-CFzprC8B.cjs.map +0 -1
- package/dist/parseFromConfig-yAiFK03V.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
2
|
const require_Oas = require('./Oas--cvTRMTA.cjs');
|
|
3
|
-
const require_getFooter = require('./getFooter-
|
|
3
|
+
const require_getFooter = require('./getFooter-pQXwqM81.cjs');
|
|
4
4
|
let __kubb_core_transformers = require("@kubb/core/transformers");
|
|
5
5
|
__kubb_core_transformers = require_chunk.__toESM(__kubb_core_transformers);
|
|
6
6
|
let __kubb_react = require("@kubb/react");
|
|
@@ -25,80 +25,95 @@ function createReactGenerator(parseOptions) {
|
|
|
25
25
|
async operations({ instance, options, operations }) {
|
|
26
26
|
if (!parseOptions.Operations) return [];
|
|
27
27
|
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(Component, {
|
|
28
|
+
const Operations = parseOptions.Operations;
|
|
29
|
+
function Component() {
|
|
30
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.App, {
|
|
31
|
+
meta: {
|
|
32
|
+
pluginManager,
|
|
33
|
+
plugin,
|
|
34
|
+
mode
|
|
35
|
+
},
|
|
36
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas, {
|
|
37
|
+
oas,
|
|
39
38
|
operations,
|
|
40
|
-
instance,
|
|
41
|
-
|
|
39
|
+
generator: instance,
|
|
40
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(Operations, {
|
|
41
|
+
operations,
|
|
42
|
+
instance,
|
|
43
|
+
options
|
|
44
|
+
})
|
|
42
45
|
})
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const app = (0, __kubb_react.createApp)(Component);
|
|
49
|
+
app.render();
|
|
50
|
+
return app.files;
|
|
46
51
|
},
|
|
47
52
|
async operation({ instance, operation, options }) {
|
|
48
53
|
if (!parseOptions.Operation) return [];
|
|
49
54
|
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(
|
|
55
|
+
const Operation = parseOptions.Operation;
|
|
56
|
+
function Component() {
|
|
57
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.App, {
|
|
58
|
+
meta: {
|
|
59
|
+
pluginManager,
|
|
60
|
+
plugin: {
|
|
61
|
+
...plugin,
|
|
62
|
+
options
|
|
63
|
+
},
|
|
64
|
+
mode
|
|
65
|
+
},
|
|
66
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas, {
|
|
67
|
+
oas,
|
|
68
|
+
operations: [operation],
|
|
69
|
+
generator: instance,
|
|
70
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas.Operation, {
|
|
66
71
|
operation,
|
|
67
|
-
|
|
68
|
-
|
|
72
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(Operation, {
|
|
73
|
+
operation,
|
|
74
|
+
options,
|
|
75
|
+
instance
|
|
76
|
+
})
|
|
69
77
|
})
|
|
70
78
|
})
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const app = (0, __kubb_react.createApp)(Component);
|
|
82
|
+
app.render();
|
|
83
|
+
return app.files;
|
|
74
84
|
},
|
|
75
85
|
async schema({ instance, schema, options }) {
|
|
76
86
|
if (!parseOptions.Schema) return [];
|
|
77
87
|
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
schema,
|
|
95
|
-
|
|
96
|
-
|
|
88
|
+
const Schema = parseOptions.Schema;
|
|
89
|
+
function Component() {
|
|
90
|
+
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.App, {
|
|
91
|
+
meta: {
|
|
92
|
+
pluginManager,
|
|
93
|
+
plugin: {
|
|
94
|
+
...plugin,
|
|
95
|
+
options
|
|
96
|
+
},
|
|
97
|
+
mode
|
|
98
|
+
},
|
|
99
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas, {
|
|
100
|
+
oas,
|
|
101
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas.Schema, {
|
|
102
|
+
name: schema.name,
|
|
103
|
+
schemaObject: schema.value,
|
|
104
|
+
tree: schema.tree,
|
|
105
|
+
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(Schema, {
|
|
106
|
+
schema,
|
|
107
|
+
options,
|
|
108
|
+
instance
|
|
109
|
+
})
|
|
97
110
|
})
|
|
98
111
|
})
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
const app = (0, __kubb_react.createApp)(Component);
|
|
115
|
+
app.render();
|
|
116
|
+
return app.files;
|
|
102
117
|
}
|
|
103
118
|
};
|
|
104
119
|
}
|
|
@@ -154,4 +169,4 @@ Object.defineProperty(exports, 'jsonGenerator', {
|
|
|
154
169
|
return jsonGenerator;
|
|
155
170
|
}
|
|
156
171
|
});
|
|
157
|
-
//# sourceMappingURL=generators-
|
|
172
|
+
//# sourceMappingURL=generators-BIyNritE.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-BIyNritE.cjs","names":["App","Oas","getBanner","getFooter"],"sources":["../src/generator.tsx","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/core/fs'\nimport type { Operation, SchemaObject } from '@kubb/oas'\nimport { App, createApp } from '@kubb/react'\nimport type { KubbNode } from '@kubb/react/types'\nimport { Oas } from './components/Oas.tsx'\nimport type { OperationGenerator } from './OperationGenerator.ts'\nimport type { SchemaGenerator, SchemaGeneratorOptions } from './SchemaGenerator.ts'\nimport type { Schema } from './SchemaMapper.ts'\n\ntype OperationsProps<TOptions extends PluginFactoryOptions> = {\n instance: Omit<OperationGenerator<TOptions>, 'build'>\n options: TOptions['resolvedOptions']\n operations: Array<Operation>\n}\n\ntype OperationProps<TOptions extends PluginFactoryOptions> = {\n instance: Omit<OperationGenerator<TOptions>, 'build'>\n options: TOptions['resolvedOptions']\n operation: Operation\n}\n\ntype SchemaProps<TOptions extends PluginFactoryOptions> = {\n instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>\n options: TOptions['resolvedOptions']\n schema: {\n name: string\n tree: Array<Schema>\n value: SchemaObject\n }\n}\n\nexport type GeneratorOptions<TOptions extends PluginFactoryOptions> = {\n name: string\n operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>\n\nexport function createGenerator<TOptions extends PluginFactoryOptions>(parseOptions: GeneratorOptions<TOptions>): Generator<TOptions> {\n return parseOptions\n}\n\nexport type ReactGeneratorOptions<TOptions extends PluginFactoryOptions> = {\n name: string\n Operations?: (this: ReactGeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => KubbNode\n Operation?: (this: ReactGeneratorOptions<TOptions>, props: OperationProps<TOptions>) => KubbNode\n Schema?: (this: ReactGeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => KubbNode\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>(parseOptions: ReactGeneratorOptions<TOptions>): Generator<TOptions> {\n return {\n ...parseOptions,\n async operations({ instance, options, operations }) {\n if (!parseOptions.Operations) {\n return []\n }\n\n const { pluginManager, oas, plugin, mode } = instance.context\n const Operations = parseOptions.Operations\n\n function Component() {\n return (\n <App meta={{ pluginManager, plugin, mode }}>\n <Oas oas={oas} operations={operations} generator={instance}>\n <Operations operations={operations} instance={instance} options={options} />\n </Oas>\n </App>\n )\n }\n const app = createApp(Component)\n\n app.render()\n return app.files\n },\n async operation({ instance, operation, options }) {\n if (!parseOptions.Operation) {\n return []\n }\n\n const { pluginManager, oas, plugin, mode } = instance.context\n const Operation = parseOptions.Operation\n\n function Component() {\n return (\n <App meta={{ pluginManager, plugin: { ...plugin, options }, mode }}>\n <Oas oas={oas} operations={[operation]} generator={instance}>\n <Oas.Operation operation={operation}>\n <Operation operation={operation} options={options} instance={instance} />\n </Oas.Operation>\n </Oas>\n </App>\n )\n }\n const app = createApp(Component)\n\n app.render()\n return app.files\n },\n async schema({ instance, schema, options }) {\n if (!parseOptions.Schema) {\n return []\n }\n\n const { pluginManager, oas, plugin, mode } = instance.context\n\n const Schema = parseOptions.Schema\n\n function Component() {\n return (\n <App meta={{ pluginManager, plugin: { ...plugin, options }, mode }}>\n <Oas oas={oas}>\n <Oas.Schema name={schema.name} schemaObject={schema.value} tree={schema.tree}>\n <Schema schema={schema} options={options} instance={instance} />\n </Oas.Schema>\n </Oas>\n </App>\n )\n }\n const app = createApp(Component)\n\n app.render()\n return app.files\n },\n }\n}\n","import { camelCase } from '@kubb/core/transformers'\nimport { createGenerator } from '../generator.tsx'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, instance }) {\n const { pluginManager, plugin } = instance.context\n const file = pluginManager.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginKey: plugin.key,\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: instance.context.oas,\n output: plugin.options.output,\n config: pluginManager.config,\n }),\n format: getFooter({ oas: instance.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;;;;;;;;;AAyCA,SAAgB,gBAAuD,cAA+D;AACpI,QAAO;;;;;;;;;AAiBT,SAAgB,qBAA4D,cAAoE;AAC9I,QAAO;EACL,GAAG;EACH,MAAM,WAAW,EAAE,UAAU,SAAS,cAAc;AAClD,OAAI,CAAC,aAAa,WAChB,QAAO,EAAE;GAGX,MAAM,EAAE,eAAe,KAAK,QAAQ,SAAS,SAAS;GACtD,MAAM,aAAa,aAAa;GAEhC,SAAS,YAAY;AACnB,WACE,kDAACA;KAAI,MAAM;MAAE;MAAe;MAAQ;MAAM;eACxC,kDAACC;MAAS;MAAiB;MAAY,WAAW;gBAChD,kDAAC;OAAuB;OAAsB;OAAmB;QAAW;OACxE;MACF;;GAGV,MAAM,kCAAgB,UAAU;AAEhC,OAAI,QAAQ;AACZ,UAAO,IAAI;;EAEb,MAAM,UAAU,EAAE,UAAU,WAAW,WAAW;AAChD,OAAI,CAAC,aAAa,UAChB,QAAO,EAAE;GAGX,MAAM,EAAE,eAAe,KAAK,QAAQ,SAAS,SAAS;GACtD,MAAM,YAAY,aAAa;GAE/B,SAAS,YAAY;AACnB,WACE,kDAACD;KAAI,MAAM;MAAE;MAAe,QAAQ;OAAE,GAAG;OAAQ;OAAS;MAAE;MAAM;eAChE,kDAACC;MAAS;MAAK,YAAY,CAAC,UAAU;MAAE,WAAW;gBACjD,kDAACA,gBAAI;OAAqB;iBACxB,kDAAC;QAAqB;QAAoB;QAAmB;SAAY;QAC3D;OACZ;MACF;;GAGV,MAAM,kCAAgB,UAAU;AAEhC,OAAI,QAAQ;AACZ,UAAO,IAAI;;EAEb,MAAM,OAAO,EAAE,UAAU,QAAQ,WAAW;AAC1C,OAAI,CAAC,aAAa,OAChB,QAAO,EAAE;GAGX,MAAM,EAAE,eAAe,KAAK,QAAQ,SAAS,SAAS;GAEtD,MAAM,SAAS,aAAa;GAE5B,SAAS,YAAY;AACnB,WACE,kDAACD;KAAI,MAAM;MAAE;MAAe,QAAQ;OAAE,GAAG;OAAQ;OAAS;MAAE;MAAM;eAChE,kDAACC;MAAS;gBACR,kDAACA,gBAAI;OAAO,MAAM,OAAO;OAAM,cAAc,OAAO;OAAO,MAAM,OAAO;iBACtE,kDAAC;QAAe;QAAiB;QAAmB;SAAY;QACrD;OACT;MACF;;GAGV,MAAM,kCAAgB,UAAU;AAEhC,OAAI,QAAQ;AACZ,UAAO,IAAI;;EAEd;;;;;AC/HH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,YAAY;EACjC,MAAM,EAAE,eAAe,WAAW,SAAS;AAQ3C,SAAO,CACL;GACE,GATS,cAAc,QAAQ;IACjC,8CAAgB,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,WAAW,OAAO;IACnB,CAAC;GAKE,SAAS,CACP;IACE,8CAAgB,OAAO,KAAK;IAC5B,cAAc;IACd,aAAa;IACb,OAAO,KAAK,UAAU,OAAO,MAAM;IACpC,CACF;GACD,QAAQC,4BAAU;IAChB,KAAK,SAAS,QAAQ;IACtB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,cAAc;IACvB,CAAC;GACF,QAAQC,4BAAU;IAAE,KAAK,SAAS,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GAChF,CACF;;CAEJ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Oas } from "./Oas-
|
|
2
|
-
import { getBanner, getFooter } from "./getFooter-
|
|
1
|
+
import { t as Oas } from "./Oas-DoN76W2_.js";
|
|
2
|
+
import { n as getBanner, t as getFooter } from "./getFooter-CvTKkK7-.js";
|
|
3
3
|
import { camelCase } from "@kubb/core/transformers";
|
|
4
|
-
import { App,
|
|
4
|
+
import { App, createApp } from "@kubb/react";
|
|
5
5
|
import { jsx } from "@kubb/react/jsx-runtime";
|
|
6
6
|
|
|
7
7
|
//#region src/generator.tsx
|
|
@@ -21,80 +21,95 @@ function createReactGenerator(parseOptions) {
|
|
|
21
21
|
async operations({ instance, options, operations }) {
|
|
22
22
|
if (!parseOptions.Operations) return [];
|
|
23
23
|
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
children: /* @__PURE__ */ jsx(Component, {
|
|
24
|
+
const Operations = parseOptions.Operations;
|
|
25
|
+
function Component() {
|
|
26
|
+
return /* @__PURE__ */ jsx(App, {
|
|
27
|
+
meta: {
|
|
28
|
+
pluginManager,
|
|
29
|
+
plugin,
|
|
30
|
+
mode
|
|
31
|
+
},
|
|
32
|
+
children: /* @__PURE__ */ jsx(Oas, {
|
|
33
|
+
oas,
|
|
35
34
|
operations,
|
|
36
|
-
instance,
|
|
37
|
-
|
|
35
|
+
generator: instance,
|
|
36
|
+
children: /* @__PURE__ */ jsx(Operations, {
|
|
37
|
+
operations,
|
|
38
|
+
instance,
|
|
39
|
+
options
|
|
40
|
+
})
|
|
38
41
|
})
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const app = createApp(Component);
|
|
45
|
+
app.render();
|
|
46
|
+
return app.files;
|
|
42
47
|
},
|
|
43
48
|
async operation({ instance, operation, options }) {
|
|
44
49
|
if (!parseOptions.Operation) return [];
|
|
45
50
|
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
children: /* @__PURE__ */ jsx(
|
|
51
|
+
const Operation = parseOptions.Operation;
|
|
52
|
+
function Component() {
|
|
53
|
+
return /* @__PURE__ */ jsx(App, {
|
|
54
|
+
meta: {
|
|
55
|
+
pluginManager,
|
|
56
|
+
plugin: {
|
|
57
|
+
...plugin,
|
|
58
|
+
options
|
|
59
|
+
},
|
|
60
|
+
mode
|
|
61
|
+
},
|
|
62
|
+
children: /* @__PURE__ */ jsx(Oas, {
|
|
63
|
+
oas,
|
|
64
|
+
operations: [operation],
|
|
65
|
+
generator: instance,
|
|
66
|
+
children: /* @__PURE__ */ jsx(Oas.Operation, {
|
|
62
67
|
operation,
|
|
63
|
-
|
|
64
|
-
|
|
68
|
+
children: /* @__PURE__ */ jsx(Operation, {
|
|
69
|
+
operation,
|
|
70
|
+
options,
|
|
71
|
+
instance
|
|
72
|
+
})
|
|
65
73
|
})
|
|
66
74
|
})
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const app = createApp(Component);
|
|
78
|
+
app.render();
|
|
79
|
+
return app.files;
|
|
70
80
|
},
|
|
71
81
|
async schema({ instance, schema, options }) {
|
|
72
82
|
if (!parseOptions.Schema) return [];
|
|
73
83
|
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
children: /* @__PURE__ */ jsx(Oas
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
schema,
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
const Schema = parseOptions.Schema;
|
|
85
|
+
function Component() {
|
|
86
|
+
return /* @__PURE__ */ jsx(App, {
|
|
87
|
+
meta: {
|
|
88
|
+
pluginManager,
|
|
89
|
+
plugin: {
|
|
90
|
+
...plugin,
|
|
91
|
+
options
|
|
92
|
+
},
|
|
93
|
+
mode
|
|
94
|
+
},
|
|
95
|
+
children: /* @__PURE__ */ jsx(Oas, {
|
|
96
|
+
oas,
|
|
97
|
+
children: /* @__PURE__ */ jsx(Oas.Schema, {
|
|
98
|
+
name: schema.name,
|
|
99
|
+
schemaObject: schema.value,
|
|
100
|
+
tree: schema.tree,
|
|
101
|
+
children: /* @__PURE__ */ jsx(Schema, {
|
|
102
|
+
schema,
|
|
103
|
+
options,
|
|
104
|
+
instance
|
|
105
|
+
})
|
|
93
106
|
})
|
|
94
107
|
})
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const app = createApp(Component);
|
|
111
|
+
app.render();
|
|
112
|
+
return app.files;
|
|
98
113
|
}
|
|
99
114
|
};
|
|
100
115
|
}
|
|
@@ -132,5 +147,5 @@ const jsonGenerator = createGenerator({
|
|
|
132
147
|
});
|
|
133
148
|
|
|
134
149
|
//#endregion
|
|
135
|
-
export { createGenerator, createReactGenerator, jsonGenerator };
|
|
136
|
-
//# sourceMappingURL=generators-
|
|
150
|
+
export { createGenerator as n, createReactGenerator as r, jsonGenerator as t };
|
|
151
|
+
//# sourceMappingURL=generators-CJBwMPUb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-CJBwMPUb.js","names":[],"sources":["../src/generator.tsx","../src/generators/jsonGenerator.ts"],"sourcesContent":["import type { PluginFactoryOptions } from '@kubb/core'\nimport type { KubbFile } from '@kubb/core/fs'\nimport type { Operation, SchemaObject } from '@kubb/oas'\nimport { App, createApp } from '@kubb/react'\nimport type { KubbNode } from '@kubb/react/types'\nimport { Oas } from './components/Oas.tsx'\nimport type { OperationGenerator } from './OperationGenerator.ts'\nimport type { SchemaGenerator, SchemaGeneratorOptions } from './SchemaGenerator.ts'\nimport type { Schema } from './SchemaMapper.ts'\n\ntype OperationsProps<TOptions extends PluginFactoryOptions> = {\n instance: Omit<OperationGenerator<TOptions>, 'build'>\n options: TOptions['resolvedOptions']\n operations: Array<Operation>\n}\n\ntype OperationProps<TOptions extends PluginFactoryOptions> = {\n instance: Omit<OperationGenerator<TOptions>, 'build'>\n options: TOptions['resolvedOptions']\n operation: Operation\n}\n\ntype SchemaProps<TOptions extends PluginFactoryOptions> = {\n instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>\n options: TOptions['resolvedOptions']\n schema: {\n name: string\n tree: Array<Schema>\n value: SchemaObject\n }\n}\n\nexport type GeneratorOptions<TOptions extends PluginFactoryOptions> = {\n name: string\n operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>\n operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<KubbFile.File[]>\n schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>\n}\n\nexport type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>\n\nexport function createGenerator<TOptions extends PluginFactoryOptions>(parseOptions: GeneratorOptions<TOptions>): Generator<TOptions> {\n return parseOptions\n}\n\nexport type ReactGeneratorOptions<TOptions extends PluginFactoryOptions> = {\n name: string\n Operations?: (this: ReactGeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => KubbNode\n Operation?: (this: ReactGeneratorOptions<TOptions>, props: OperationProps<TOptions>) => KubbNode\n Schema?: (this: ReactGeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => KubbNode\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>(parseOptions: ReactGeneratorOptions<TOptions>): Generator<TOptions> {\n return {\n ...parseOptions,\n async operations({ instance, options, operations }) {\n if (!parseOptions.Operations) {\n return []\n }\n\n const { pluginManager, oas, plugin, mode } = instance.context\n const Operations = parseOptions.Operations\n\n function Component() {\n return (\n <App meta={{ pluginManager, plugin, mode }}>\n <Oas oas={oas} operations={operations} generator={instance}>\n <Operations operations={operations} instance={instance} options={options} />\n </Oas>\n </App>\n )\n }\n const app = createApp(Component)\n\n app.render()\n return app.files\n },\n async operation({ instance, operation, options }) {\n if (!parseOptions.Operation) {\n return []\n }\n\n const { pluginManager, oas, plugin, mode } = instance.context\n const Operation = parseOptions.Operation\n\n function Component() {\n return (\n <App meta={{ pluginManager, plugin: { ...plugin, options }, mode }}>\n <Oas oas={oas} operations={[operation]} generator={instance}>\n <Oas.Operation operation={operation}>\n <Operation operation={operation} options={options} instance={instance} />\n </Oas.Operation>\n </Oas>\n </App>\n )\n }\n const app = createApp(Component)\n\n app.render()\n return app.files\n },\n async schema({ instance, schema, options }) {\n if (!parseOptions.Schema) {\n return []\n }\n\n const { pluginManager, oas, plugin, mode } = instance.context\n\n const Schema = parseOptions.Schema\n\n function Component() {\n return (\n <App meta={{ pluginManager, plugin: { ...plugin, options }, mode }}>\n <Oas oas={oas}>\n <Oas.Schema name={schema.name} schemaObject={schema.value} tree={schema.tree}>\n <Schema schema={schema} options={options} instance={instance} />\n </Oas.Schema>\n </Oas>\n </App>\n )\n }\n const app = createApp(Component)\n\n app.render()\n return app.files\n },\n }\n}\n","import { camelCase } from '@kubb/core/transformers'\nimport { createGenerator } from '../generator.tsx'\nimport type { PluginOas } from '../types.ts'\nimport { getBanner } from '../utils/getBanner.ts'\nimport { getFooter } from '../utils/getFooter.ts'\n\nexport const jsonGenerator = createGenerator<PluginOas>({\n name: 'plugin-oas',\n async schema({ schema, instance }) {\n const { pluginManager, plugin } = instance.context\n const file = pluginManager.getFile({\n name: camelCase(schema.name),\n extname: '.json',\n mode: 'split',\n pluginKey: plugin.key,\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: instance.context.oas,\n output: plugin.options.output,\n config: pluginManager.config,\n }),\n format: getFooter({ oas: instance.context.oas, output: plugin.options.output }),\n },\n ]\n },\n})\n"],"mappings":";;;;;;;AAyCA,SAAgB,gBAAuD,cAA+D;AACpI,QAAO;;;;;;;;;AAiBT,SAAgB,qBAA4D,cAAoE;AAC9I,QAAO;EACL,GAAG;EACH,MAAM,WAAW,EAAE,UAAU,SAAS,cAAc;AAClD,OAAI,CAAC,aAAa,WAChB,QAAO,EAAE;GAGX,MAAM,EAAE,eAAe,KAAK,QAAQ,SAAS,SAAS;GACtD,MAAM,aAAa,aAAa;GAEhC,SAAS,YAAY;AACnB,WACE,oBAAC;KAAI,MAAM;MAAE;MAAe;MAAQ;MAAM;eACxC,oBAAC;MAAS;MAAiB;MAAY,WAAW;gBAChD,oBAAC;OAAuB;OAAsB;OAAmB;QAAW;OACxE;MACF;;GAGV,MAAM,MAAM,UAAU,UAAU;AAEhC,OAAI,QAAQ;AACZ,UAAO,IAAI;;EAEb,MAAM,UAAU,EAAE,UAAU,WAAW,WAAW;AAChD,OAAI,CAAC,aAAa,UAChB,QAAO,EAAE;GAGX,MAAM,EAAE,eAAe,KAAK,QAAQ,SAAS,SAAS;GACtD,MAAM,YAAY,aAAa;GAE/B,SAAS,YAAY;AACnB,WACE,oBAAC;KAAI,MAAM;MAAE;MAAe,QAAQ;OAAE,GAAG;OAAQ;OAAS;MAAE;MAAM;eAChE,oBAAC;MAAS;MAAK,YAAY,CAAC,UAAU;MAAE,WAAW;gBACjD,oBAAC,IAAI;OAAqB;iBACxB,oBAAC;QAAqB;QAAoB;QAAmB;SAAY;QAC3D;OACZ;MACF;;GAGV,MAAM,MAAM,UAAU,UAAU;AAEhC,OAAI,QAAQ;AACZ,UAAO,IAAI;;EAEb,MAAM,OAAO,EAAE,UAAU,QAAQ,WAAW;AAC1C,OAAI,CAAC,aAAa,OAChB,QAAO,EAAE;GAGX,MAAM,EAAE,eAAe,KAAK,QAAQ,SAAS,SAAS;GAEtD,MAAM,SAAS,aAAa;GAE5B,SAAS,YAAY;AACnB,WACE,oBAAC;KAAI,MAAM;MAAE;MAAe,QAAQ;OAAE,GAAG;OAAQ;OAAS;MAAE;MAAM;eAChE,oBAAC;MAAS;gBACR,oBAAC,IAAI;OAAO,MAAM,OAAO;OAAM,cAAc,OAAO;OAAO,MAAM,OAAO;iBACtE,oBAAC;QAAe;QAAiB;QAAmB;SAAY;QACrD;OACT;MACF;;GAGV,MAAM,MAAM,UAAU,UAAU;AAEhC,OAAI,QAAQ;AACZ,UAAO,IAAI;;EAEd;;;;;AC/HH,MAAa,gBAAgB,gBAA2B;CACtD,MAAM;CACN,MAAM,OAAO,EAAE,QAAQ,YAAY;EACjC,MAAM,EAAE,eAAe,WAAW,SAAS;AAQ3C,SAAO,CACL;GACE,GATS,cAAc,QAAQ;IACjC,MAAM,UAAU,OAAO,KAAK;IAC5B,SAAS;IACT,MAAM;IACN,WAAW,OAAO;IACnB,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,SAAS,QAAQ;IACtB,QAAQ,OAAO,QAAQ;IACvB,QAAQ,cAAc;IACvB,CAAC;GACF,QAAQ,UAAU;IAAE,KAAK,SAAS,QAAQ;IAAK,QAAQ,OAAO,QAAQ;IAAQ,CAAC;GAChF,CACF;;CAEJ,CAAC"}
|
package/dist/generators.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require('./Oas--cvTRMTA.cjs');
|
|
2
|
-
const require_generators = require('./generators-
|
|
3
|
-
require('./getFooter-
|
|
2
|
+
const require_generators = require('./generators-BIyNritE.cjs');
|
|
3
|
+
require('./getFooter-pQXwqM81.cjs');
|
|
4
4
|
|
|
5
5
|
exports.jsonGenerator = require_generators.jsonGenerator;
|
package/dist/generators.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./SchemaMapper-
|
|
1
|
+
import { b as PluginOas, r as Generator } from "./OperationGenerator-BeVo1_b1.cjs";
|
|
2
|
+
import "./SchemaMapper-BvE5JflR.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/jsonGenerator.d.ts
|
|
5
5
|
declare const jsonGenerator: Generator<PluginOas>;
|
package/dist/generators.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./SchemaMapper-
|
|
1
|
+
import { b as PluginOas, r as Generator } from "./OperationGenerator-CUE372Ht.js";
|
|
2
|
+
import "./SchemaMapper-BWDIvdP9.js";
|
|
3
3
|
|
|
4
4
|
//#region src/generators/jsonGenerator.d.ts
|
|
5
5
|
declare const jsonGenerator: Generator<PluginOas>;
|
package/dist/generators.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./Oas-
|
|
2
|
-
import { jsonGenerator } from "./generators-
|
|
3
|
-
import "./getFooter-
|
|
1
|
+
import "./Oas-DoN76W2_.js";
|
|
2
|
+
import { t as jsonGenerator } from "./generators-CJBwMPUb.js";
|
|
3
|
+
import "./getFooter-CvTKkK7-.js";
|
|
4
4
|
|
|
5
5
|
export { jsonGenerator };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { isFunction } from "remeda";
|
|
3
|
+
|
|
4
|
+
//#region src/utils/getBanner.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generate a default banner for files created by Kubb
|
|
7
|
+
* @returns A string with the default banner
|
|
8
|
+
*/
|
|
9
|
+
function getDefaultBanner({ title, description, version, config }) {
|
|
10
|
+
try {
|
|
11
|
+
let source = "";
|
|
12
|
+
if ("path" in config.input) source = path.basename(config.input.path);
|
|
13
|
+
else if ("data" in config.input) source = "text content";
|
|
14
|
+
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
|
|
15
|
+
if (config.output.defaultBanner === "simple") {
|
|
16
|
+
banner += "*/\n";
|
|
17
|
+
return banner;
|
|
18
|
+
}
|
|
19
|
+
if (source) banner += `* Source: ${source}\n`;
|
|
20
|
+
if (title) banner += `* Title: ${title}\n`;
|
|
21
|
+
if (description) {
|
|
22
|
+
const formattedDescription = description.replace(/\n/gm, "\n* ");
|
|
23
|
+
banner += `* Description: ${formattedDescription}\n`;
|
|
24
|
+
}
|
|
25
|
+
if (version) banner += `* OpenAPI spec version: ${version}\n`;
|
|
26
|
+
banner += "*/\n";
|
|
27
|
+
return banner;
|
|
28
|
+
} catch (_error) {
|
|
29
|
+
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function getBanner({ output, oas, config }) {
|
|
33
|
+
let banner = "";
|
|
34
|
+
if (config?.output?.defaultBanner !== false && config) {
|
|
35
|
+
const { title, description, version } = oas.api?.info || {};
|
|
36
|
+
banner = getDefaultBanner({
|
|
37
|
+
title,
|
|
38
|
+
description,
|
|
39
|
+
version,
|
|
40
|
+
config
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (!output.banner) return banner;
|
|
44
|
+
if (isFunction(output.banner)) return `${output.banner(oas)}\n${banner}`;
|
|
45
|
+
return `${output.banner}\n${banner}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/utils/getFooter.ts
|
|
50
|
+
function getFooter({ output, oas }) {
|
|
51
|
+
if (!output.footer) return;
|
|
52
|
+
if (isFunction(output.footer)) return output.footer(oas);
|
|
53
|
+
return output.footer;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { getBanner as n, getFooter as t };
|
|
58
|
+
//# sourceMappingURL=getFooter-CvTKkK7-.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFooter-CvTKkK7-.js","names":[],"sources":["../src/utils/getBanner.ts","../src/utils/getFooter.ts"],"sourcesContent":["import type { Config, Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\nimport path from 'node:path'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n config?: Config\n}\n\n/**\n * Generate a default banner for files created by Kubb\n * @returns A string with the default banner\n */\nfunction getDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n // If there's any error in parsing the Oas data, return a simpler banner\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function getBanner<TOas extends Oas>({ output, oas, config }: Props<TOas>): string {\n let banner = ''\n if (config?.output?.defaultBanner !== false && config) {\n const { title, description, version } = oas.api?.info || {}\n\n banner = getDefaultBanner({ title, description, version, config })\n }\n\n if (!output.banner) {\n return banner\n }\n\n if (isFunction(output.banner)) {\n return `${output.banner(oas)}\\n${banner}`\n }\n\n return `${output.banner}\\n${banner}`\n}\n","import type { Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n}\n\nexport function getFooter<TOas extends Oas>({ output, oas }: Props<TOas>) {\n if (!output.footer) {\n return undefined\n }\n\n if (isFunction(output.footer)) {\n return output.footer(oas)\n }\n\n return output.footer\n}\n"],"mappings":";;;;;;;;AAeA,SAAS,iBAAiB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACrJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,UAAU,OAAO,MACnB,UAAS,KAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AAEf,SAAO;;;AAIX,SAAgB,UAA4B,EAAE,QAAQ,KAAK,UAA+B;CACxF,IAAI,SAAS;AACb,KAAI,QAAQ,QAAQ,kBAAkB,SAAS,QAAQ;EACrD,MAAM,EAAE,OAAO,aAAa,YAAY,IAAI,KAAK,QAAQ,EAAE;AAE3D,WAAS,iBAAiB;GAAE;GAAO;GAAa;GAAS;GAAQ,CAAC;;AAGpE,KAAI,CAAC,OAAO,OACV,QAAO;AAGT,KAAI,WAAW,OAAO,OAAO,CAC3B,QAAO,GAAG,OAAO,OAAO,IAAI,CAAC,IAAI;AAGnC,QAAO,GAAG,OAAO,OAAO,IAAI;;;;;AC/D9B,SAAgB,UAA4B,EAAE,QAAQ,OAAoB;AACxE,KAAI,CAAC,OAAO,OACV;AAGF,KAAI,WAAW,OAAO,OAAO,CAC3B,QAAO,OAAO,OAAO,IAAI;AAG3B,QAAO,OAAO"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
node_path = require_chunk.__toESM(node_path);
|
|
4
|
+
let remeda = require("remeda");
|
|
5
|
+
remeda = require_chunk.__toESM(remeda);
|
|
6
|
+
|
|
7
|
+
//#region src/utils/getBanner.ts
|
|
8
|
+
/**
|
|
9
|
+
* Generate a default banner for files created by Kubb
|
|
10
|
+
* @returns A string with the default banner
|
|
11
|
+
*/
|
|
12
|
+
function getDefaultBanner({ title, description, version, config }) {
|
|
13
|
+
try {
|
|
14
|
+
let source = "";
|
|
15
|
+
if ("path" in config.input) source = node_path.default.basename(config.input.path);
|
|
16
|
+
else if ("data" in config.input) source = "text content";
|
|
17
|
+
let banner = "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n";
|
|
18
|
+
if (config.output.defaultBanner === "simple") {
|
|
19
|
+
banner += "*/\n";
|
|
20
|
+
return banner;
|
|
21
|
+
}
|
|
22
|
+
if (source) banner += `* Source: ${source}\n`;
|
|
23
|
+
if (title) banner += `* Title: ${title}\n`;
|
|
24
|
+
if (description) {
|
|
25
|
+
const formattedDescription = description.replace(/\n/gm, "\n* ");
|
|
26
|
+
banner += `* Description: ${formattedDescription}\n`;
|
|
27
|
+
}
|
|
28
|
+
if (version) banner += `* OpenAPI spec version: ${version}\n`;
|
|
29
|
+
banner += "*/\n";
|
|
30
|
+
return banner;
|
|
31
|
+
} catch (_error) {
|
|
32
|
+
return "/**\n* Generated by Kubb (https://kubb.dev/).\n* Do not edit manually.\n*/";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function getBanner({ output, oas, config }) {
|
|
36
|
+
let banner = "";
|
|
37
|
+
if (config?.output?.defaultBanner !== false && config) {
|
|
38
|
+
const { title, description, version } = oas.api?.info || {};
|
|
39
|
+
banner = getDefaultBanner({
|
|
40
|
+
title,
|
|
41
|
+
description,
|
|
42
|
+
version,
|
|
43
|
+
config
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (!output.banner) return banner;
|
|
47
|
+
if ((0, remeda.isFunction)(output.banner)) return `${output.banner(oas)}\n${banner}`;
|
|
48
|
+
return `${output.banner}\n${banner}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/utils/getFooter.ts
|
|
53
|
+
function getFooter({ output, oas }) {
|
|
54
|
+
if (!output.footer) return;
|
|
55
|
+
if ((0, remeda.isFunction)(output.footer)) return output.footer(oas);
|
|
56
|
+
return output.footer;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
Object.defineProperty(exports, 'getBanner', {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return getBanner;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, 'getFooter', {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return getFooter;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=getFooter-pQXwqM81.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFooter-pQXwqM81.cjs","names":["path"],"sources":["../src/utils/getBanner.ts","../src/utils/getFooter.ts"],"sourcesContent":["import type { Config, Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\nimport path from 'node:path'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n config?: Config\n}\n\n/**\n * Generate a default banner for files created by Kubb\n * @returns A string with the default banner\n */\nfunction getDefaultBanner({ title, description, version, config }: { title?: string; description?: string; version?: string; config: Config }): string {\n try {\n let source = ''\n if ('path' in config.input) {\n source = path.basename(config.input.path)\n } else if ('data' in config.input) {\n source = 'text content'\n }\n\n let banner = '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n'\n\n if (config.output.defaultBanner === 'simple') {\n banner += '*/\\n'\n return banner\n }\n\n if (source) {\n banner += `* Source: ${source}\\n`\n }\n\n if (title) {\n banner += `* Title: ${title}\\n`\n }\n\n if (description) {\n const formattedDescription = description.replace(/\\n/gm, '\\n* ')\n banner += `* Description: ${formattedDescription}\\n`\n }\n\n if (version) {\n banner += `* OpenAPI spec version: ${version}\\n`\n }\n\n banner += '*/\\n'\n return banner\n } catch (_error) {\n // If there's any error in parsing the Oas data, return a simpler banner\n return '/**\\n* Generated by Kubb (https://kubb.dev/).\\n* Do not edit manually.\\n*/'\n }\n}\n\nexport function getBanner<TOas extends Oas>({ output, oas, config }: Props<TOas>): string {\n let banner = ''\n if (config?.output?.defaultBanner !== false && config) {\n const { title, description, version } = oas.api?.info || {}\n\n banner = getDefaultBanner({ title, description, version, config })\n }\n\n if (!output.banner) {\n return banner\n }\n\n if (isFunction(output.banner)) {\n return `${output.banner(oas)}\\n${banner}`\n }\n\n return `${output.banner}\\n${banner}`\n}\n","import type { Output } from '@kubb/core'\nimport type { Oas } from '@kubb/oas'\nimport { isFunction } from 'remeda'\n\ntype Props<TOas extends Oas> = {\n oas: TOas\n output: Output<any>\n}\n\nexport function getFooter<TOas extends Oas>({ output, oas }: Props<TOas>) {\n if (!output.footer) {\n return undefined\n }\n\n if (isFunction(output.footer)) {\n return output.footer(oas)\n }\n\n return output.footer\n}\n"],"mappings":";;;;;;;;;;;AAeA,SAAS,iBAAiB,EAAE,OAAO,aAAa,SAAS,UAA8F;AACrJ,KAAI;EACF,IAAI,SAAS;AACb,MAAI,UAAU,OAAO,MACnB,UAASA,kBAAK,SAAS,OAAO,MAAM,KAAK;WAChC,UAAU,OAAO,MAC1B,UAAS;EAGX,IAAI,SAAS;AAEb,MAAI,OAAO,OAAO,kBAAkB,UAAU;AAC5C,aAAU;AACV,UAAO;;AAGT,MAAI,OACF,WAAU,aAAa,OAAO;AAGhC,MAAI,MACF,WAAU,YAAY,MAAM;AAG9B,MAAI,aAAa;GACf,MAAM,uBAAuB,YAAY,QAAQ,QAAQ,OAAO;AAChE,aAAU,kBAAkB,qBAAqB;;AAGnD,MAAI,QACF,WAAU,2BAA2B,QAAQ;AAG/C,YAAU;AACV,SAAO;UACA,QAAQ;AAEf,SAAO;;;AAIX,SAAgB,UAA4B,EAAE,QAAQ,KAAK,UAA+B;CACxF,IAAI,SAAS;AACb,KAAI,QAAQ,QAAQ,kBAAkB,SAAS,QAAQ;EACrD,MAAM,EAAE,OAAO,aAAa,YAAY,IAAI,KAAK,QAAQ,EAAE;AAE3D,WAAS,iBAAiB;GAAE;GAAO;GAAa;GAAS;GAAQ,CAAC;;AAGpE,KAAI,CAAC,OAAO,OACV,QAAO;AAGT,4BAAe,OAAO,OAAO,CAC3B,QAAO,GAAG,OAAO,OAAO,IAAI,CAAC,IAAI;AAGnC,QAAO,GAAG,OAAO,OAAO,IAAI;;;;;AC/D9B,SAAgB,UAA4B,EAAE,QAAQ,OAAoB;AACxE,KAAI,CAAC,OAAO,OACV;AAGF,4BAAe,OAAO,OAAO,CAC3B,QAAO,OAAO,OAAO,IAAI;AAG3B,QAAO,OAAO"}
|
|
@@ -51,5 +51,5 @@ function getSchemas({ oas, contentType, includes = [
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
//#endregion
|
|
54
|
-
export { getSchemaFactory, getSchemas };
|
|
55
|
-
//# sourceMappingURL=getSchemas-
|
|
54
|
+
export { getSchemaFactory as n, getSchemas as t };
|
|
55
|
+
//# sourceMappingURL=getSchemas-CvUX0jWa.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSchemas-
|
|
1
|
+
{"version":3,"file":"getSchemas-CvUX0jWa.js","names":["schemas: Record<string, OasTypes.SchemaObject>"],"sources":["../src/utils/getSchemaFactory.ts","../src/utils/getSchemas.ts"],"sourcesContent":["import { isOpenApiV3_1Document } from '@kubb/oas'\n\nimport type { Oas, OpenAPIV3, OpenAPIV3_1, SchemaObject } from '@kubb/oas'\n\n/**\n * Make it possible to narrow down the schema based on a specific version(3 or 3.1)\n */\ntype SchemaResult<TWithRef extends boolean = false> =\n | {\n schemaObject?: (TWithRef extends true ? OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject : OpenAPIV3.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.0'\n }\n | {\n schemaObject?: (TWithRef extends true ? OpenAPIV3_1.SchemaObject | OpenAPIV3_1.ReferenceObject : OpenAPIV3_1.SchemaObject) & {\n nullable?: boolean\n 'x-nullable'?: boolean\n }\n version: '3.1'\n }\n\n/**\n * Creates a factory function that generates a versioned OpenAPI schema result.\n *\n * The returned function accepts an optional schema object and produces a {@link SchemaResult} containing the dereferenced schema and the OpenAPI version ('3.0' or '3.1').\n *\n * @returns A function that takes an optional schema and returns a versioned schema result.\n */\nexport function getSchemaFactory<TWithRef extends boolean = false>(oas: Oas): (schema?: SchemaObject) => SchemaResult<TWithRef> {\n return (schema?: SchemaObject) => {\n const version = isOpenApiV3_1Document(oas.api) ? '3.1' : '3.0'\n\n return {\n schemaObject: oas.dereferenceWithRef(schema),\n version,\n } as SchemaResult<TWithRef>\n }\n}\n","import type { Oas, OasTypes, contentType } from '@kubb/oas'\n\ntype Mode = 'schemas' | 'responses' | 'requestBodies'\n\ntype GetSchemasProps = {\n oas: Oas\n contentType?: contentType\n includes?: Mode[]\n}\n\nexport function getSchemas({ oas, contentType, includes = ['schemas', 'requestBodies', 'responses'] }: GetSchemasProps): Record<string, OasTypes.SchemaObject> {\n const components = oas.getDefinition().components\n\n let schemas: Record<string, OasTypes.SchemaObject> = {}\n\n if (includes.includes('schemas')) {\n schemas = {\n ...schemas,\n ...((components?.schemas as Record<string, OasTypes.SchemaObject>) || {}),\n }\n }\n\n const requestBodies = components?.requestBodies || {}\n if (includes.includes('responses')) {\n const responses = components?.responses || {}\n\n Object.entries(responses).forEach(([name, response]: [string, OasTypes.ResponseObject]) => {\n if (response.content && !schemas[name]) {\n const firstContentType = Object.keys(response.content)[0] || 'application/json'\n schemas[name] = response.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n if (includes.includes('requestBodies')) {\n Object.entries(requestBodies).forEach(([name, request]: [string, OasTypes.RequestBodyObject]) => {\n if (request.content && !schemas[name]) {\n const firstContentType = Object.keys(request.content)[0] || 'application/json'\n schemas[name] = request.content?.[contentType || firstContentType]?.schema as OasTypes.SchemaObject\n }\n })\n }\n\n return schemas\n}\n"],"mappings":";;;;;;;;;;AA8BA,SAAgB,iBAAmD,KAA6D;AAC9H,SAAQ,WAA0B;EAChC,MAAM,UAAU,sBAAsB,IAAI,IAAI,GAAG,QAAQ;AAEzD,SAAO;GACL,cAAc,IAAI,mBAAmB,OAAO;GAC5C;GACD;;;;;;AC3BL,SAAgB,WAAW,EAAE,KAAK,aAAa,WAAW;CAAC;CAAW;CAAiB;CAAY,IAA4D;CAC7J,MAAM,aAAa,IAAI,eAAe,CAAC;CAEvC,IAAIA,UAAiD,EAAE;AAEvD,KAAI,SAAS,SAAS,UAAU,CAC9B,WAAU;EACR,GAAG;EACH,GAAK,YAAY,WAAqD,EAAE;EACzE;CAGH,MAAM,gBAAgB,YAAY,iBAAiB,EAAE;AACrD,KAAI,SAAS,SAAS,YAAY,EAAE;EAClC,MAAM,YAAY,YAAY,aAAa,EAAE;AAE7C,SAAO,QAAQ,UAAU,CAAC,SAAS,CAAC,MAAM,cAAiD;AACzF,OAAI,SAAS,WAAW,CAAC,QAAQ,OAAO;IACtC,MAAM,mBAAmB,OAAO,KAAK,SAAS,QAAQ,CAAC,MAAM;AAC7D,YAAQ,QAAQ,SAAS,UAAU,eAAe,mBAAmB;;IAEvE;;AAGJ,KAAI,SAAS,SAAS,gBAAgB,CACpC,QAAO,QAAQ,cAAc,CAAC,SAAS,CAAC,MAAM,aAAmD;AAC/F,MAAI,QAAQ,WAAW,CAAC,QAAQ,OAAO;GACrC,MAAM,mBAAmB,OAAO,KAAK,QAAQ,QAAQ,CAAC,MAAM;AAC5D,WAAQ,QAAQ,QAAQ,UAAU,eAAe,mBAAmB;;GAEtE;AAGJ,QAAO"}
|
package/dist/hooks.cjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_SchemaGenerator = require('./SchemaGenerator-
|
|
2
|
+
const require_SchemaGenerator = require('./SchemaGenerator-BQUPa5AD.cjs');
|
|
3
3
|
const require_Oas = require('./Oas--cvTRMTA.cjs');
|
|
4
4
|
const require_SchemaMapper = require('./SchemaMapper-D8J0V9Pj.cjs');
|
|
5
5
|
require('./getSchemas-08CU8KWq.cjs');
|
|
6
6
|
let __kubb_react = require("@kubb/react");
|
|
7
7
|
__kubb_react = require_chunk.__toESM(__kubb_react);
|
|
8
|
+
let __kubb_core_hooks = require("@kubb/core/hooks");
|
|
9
|
+
__kubb_core_hooks = require_chunk.__toESM(__kubb_core_hooks);
|
|
8
10
|
|
|
9
11
|
//#region src/hooks/useOas.ts
|
|
10
12
|
function useOas() {
|
|
@@ -30,7 +32,8 @@ function useOperation() {
|
|
|
30
32
|
* `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.
|
|
31
33
|
*/
|
|
32
34
|
function useOperationManager() {
|
|
33
|
-
const
|
|
35
|
+
const plugin = (0, __kubb_core_hooks.usePlugin)();
|
|
36
|
+
const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
|
|
34
37
|
const { generator } = (0, __kubb_react.useContext)(require_Oas.Oas.Context);
|
|
35
38
|
const getName = (operation, { prefix = "", suffix = "", pluginKey = plugin.key, type }) => {
|
|
36
39
|
return pluginManager.resolveName({
|
|
@@ -175,7 +178,8 @@ function useSchema() {
|
|
|
175
178
|
* `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.
|
|
176
179
|
*/
|
|
177
180
|
function useSchemaManager() {
|
|
178
|
-
const
|
|
181
|
+
const plugin = (0, __kubb_core_hooks.usePlugin)();
|
|
182
|
+
const pluginManager = (0, __kubb_core_hooks.usePluginManager)();
|
|
179
183
|
const getName = (name, { pluginKey = plugin.key, type }) => {
|
|
180
184
|
return pluginManager.resolveName({
|
|
181
185
|
name,
|