@kubb/plugin-oas 4.1.3 → 4.2.0
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/README.md +16 -16
- 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-D9MJSd3H.d.ts} +78 -104
- package/dist/{OperationGenerator-aKcfGbOt.d.cts → OperationGenerator-DiPab7wp.d.cts} +78 -104
- package/dist/{Schema-DxWT5L8_.d.ts → Schema-DzjTOgNU.d.ts} +7 -8
- package/dist/{Schema-CEmdFRTN.d.cts → Schema-lFrS1u1u.d.cts} +7 -8
- package/dist/{SchemaGenerator-BQG5bN6q.cjs → SchemaGenerator-BQUPa5AD.cjs} +4 -4
- package/dist/SchemaGenerator-BQUPa5AD.cjs.map +1 -0
- package/dist/{SchemaGenerator-B0NuJl4f.js → SchemaGenerator-DYOXlswO.js} +7 -7
- package/dist/SchemaGenerator-DYOXlswO.js.map +1 -0
- 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-CW7v1RgJ.js → generators-CC4tK-sV.js} +79 -64
- package/dist/generators-CC4tK-sV.js.map +1 -0
- package/dist/{generators-L3av7_7B.cjs → generators-DeiYqSf3.cjs} +75 -60
- package/dist/generators-DeiYqSf3.cjs.map +1 -0
- package/dist/generators.cjs +1 -1
- package/dist/generators.d.cts +2 -2
- package/dist/generators.d.ts +2 -2
- package/dist/generators.js +3 -3
- package/dist/{getFooter-DM8B8cnC.js → getFooter-DrSj240h.js} +2 -2
- package/dist/{getFooter-DM8B8cnC.js.map → getFooter-DrSj240h.js.map} +1 -1
- 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 +2 -2
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -7
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +1 -1
- package/dist/{parseFromConfig-DoynWlIk.js → parseFromConfig-DSI6Meg0.js} +2 -2
- package/dist/{parseFromConfig-DoynWlIk.js.map → parseFromConfig-DSI6Meg0.js.map} +1 -1
- package/dist/utils.d.cts +3 -3
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +3 -3
- package/package.json +6 -8
- package/src/generator.tsx +50 -43
- package/src/hooks/useOperationManager.ts +5 -6
- package/src/hooks/useSchemaManager.ts +3 -3
- package/dist/SchemaGenerator-B0NuJl4f.js.map +0 -1
- package/dist/SchemaGenerator-BQG5bN6q.cjs.map +0 -1
- package/dist/generators-CW7v1RgJ.js.map +0 -1
- package/dist/generators-L3av7_7B.cjs.map +0 -1
|
@@ -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-DrSj240h.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.getFiles();
|
|
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.getFiles();
|
|
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.getFiles();
|
|
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-CC4tK-sV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-CC4tK-sV.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.getFiles()\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.getFiles()\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.getFiles()\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,UAAU;;EAEvB,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,UAAU;;EAEvB,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,UAAU;;EAExB;;;;;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"}
|
|
@@ -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.getFiles();
|
|
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.getFiles();
|
|
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.getFiles();
|
|
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-DeiYqSf3.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generators-DeiYqSf3.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.getFiles()\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.getFiles()\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.getFiles()\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,UAAU;;EAEvB,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;OAA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generators.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./SchemaMapper-
|
|
1
|
+
import { b as PluginOas, r as Generator } from "./OperationGenerator-DiPab7wp.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-D9MJSd3H.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-CC4tK-sV.js";
|
|
3
|
+
import "./getFooter-DrSj240h.js";
|
|
4
4
|
|
|
5
5
|
export { jsonGenerator };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFooter-
|
|
1
|
+
{"version":3,"file":"getFooter-DrSj240h.js","names":[],"sources":["../src/utils/getBanner.ts","../src/utils/getFooter.ts"],"sourcesContent":["import { type Config, getDefaultBanner, 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 config?: Config\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":";;;;AAUA,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;;;;;ACjB9B,SAAgB,UAA4B,EAAE,QAAQ,OAAoB;AACxE,KAAI,CAAC,OAAO,OACV;AAGF,KAAI,WAAW,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,
|
package/dist/hooks.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":["Oas","Operation","Oas","getName: UseOperationManagerResult['getName']","getGroup: UseOperationManagerResult['getGroup']","getSchemas: UseOperationManagerResult['getSchemas']","getFile: UseOperationManagerResult['getFile']","groupSchemasByName: UseOperationManagerResult['groupSchemasByName']","Oas","Schema","getName: UseSchemaManagerResult['getName']","getFile: UseSchemaManagerResult['getFile']","getImports: UseSchemaManagerResult['getImports']","SchemaGenerator","schemaKeywords"],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts","../src/hooks/useSchema.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { Oas as OasType } from '@kubb/oas'\n\nexport function useOas(): OasType {\n const { oas } = useContext(Oas.Context)\n\n if (!oas) {\n throw new Error('Oas is not defined')\n }\n\n return oas\n}\n","import { useContext } from '@kubb/react'\n\nimport { Operation } from '../components/Operation.tsx'\n\nimport type { Operation as OperationType } from '@kubb/oas'\n\n/**\n * `useOperation` will return the current `Operation`\n */\nexport function useOperation(): OperationType {\n const { operation } = useContext(Operation.Context)\n\n if (!operation) {\n throw new Error('Operation is not defined')\n }\n\n return operation\n}\n","import { useApp, useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\n\nimport type { KubbFile } from '@kubb/core/fs'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\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 pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\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 pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager(): UseOperationManagerResult {\n const { plugin, pluginManager } = useApp()\n const { generator } = useContext(Oas.Context)\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginKey,\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(`'generator' is not defined`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginKey = plugin.key, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n const group = getGroup(operation)\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\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 pluginKey,\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 pluginKey,\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 pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\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 { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype UseOperationsProps = {\n /**\n * Filter based on path\n * Weight: 2\n */\n path?: string\n /**\n * Filter based on method\n * Weight: 1\n */\n method?: HttpMethod\n}\n\n/**\n * `useOperations` will return all the Operations\n */\nexport function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {\n const { operations } = useContext(Oas.Context)\n\n if (!operations) {\n throw new Error('Operations is not defined')\n }\n let items = operations\n\n if (path) {\n items = items.filter((item) => item.path === path)\n }\n\n if (method) {\n items = items.filter((item) => item.method === method)\n }\n\n return items\n}\n","import { useContext } from '@kubb/react'\n\nimport { Schema } from '../components/Schema.tsx'\n\nimport type { SchemaContextProps } from '../components/Schema.tsx'\n\ntype UseSchemaResult = SchemaContextProps\n\n/**\n * `useSchema` will return the current `schema properties`\n */\nexport function useSchema(): UseSchemaResult {\n const props = useContext(Schema.Context)\n\n return props as UseSchemaResult\n}\n","import { useApp } from '@kubb/react'\n\nimport type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type { KubbFile } from '@kubb/core/fs'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport { type Schema, schemaKeywords } from '../SchemaMapper'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginKey?: Plugin['key']\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n getImports: (tree: Array<Schema>) => Array<KubbFile.Import>\n}\n\n/**\n * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const { plugin, pluginManager } = useApp()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name,\n pluginKey,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginKey,\n },\n }\n }\n\n const getImports: UseSchemaManagerResult['getImports'] = (tree) => {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n return refs\n ?.map((item) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n }\n })\n .filter(Boolean)\n }\n\n return {\n getName,\n getFile,\n getImports,\n }\n}\n"],"mappings":";;;;;;;;;AAMA,SAAgB,SAAkB;CAChC,MAAM,EAAE,qCAAmBA,gBAAI,QAAQ;AAEvC,KAAI,CAAC,IACH,OAAM,IAAI,MAAM,qBAAqB;AAGvC,QAAO;;;;;;;;ACJT,SAAgB,eAA8B;CAC5C,MAAM,EAAE,2CAAyBC,sBAAU,QAAQ;AAEnD,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,2BAA2B;AAG7C,QAAO;;;;;;;;ACmDT,SAAgB,sBAAiD;CAC/D,MAAM,EAAE,QAAQ,4CAA0B;CAC1C,MAAM,EAAE,2CAAyBC,gBAAI,QAAQ;CAE7C,MAAMC,WAAiD,WAAW,EAAE,SAAS,IAAI,SAAS,IAAI,YAAY,OAAO,KAAK,WAAW;AAC/H,SAAO,cAAc,YAAY;GAC/B,MAAM,GAAG,OAAO,GAAG,UAAU,gBAAgB,CAAC,G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U,OAAO,UAAU,EAAE,KAAK;EACpI,MAAM,eAAe,SAAS,WAAW,KAAK,QAAQ,MAAM;GAAE,MAAM;GAAQ;GAAW,CAAC;EAExF,MAAM,OAAO,cAAc,QAAQ;GACjC,MAAM;GACN;GACA;GACA,SAAS;IAAE,MAAM;IAAQ;IAAW;IAAO;GAC5C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR,MAAM;IACN;IACD;GACF;;CAGH,MAAMC,cAAoD,SAAS;AAGjE,SAFaC,wCAAgB,WAAW,MAAMC,oCAAe,IAAI,EAG7D,KAAK,SAAS;AACd,OAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,KAAK,aAChC;AAGF,UAAO;IACL,MAAM,CAAC,KAAK,KAAK,KAAK;IACtB,MAAM,KAAK,KAAK;IACjB;IACD,CACD,OAAO,QAAQ;;AAGpB,QAAO;EACL;EACA;EACA;EACD"}
|
|
1
|
+
{"version":3,"file":"hooks.cjs","names":["Oas","Operation","Oas","getName: UseOperationManagerResult['getName']","getGroup: UseOperationManagerResult['getGroup']","getSchemas: UseOperationManagerResult['getSchemas']","getFile: UseOperationManagerResult['getFile']","groupSchemasByName: UseOperationManagerResult['groupSchemasByName']","Oas","Schema","getName: UseSchemaManagerResult['getName']","getFile: UseSchemaManagerResult['getFile']","getImports: UseSchemaManagerResult['getImports']","SchemaGenerator","schemaKeywords"],"sources":["../src/hooks/useOas.ts","../src/hooks/useOperation.ts","../src/hooks/useOperationManager.ts","../src/hooks/useOperations.ts","../src/hooks/useSchema.ts","../src/hooks/useSchemaManager.ts"],"sourcesContent":["import { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { Oas as OasType } from '@kubb/oas'\n\nexport function useOas(): OasType {\n const { oas } = useContext(Oas.Context)\n\n if (!oas) {\n throw new Error('Oas is not defined')\n }\n\n return oas\n}\n","import { useContext } from '@kubb/react'\n\nimport { Operation } from '../components/Operation.tsx'\n\nimport type { Operation as OperationType } from '@kubb/oas'\n\n/**\n * `useOperation` will return the current `Operation`\n */\nexport function useOperation(): OperationType {\n const { operation } = useContext(Operation.Context)\n\n if (!operation) {\n throw new Error('Operation is not defined')\n }\n\n return operation\n}\n","import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type { KubbFile } from '@kubb/core/fs'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport type { Operation, Operation as OperationType } from '@kubb/oas'\nimport { useContext } from '@kubb/react'\nimport { Oas } from '../components/Oas.tsx'\nimport type { OperationSchemas } from '../types.ts'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\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 pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => string\n getFile: (\n operation: OperationType,\n params?: {\n prefix?: string\n suffix?: string\n pluginKey?: Plugin['key']\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 pluginKey?: Plugin['key']\n type: ResolveNameParams['type']\n },\n ) => SchemaNames\n getSchemas: (operation: Operation, params?: { pluginKey?: Plugin['key']; type?: ResolveNameParams['type'] }) => OperationSchemas\n getGroup: (operation: Operation) => FileMeta['group'] | undefined\n}\n\n/**\n * `useOperationManager` will return some helper functions that can be used to get the operation file, get the operation name.\n */\nexport function useOperationManager(): UseOperationManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n const { generator } = useContext(Oas.Context)\n\n const getName: UseOperationManagerResult['getName'] = (operation, { prefix = '', suffix = '', pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name: `${prefix} ${operation.getOperationId()} ${suffix}`,\n pluginKey,\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(`'generator' is not defined`)\n }\n\n return generator.getSchemas(operation, {\n resolveName: (name) =>\n pluginManager.resolveName({\n name,\n pluginKey: params?.pluginKey,\n type: params?.type,\n }),\n })\n }\n\n const getFile: UseOperationManagerResult['getFile'] = (operation, { prefix, suffix, pluginKey = plugin.key, extname = '.ts' } = {}) => {\n const name = getName(operation, { type: 'file', pluginKey, prefix, suffix })\n const group = getGroup(operation)\n\n const file = pluginManager.getFile({\n name,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name,\n pluginKey,\n group,\n },\n }\n }\n\n const groupSchemasByName: UseOperationManagerResult['groupSchemasByName'] = (operation, { pluginKey = plugin.key, type }) => {\n if (!generator) {\n throw new Error(`'generator' is not defined`)\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 pluginKey,\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 pluginKey,\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 pluginKey,\n type,\n })\n : undefined,\n parameters: {\n path: schemas.pathParams?.name\n ? pluginManager.resolveName({\n name: schemas.pathParams.name,\n pluginKey,\n type,\n })\n : undefined,\n query: schemas.queryParams?.name\n ? pluginManager.resolveName({\n name: schemas.queryParams.name,\n pluginKey,\n type,\n })\n : undefined,\n header: schemas.headerParams?.name\n ? pluginManager.resolveName({\n name: schemas.headerParams.name,\n pluginKey,\n type,\n })\n : undefined,\n },\n responses: {\n ...responses,\n ['default']: pluginManager.resolveName({\n name: schemas.response.name,\n pluginKey,\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 { useContext } from '@kubb/react'\n\nimport { Oas } from '../components/Oas.tsx'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype UseOperationsProps = {\n /**\n * Filter based on path\n * Weight: 2\n */\n path?: string\n /**\n * Filter based on method\n * Weight: 1\n */\n method?: HttpMethod\n}\n\n/**\n * `useOperations` will return all the Operations\n */\nexport function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {\n const { operations } = useContext(Oas.Context)\n\n if (!operations) {\n throw new Error('Operations is not defined')\n }\n let items = operations\n\n if (path) {\n items = items.filter((item) => item.path === path)\n }\n\n if (method) {\n items = items.filter((item) => item.method === method)\n }\n\n return items\n}\n","import { useContext } from '@kubb/react'\n\nimport { Schema } from '../components/Schema.tsx'\n\nimport type { SchemaContextProps } from '../components/Schema.tsx'\n\ntype UseSchemaResult = SchemaContextProps\n\n/**\n * `useSchema` will return the current `schema properties`\n */\nexport function useSchema(): UseSchemaResult {\n const props = useContext(Schema.Context)\n\n return props as UseSchemaResult\n}\n","import type { FileMetaBase, Plugin, ResolveNameParams } from '@kubb/core'\nimport type { KubbFile } from '@kubb/core/fs'\nimport { usePlugin, usePluginManager } from '@kubb/core/hooks'\nimport { SchemaGenerator } from '../SchemaGenerator.ts'\nimport { type Schema, schemaKeywords } from '../SchemaMapper'\n\ntype FileMeta = FileMetaBase & {\n pluginKey: Plugin['key']\n name: string\n group?: {\n tag?: string\n path?: string\n }\n}\n\ntype UseSchemaManagerResult = {\n getName: (name: string, params: { pluginKey?: Plugin['key']; type: ResolveNameParams['type'] }) => string\n getFile: (\n name: string,\n params?: {\n pluginKey?: Plugin['key']\n mode?: KubbFile.Mode\n extname?: KubbFile.Extname\n group?: {\n tag?: string\n path?: string\n }\n },\n ) => KubbFile.File<FileMeta>\n getImports: (tree: Array<Schema>) => Array<KubbFile.Import>\n}\n\n/**\n * `useSchemaManager` will return some helper functions that can be used to get the schema file, get the schema name.\n */\nexport function useSchemaManager(): UseSchemaManagerResult {\n const plugin = usePlugin()\n const pluginManager = usePluginManager()\n\n const getName: UseSchemaManagerResult['getName'] = (name, { pluginKey = plugin.key, type }) => {\n return pluginManager.resolveName({\n name,\n pluginKey,\n type,\n })\n }\n\n const getFile: UseSchemaManagerResult['getFile'] = (name, { mode = 'split', pluginKey = plugin.key, extname = '.ts', group } = {}) => {\n const resolvedName = mode === 'single' ? '' : getName(name, { type: 'file', pluginKey })\n\n const file = pluginManager.getFile({\n name: resolvedName,\n extname,\n pluginKey,\n options: { type: 'file', pluginKey, group },\n })\n\n return {\n ...file,\n meta: {\n ...file.meta,\n name: resolvedName,\n pluginKey,\n },\n }\n }\n\n const getImports: UseSchemaManagerResult['getImports'] = (tree) => {\n const refs = SchemaGenerator.deepSearch(tree, schemaKeywords.ref)\n\n return refs\n ?.map((item) => {\n if (!item.args.path || !item.args.isImportable) {\n return undefined\n }\n\n return {\n name: [item.args.name],\n path: item.args.path,\n }\n })\n .filter(Boolean)\n }\n\n return {\n getName,\n getFile,\n getImports,\n }\n}\n"],"mappings":";;;;;;;;;;;AAMA,SAAgB,SAAkB;CAChC,MAAM,EAAE,qCAAmBA,gBAAI,QAAQ;AAEvC,KAAI,CAAC,IACH,OAAM,IAAI,MAAM,qBAAqB;AAGvC,QAAO;;;;;;;;ACJT,SAAgB,eAA8B;CAC5C,MAAM,EAAE,2CAAyBC,sBAAU,QAAQ;AAEnD,KAAI,CAAC,UACH,OAAM,IAAI,MAAM,2BAA2B;AAG7C,QAAO;;;;;;;;ACiDT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BC,mBAAO,QAAQ;;;;;;;;ACuB1C,SAAgB,mBAA2C;CACzD,MAAM,2CAAoB;CAC1B,MAAM,yDAAkC;CAExC,MAAMC,WAA8C,MAAM,EAAE,YAAY,OAAO,KAAK,WAAW;AAC7F,SAAO,cAAc,YAAY;GAC/B;GACA;GACA;GACD,CAAC;;CAGJ,MAAMC,WAA8C,MAAM,EAAE,OAAO,SAAS,YAAY,OAAO,KAAK,UAAU,OAAO,UAAU,EAAE,KAAK;EACpI,MAAM,eAAe,SAAS,WAAW,KAAK,QAAQ,MAAM;GAAE,MAAM;GAAQ;GAAW,CAAC;EAExF,MAAM,OAAO,cAAc,QAAQ;GACjC,MAAM;GACN;GACA;GACA,SAAS;IAAE,MAAM;IAAQ;IAAW;IAAO;GAC5C,CAAC;AAEF,SAAO;GACL,GAAG;GACH,MAAM;IACJ,GAAG,KAAK;IACR,MAAM;IACN;IACD;GACF;;CAGH,MAAMC,cAAoD,SAAS;AAGjE,SAFaC,wCAAgB,WAAW,MAAMC,oCAAe,IAAI,EAG7D,KAAK,SAAS;AACd,OAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,KAAK,aAChC;AAGF,UAAO;IACL,MAAM,CAAC,KAAK,KAAK,KAAK;IACtB,MAAM,KAAK,KAAK;IACjB;IACD,CACD,OAAO,QAAQ;;AAGpB,QAAO;EACL;EACA;EACA;EACD"}
|
package/dist/hooks.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SchemaContextProps } from "./Schema-
|
|
1
|
+
import { L as Operation, M as Oas, N as HttpMethod, O as Plugin, T as FileMetaBase, _ as OperationSchemas, k as ResolveNameParams } from "./OperationGenerator-DiPab7wp.cjs";
|
|
2
|
+
import { d as File, f as Import, p as Mode, t as Schema, u as Extname } from "./SchemaMapper-BvE5JflR.cjs";
|
|
3
|
+
import { n as SchemaContextProps } from "./Schema-lFrS1u1u.cjs";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useOas.d.ts
|
|
6
6
|
declare function useOas(): Oas;
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SchemaContextProps } from "./Schema-
|
|
1
|
+
import { L as Operation, M as Oas, N as HttpMethod, O as Plugin, T as FileMetaBase, _ as OperationSchemas, k as ResolveNameParams } from "./OperationGenerator-D9MJSd3H.js";
|
|
2
|
+
import { d as File, f as Import, p as Mode, t as Schema, u as Extname } from "./SchemaMapper-BWDIvdP9.js";
|
|
3
|
+
import { n as SchemaContextProps } from "./Schema-DzjTOgNU.js";
|
|
4
4
|
|
|
5
5
|
//#region src/hooks/useOas.d.ts
|
|
6
6
|
declare function useOas(): Oas;
|