@kubb/plugin-oas 4.3.1 → 4.4.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-DoN76W2_.js → Oas-CHC1IC5D.js} +5 -9
- package/dist/Oas-CHC1IC5D.js.map +1 -0
- package/dist/{Oas--cvTRMTA.cjs → Oas-CQrRP_NH.cjs} +13 -17
- package/dist/Oas-CQrRP_NH.cjs.map +1 -0
- package/dist/{OperationGenerator-XkW6FZJh.d.cts → OperationGenerator-CRZpkIpZ.d.ts} +182 -109
- package/dist/{OperationGenerator-ki8g970_.d.ts → OperationGenerator-S_1PevQN.d.cts} +182 -109
- package/dist/{Schema-CHstINXC.d.ts → Schema-CZsDEhET.d.cts} +7 -6
- package/dist/{Schema-BXYfUkqN.d.cts → Schema-DBvtiLS7.d.ts} +7 -6
- package/dist/{SchemaGenerator-DsK0wuii.cjs → SchemaGenerator-DWj6buY0.cjs} +22 -5
- package/dist/SchemaGenerator-DWj6buY0.cjs.map +1 -0
- package/dist/{SchemaGenerator-B07tXh1b.js → SchemaGenerator-b7XixzRv.js} +21 -4
- package/dist/SchemaGenerator-b7XixzRv.js.map +1 -0
- package/dist/{SchemaMapper-qjB3rBph.d.ts → SchemaMapper-CX7sIIuZ.d.cts} +5 -118
- package/dist/{SchemaMapper-MiRB5_Zp.d.cts → SchemaMapper-CtfTw3hq.d.ts} +5 -118
- package/dist/{SchemaMapper-CM1eXksi.js → SchemaMapper-Cx4X1al6.js} +1 -1
- package/dist/SchemaMapper-Cx4X1al6.js.map +1 -0
- package/dist/{SchemaMapper-CpAbmGiH.cjs → SchemaMapper-DoL-a6qq.cjs} +1 -1
- package/dist/SchemaMapper-DoL-a6qq.cjs.map +1 -0
- package/dist/chunk-BEV-X5tz.js +27 -0
- package/dist/components.cjs +1 -1
- package/dist/components.d.cts +8 -11
- package/dist/components.d.ts +8 -11
- package/dist/components.js +1 -1
- package/dist/generators-B27La9Vd.cjs +99 -0
- package/dist/generators-B27La9Vd.cjs.map +1 -0
- package/dist/generators-C61FxVIj.js +80 -0
- package/dist/generators-C61FxVIj.js.map +1 -0
- package/dist/generators.cjs +9 -3
- package/dist/generators.d.cts +3 -8
- package/dist/generators.d.ts +3 -8
- package/dist/generators.js +5 -4
- package/dist/{getFooter-pQXwqM81.cjs → getFooter-CwjCW4h5.cjs} +3 -3
- package/dist/{getFooter-pQXwqM81.cjs.map → getFooter-CwjCW4h5.cjs.map} +1 -1
- package/dist/{getFooter-CvTKkK7-.js → getFooter-D5MdeUVv.js} +2 -2
- package/dist/{getFooter-CvTKkK7-.js.map → getFooter-D5MdeUVv.js.map} +1 -1
- package/dist/{getSchemas-CvUX0jWa.js → getSchemas-Bdg6n9Qk.js} +1 -1
- package/dist/{getSchemas-CvUX0jWa.js.map → getSchemas-Bdg6n9Qk.js.map} +1 -1
- package/dist/{getSchemas-08CU8KWq.cjs → getSchemas-DY8s2CSl.cjs} +1 -1
- package/dist/{getSchemas-08CU8KWq.cjs.map → getSchemas-DY8s2CSl.cjs.map} +1 -1
- package/dist/hooks.cjs +12 -27
- package/dist/hooks.cjs.map +1 -1
- package/dist/hooks.d.cts +11 -31
- package/dist/hooks.d.ts +11 -31
- package/dist/hooks.js +9 -23
- package/dist/hooks.js.map +1 -1
- package/dist/index.cjs +37 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -9
- package/dist/index.d.ts +3 -9
- package/dist/index.js +33 -9
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +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-DSI6Meg0.js → parseFromConfig-CqiiLCPe.js} +1 -1
- package/dist/{parseFromConfig-DSI6Meg0.js.map → parseFromConfig-CqiiLCPe.js.map} +1 -1
- package/dist/{parseFromConfig-o3tU1XJt.cjs → parseFromConfig-RR31a98-.cjs} +1 -1
- package/dist/{parseFromConfig-o3tU1XJt.cjs.map → parseFromConfig-RR31a98-.cjs.map} +1 -1
- package/dist/utils-DYf-j63H.cjs +115 -0
- package/dist/utils-DYf-j63H.cjs.map +1 -0
- package/dist/utils-DaV25sy8.js +95 -0
- package/dist/utils-DaV25sy8.js.map +1 -0
- package/dist/utils.cjs +3 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +4 -3
- package/dist/utils.d.ts +4 -3
- package/dist/utils.js +3 -3
- package/dist/utils.js.map +1 -1
- package/package.json +14 -11
- package/src/OperationGenerator.ts +36 -7
- package/src/SchemaGenerator.ts +26 -2
- package/src/SchemaMapper.ts +1 -1
- package/src/components/Oas.tsx +5 -12
- package/src/components/Operation.tsx +3 -3
- package/src/components/Schema.tsx +3 -4
- package/src/generators/createGenerator.ts +34 -0
- package/src/generators/createReactGenerator.ts +41 -0
- package/src/generators/index.ts +4 -0
- package/src/generators/jsonGenerator.ts +1 -1
- package/src/generators/types.ts +35 -0
- package/src/generators/utils.tsx +114 -0
- package/src/hooks/index.ts +1 -2
- package/src/hooks/useOas.ts +5 -11
- package/src/hooks/useOperation.ts +1 -1
- package/src/hooks/useOperationManager.ts +2 -2
- package/src/hooks/useSchema.ts +1 -1
- package/src/hooks/useSchemaManager.ts +1 -1
- package/src/index.ts +3 -5
- package/src/plugin.ts +2 -0
- package/src/types.ts +2 -2
- package/src/utils/getParams.ts +1 -1
- package/dist/Oas--cvTRMTA.cjs.map +0 -1
- package/dist/Oas-DoN76W2_.js.map +0 -1
- package/dist/SchemaGenerator-B07tXh1b.js.map +0 -1
- package/dist/SchemaGenerator-DsK0wuii.cjs.map +0 -1
- package/dist/SchemaMapper-CM1eXksi.js.map +0 -1
- package/dist/SchemaMapper-CpAbmGiH.cjs.map +0 -1
- package/dist/generators-BUNmB1lx.js +0 -154
- package/dist/generators-BUNmB1lx.js.map +0 -1
- package/dist/generators-CoiXCnDY.cjs +0 -175
- package/dist/generators-CoiXCnDY.cjs.map +0 -1
- package/src/generator.tsx +0 -139
- package/src/hooks/useOperations.ts +0 -40
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { t as Oas } from "./Oas-DoN76W2_.js";
|
|
2
|
-
import { n as getBanner, t as getFooter } from "./getFooter-CvTKkK7-.js";
|
|
3
|
-
import { camelCase } from "@kubb/core/transformers";
|
|
4
|
-
import { App, createApp, reactPlugin } from "@kubb/react";
|
|
5
|
-
import { jsx } from "@kubb/react/jsx-runtime";
|
|
6
|
-
|
|
7
|
-
//#region src/generator.tsx
|
|
8
|
-
function createGenerator(parseOptions) {
|
|
9
|
-
return parseOptions;
|
|
10
|
-
}
|
|
11
|
-
/****
|
|
12
|
-
* Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.
|
|
13
|
-
*
|
|
14
|
-
* 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.
|
|
15
|
-
*
|
|
16
|
-
* @returns A generator object with async methods for operations, operation, and schema file generation.
|
|
17
|
-
*/
|
|
18
|
-
function createReactGenerator(parseOptions) {
|
|
19
|
-
return {
|
|
20
|
-
...parseOptions,
|
|
21
|
-
async operations({ instance, options, operations }) {
|
|
22
|
-
if (!parseOptions.Operations) return [];
|
|
23
|
-
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
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,
|
|
34
|
-
operations,
|
|
35
|
-
generator: instance,
|
|
36
|
-
children: /* @__PURE__ */ jsx(Operations, {
|
|
37
|
-
operations,
|
|
38
|
-
instance,
|
|
39
|
-
options
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
const app = createApp();
|
|
45
|
-
app.use(reactPlugin);
|
|
46
|
-
app.render(Component);
|
|
47
|
-
return app.files;
|
|
48
|
-
},
|
|
49
|
-
async operation({ instance, operation, options }) {
|
|
50
|
-
if (!parseOptions.Operation) return [];
|
|
51
|
-
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
52
|
-
const Operation = parseOptions.Operation;
|
|
53
|
-
function Component() {
|
|
54
|
-
return /* @__PURE__ */ jsx(App, {
|
|
55
|
-
meta: {
|
|
56
|
-
pluginManager,
|
|
57
|
-
plugin: {
|
|
58
|
-
...plugin,
|
|
59
|
-
options
|
|
60
|
-
},
|
|
61
|
-
mode
|
|
62
|
-
},
|
|
63
|
-
children: /* @__PURE__ */ jsx(Oas, {
|
|
64
|
-
oas,
|
|
65
|
-
operations: [operation],
|
|
66
|
-
generator: instance,
|
|
67
|
-
children: /* @__PURE__ */ jsx(Oas.Operation, {
|
|
68
|
-
operation,
|
|
69
|
-
children: /* @__PURE__ */ jsx(Operation, {
|
|
70
|
-
operation,
|
|
71
|
-
options,
|
|
72
|
-
instance
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
const app = createApp();
|
|
79
|
-
app.use(reactPlugin);
|
|
80
|
-
app.render(Component);
|
|
81
|
-
return app.files;
|
|
82
|
-
},
|
|
83
|
-
async schema({ instance, schema, options }) {
|
|
84
|
-
if (!parseOptions.Schema) return [];
|
|
85
|
-
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
86
|
-
const Schema = parseOptions.Schema;
|
|
87
|
-
function Component() {
|
|
88
|
-
return /* @__PURE__ */ jsx(App, {
|
|
89
|
-
meta: {
|
|
90
|
-
pluginManager,
|
|
91
|
-
plugin: {
|
|
92
|
-
...plugin,
|
|
93
|
-
options
|
|
94
|
-
},
|
|
95
|
-
mode
|
|
96
|
-
},
|
|
97
|
-
children: /* @__PURE__ */ jsx(Oas, {
|
|
98
|
-
oas,
|
|
99
|
-
children: /* @__PURE__ */ jsx(Oas.Schema, {
|
|
100
|
-
name: schema.name,
|
|
101
|
-
schemaObject: schema.value,
|
|
102
|
-
tree: schema.tree,
|
|
103
|
-
children: /* @__PURE__ */ jsx(Schema, {
|
|
104
|
-
schema,
|
|
105
|
-
options,
|
|
106
|
-
instance
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
})
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
const app = createApp();
|
|
113
|
-
app.use(reactPlugin);
|
|
114
|
-
app.render(Component);
|
|
115
|
-
return app.files;
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
//#endregion
|
|
121
|
-
//#region src/generators/jsonGenerator.ts
|
|
122
|
-
const jsonGenerator = createGenerator({
|
|
123
|
-
name: "plugin-oas",
|
|
124
|
-
async schema({ schema, instance }) {
|
|
125
|
-
const { pluginManager, plugin } = instance.context;
|
|
126
|
-
return [{
|
|
127
|
-
...pluginManager.getFile({
|
|
128
|
-
name: camelCase(schema.name),
|
|
129
|
-
extname: ".json",
|
|
130
|
-
mode: "split",
|
|
131
|
-
pluginKey: plugin.key
|
|
132
|
-
}),
|
|
133
|
-
sources: [{
|
|
134
|
-
name: camelCase(schema.name),
|
|
135
|
-
isExportable: false,
|
|
136
|
-
isIndexable: false,
|
|
137
|
-
value: JSON.stringify(schema.value)
|
|
138
|
-
}],
|
|
139
|
-
banner: getBanner({
|
|
140
|
-
oas: instance.context.oas,
|
|
141
|
-
output: plugin.options.output,
|
|
142
|
-
config: pluginManager.config
|
|
143
|
-
}),
|
|
144
|
-
format: getFooter({
|
|
145
|
-
oas: instance.context.oas,
|
|
146
|
-
output: plugin.options.output
|
|
147
|
-
})
|
|
148
|
-
}];
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
//#endregion
|
|
153
|
-
export { createGenerator as n, createReactGenerator as r, jsonGenerator as t };
|
|
154
|
-
//# sourceMappingURL=generators-BUNmB1lx.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-BUNmB1lx.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, reactPlugin } 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()\n app.use(reactPlugin)\n\n app.render(Component)\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()\n app.use(reactPlugin)\n\n app.render(Component)\n\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()\n app.use(reactPlugin)\n\n app.render(Component)\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,WAAW;AACvB,OAAI,IAAI,YAAY;AAEpB,OAAI,OAAO,UAAU;AACrB,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,WAAW;AACvB,OAAI,IAAI,YAAY;AAEpB,OAAI,OAAO,UAAU;AAErB,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,WAAW;AACvB,OAAI,IAAI,YAAY;AAEpB,OAAI,OAAO,UAAU;AACrB,UAAO,IAAI;;EAEd;;;;;ACnIH,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"}
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
-
const require_Oas = require('./Oas--cvTRMTA.cjs');
|
|
3
|
-
const require_getFooter = require('./getFooter-pQXwqM81.cjs');
|
|
4
|
-
let __kubb_core_transformers = require("@kubb/core/transformers");
|
|
5
|
-
__kubb_core_transformers = require_chunk.__toESM(__kubb_core_transformers);
|
|
6
|
-
let __kubb_react = require("@kubb/react");
|
|
7
|
-
__kubb_react = require_chunk.__toESM(__kubb_react);
|
|
8
|
-
let __kubb_react_jsx_runtime = require("@kubb/react/jsx-runtime");
|
|
9
|
-
__kubb_react_jsx_runtime = require_chunk.__toESM(__kubb_react_jsx_runtime);
|
|
10
|
-
|
|
11
|
-
//#region src/generator.tsx
|
|
12
|
-
function createGenerator(parseOptions) {
|
|
13
|
-
return parseOptions;
|
|
14
|
-
}
|
|
15
|
-
/****
|
|
16
|
-
* Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.
|
|
17
|
-
*
|
|
18
|
-
* 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.
|
|
19
|
-
*
|
|
20
|
-
* @returns A generator object with async methods for operations, operation, and schema file generation.
|
|
21
|
-
*/
|
|
22
|
-
function createReactGenerator(parseOptions) {
|
|
23
|
-
return {
|
|
24
|
-
...parseOptions,
|
|
25
|
-
async operations({ instance, options, operations }) {
|
|
26
|
-
if (!parseOptions.Operations) return [];
|
|
27
|
-
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
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,
|
|
38
|
-
operations,
|
|
39
|
-
generator: instance,
|
|
40
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(Operations, {
|
|
41
|
-
operations,
|
|
42
|
-
instance,
|
|
43
|
-
options
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
const app = (0, __kubb_react.createApp)();
|
|
49
|
-
app.use(__kubb_react.reactPlugin);
|
|
50
|
-
app.render(Component);
|
|
51
|
-
return app.files;
|
|
52
|
-
},
|
|
53
|
-
async operation({ instance, operation, options }) {
|
|
54
|
-
if (!parseOptions.Operation) return [];
|
|
55
|
-
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
56
|
-
const Operation = parseOptions.Operation;
|
|
57
|
-
function Component() {
|
|
58
|
-
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.App, {
|
|
59
|
-
meta: {
|
|
60
|
-
pluginManager,
|
|
61
|
-
plugin: {
|
|
62
|
-
...plugin,
|
|
63
|
-
options
|
|
64
|
-
},
|
|
65
|
-
mode
|
|
66
|
-
},
|
|
67
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas, {
|
|
68
|
-
oas,
|
|
69
|
-
operations: [operation],
|
|
70
|
-
generator: instance,
|
|
71
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas.Operation, {
|
|
72
|
-
operation,
|
|
73
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(Operation, {
|
|
74
|
-
operation,
|
|
75
|
-
options,
|
|
76
|
-
instance
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
const app = (0, __kubb_react.createApp)();
|
|
83
|
-
app.use(__kubb_react.reactPlugin);
|
|
84
|
-
app.render(Component);
|
|
85
|
-
return app.files;
|
|
86
|
-
},
|
|
87
|
-
async schema({ instance, schema, options }) {
|
|
88
|
-
if (!parseOptions.Schema) return [];
|
|
89
|
-
const { pluginManager, oas, plugin, mode } = instance.context;
|
|
90
|
-
const Schema = parseOptions.Schema;
|
|
91
|
-
function Component() {
|
|
92
|
-
return /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(__kubb_react.App, {
|
|
93
|
-
meta: {
|
|
94
|
-
pluginManager,
|
|
95
|
-
plugin: {
|
|
96
|
-
...plugin,
|
|
97
|
-
options
|
|
98
|
-
},
|
|
99
|
-
mode
|
|
100
|
-
},
|
|
101
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas, {
|
|
102
|
-
oas,
|
|
103
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(require_Oas.Oas.Schema, {
|
|
104
|
-
name: schema.name,
|
|
105
|
-
schemaObject: schema.value,
|
|
106
|
-
tree: schema.tree,
|
|
107
|
-
children: /* @__PURE__ */ (0, __kubb_react_jsx_runtime.jsx)(Schema, {
|
|
108
|
-
schema,
|
|
109
|
-
options,
|
|
110
|
-
instance
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
})
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
const app = (0, __kubb_react.createApp)();
|
|
117
|
-
app.use(__kubb_react.reactPlugin);
|
|
118
|
-
app.render(Component);
|
|
119
|
-
return app.files;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
//#endregion
|
|
125
|
-
//#region src/generators/jsonGenerator.ts
|
|
126
|
-
const jsonGenerator = createGenerator({
|
|
127
|
-
name: "plugin-oas",
|
|
128
|
-
async schema({ schema, instance }) {
|
|
129
|
-
const { pluginManager, plugin } = instance.context;
|
|
130
|
-
return [{
|
|
131
|
-
...pluginManager.getFile({
|
|
132
|
-
name: (0, __kubb_core_transformers.camelCase)(schema.name),
|
|
133
|
-
extname: ".json",
|
|
134
|
-
mode: "split",
|
|
135
|
-
pluginKey: plugin.key
|
|
136
|
-
}),
|
|
137
|
-
sources: [{
|
|
138
|
-
name: (0, __kubb_core_transformers.camelCase)(schema.name),
|
|
139
|
-
isExportable: false,
|
|
140
|
-
isIndexable: false,
|
|
141
|
-
value: JSON.stringify(schema.value)
|
|
142
|
-
}],
|
|
143
|
-
banner: require_getFooter.getBanner({
|
|
144
|
-
oas: instance.context.oas,
|
|
145
|
-
output: plugin.options.output,
|
|
146
|
-
config: pluginManager.config
|
|
147
|
-
}),
|
|
148
|
-
format: require_getFooter.getFooter({
|
|
149
|
-
oas: instance.context.oas,
|
|
150
|
-
output: plugin.options.output
|
|
151
|
-
})
|
|
152
|
-
}];
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
//#endregion
|
|
157
|
-
Object.defineProperty(exports, 'createGenerator', {
|
|
158
|
-
enumerable: true,
|
|
159
|
-
get: function () {
|
|
160
|
-
return createGenerator;
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
Object.defineProperty(exports, 'createReactGenerator', {
|
|
164
|
-
enumerable: true,
|
|
165
|
-
get: function () {
|
|
166
|
-
return createReactGenerator;
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
Object.defineProperty(exports, 'jsonGenerator', {
|
|
170
|
-
enumerable: true,
|
|
171
|
-
get: function () {
|
|
172
|
-
return jsonGenerator;
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
//# sourceMappingURL=generators-CoiXCnDY.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generators-CoiXCnDY.cjs","names":["App","Oas","reactPlugin","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, reactPlugin } 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()\n app.use(reactPlugin)\n\n app.render(Component)\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()\n app.use(reactPlugin)\n\n app.render(Component)\n\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()\n app.use(reactPlugin)\n\n app.render(Component)\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,mCAAiB;AACvB,OAAI,IAAIC,yBAAY;AAEpB,OAAI,OAAO,UAAU;AACrB,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,kDAACF;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,mCAAiB;AACvB,OAAI,IAAIC,yBAAY;AAEpB,OAAI,OAAO,UAAU;AAErB,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,kDAACF;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,mCAAiB;AACvB,OAAI,IAAIC,yBAAY;AAEpB,OAAI,OAAO,UAAU;AACrB,UAAO,IAAI;;EAEd;;;;;ACnIH,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"}
|
package/src/generator.tsx
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import type { PluginFactoryOptions } from '@kubb/core'
|
|
2
|
-
import type { KubbFile } from '@kubb/core/fs'
|
|
3
|
-
import type { Operation, SchemaObject } from '@kubb/oas'
|
|
4
|
-
import { App, createApp, reactPlugin } from '@kubb/react'
|
|
5
|
-
import type { KubbNode } from '@kubb/react/types'
|
|
6
|
-
import { Oas } from './components/Oas.tsx'
|
|
7
|
-
import type { OperationGenerator } from './OperationGenerator.ts'
|
|
8
|
-
import type { SchemaGenerator, SchemaGeneratorOptions } from './SchemaGenerator.ts'
|
|
9
|
-
import type { Schema } from './SchemaMapper.ts'
|
|
10
|
-
|
|
11
|
-
type OperationsProps<TOptions extends PluginFactoryOptions> = {
|
|
12
|
-
instance: Omit<OperationGenerator<TOptions>, 'build'>
|
|
13
|
-
options: TOptions['resolvedOptions']
|
|
14
|
-
operations: Array<Operation>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type OperationProps<TOptions extends PluginFactoryOptions> = {
|
|
18
|
-
instance: Omit<OperationGenerator<TOptions>, 'build'>
|
|
19
|
-
options: TOptions['resolvedOptions']
|
|
20
|
-
operation: Operation
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type SchemaProps<TOptions extends PluginFactoryOptions> = {
|
|
24
|
-
instance: Omit<SchemaGenerator<SchemaGeneratorOptions, TOptions>, 'build'>
|
|
25
|
-
options: TOptions['resolvedOptions']
|
|
26
|
-
schema: {
|
|
27
|
-
name: string
|
|
28
|
-
tree: Array<Schema>
|
|
29
|
-
value: SchemaObject
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type GeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
34
|
-
name: string
|
|
35
|
-
operations?: (this: GeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => Promise<KubbFile.File[]>
|
|
36
|
-
operation?: (this: GeneratorOptions<TOptions>, props: OperationProps<TOptions>) => Promise<KubbFile.File[]>
|
|
37
|
-
schema?: (this: GeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => Promise<KubbFile.File[]>
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type Generator<TOptions extends PluginFactoryOptions> = GeneratorOptions<TOptions>
|
|
41
|
-
|
|
42
|
-
export function createGenerator<TOptions extends PluginFactoryOptions>(parseOptions: GeneratorOptions<TOptions>): Generator<TOptions> {
|
|
43
|
-
return parseOptions
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export type ReactGeneratorOptions<TOptions extends PluginFactoryOptions> = {
|
|
47
|
-
name: string
|
|
48
|
-
Operations?: (this: ReactGeneratorOptions<TOptions>, props: OperationsProps<TOptions>) => KubbNode
|
|
49
|
-
Operation?: (this: ReactGeneratorOptions<TOptions>, props: OperationProps<TOptions>) => KubbNode
|
|
50
|
-
Schema?: (this: ReactGeneratorOptions<TOptions>, props: SchemaProps<TOptions>) => KubbNode
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/****
|
|
54
|
-
* Creates a generator that uses React component functions to generate files for OpenAPI operations and schemas.
|
|
55
|
-
*
|
|
56
|
-
* 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.
|
|
57
|
-
*
|
|
58
|
-
* @returns A generator object with async methods for operations, operation, and schema file generation.
|
|
59
|
-
*/
|
|
60
|
-
export function createReactGenerator<TOptions extends PluginFactoryOptions>(parseOptions: ReactGeneratorOptions<TOptions>): Generator<TOptions> {
|
|
61
|
-
return {
|
|
62
|
-
...parseOptions,
|
|
63
|
-
async operations({ instance, options, operations }) {
|
|
64
|
-
if (!parseOptions.Operations) {
|
|
65
|
-
return []
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const { pluginManager, oas, plugin, mode } = instance.context
|
|
69
|
-
const Operations = parseOptions.Operations
|
|
70
|
-
|
|
71
|
-
function Component() {
|
|
72
|
-
return (
|
|
73
|
-
<App meta={{ pluginManager, plugin, mode }}>
|
|
74
|
-
<Oas oas={oas} operations={operations} generator={instance}>
|
|
75
|
-
<Operations operations={operations} instance={instance} options={options} />
|
|
76
|
-
</Oas>
|
|
77
|
-
</App>
|
|
78
|
-
)
|
|
79
|
-
}
|
|
80
|
-
const app = createApp()
|
|
81
|
-
app.use(reactPlugin)
|
|
82
|
-
|
|
83
|
-
app.render(Component)
|
|
84
|
-
return app.files
|
|
85
|
-
},
|
|
86
|
-
async operation({ instance, operation, options }) {
|
|
87
|
-
if (!parseOptions.Operation) {
|
|
88
|
-
return []
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const { pluginManager, oas, plugin, mode } = instance.context
|
|
92
|
-
const Operation = parseOptions.Operation
|
|
93
|
-
|
|
94
|
-
function Component() {
|
|
95
|
-
return (
|
|
96
|
-
<App meta={{ pluginManager, plugin: { ...plugin, options }, mode }}>
|
|
97
|
-
<Oas oas={oas} operations={[operation]} generator={instance}>
|
|
98
|
-
<Oas.Operation operation={operation}>
|
|
99
|
-
<Operation operation={operation} options={options} instance={instance} />
|
|
100
|
-
</Oas.Operation>
|
|
101
|
-
</Oas>
|
|
102
|
-
</App>
|
|
103
|
-
)
|
|
104
|
-
}
|
|
105
|
-
const app = createApp()
|
|
106
|
-
app.use(reactPlugin)
|
|
107
|
-
|
|
108
|
-
app.render(Component)
|
|
109
|
-
|
|
110
|
-
return app.files
|
|
111
|
-
},
|
|
112
|
-
async schema({ instance, schema, options }) {
|
|
113
|
-
if (!parseOptions.Schema) {
|
|
114
|
-
return []
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const { pluginManager, oas, plugin, mode } = instance.context
|
|
118
|
-
|
|
119
|
-
const Schema = parseOptions.Schema
|
|
120
|
-
|
|
121
|
-
function Component() {
|
|
122
|
-
return (
|
|
123
|
-
<App meta={{ pluginManager, plugin: { ...plugin, options }, mode }}>
|
|
124
|
-
<Oas oas={oas}>
|
|
125
|
-
<Oas.Schema name={schema.name} schemaObject={schema.value} tree={schema.tree}>
|
|
126
|
-
<Schema schema={schema} options={options} instance={instance} />
|
|
127
|
-
</Oas.Schema>
|
|
128
|
-
</Oas>
|
|
129
|
-
</App>
|
|
130
|
-
)
|
|
131
|
-
}
|
|
132
|
-
const app = createApp()
|
|
133
|
-
app.use(reactPlugin)
|
|
134
|
-
|
|
135
|
-
app.render(Component)
|
|
136
|
-
return app.files
|
|
137
|
-
},
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { useContext } from '@kubb/react'
|
|
2
|
-
|
|
3
|
-
import { Oas } from '../components/Oas.tsx'
|
|
4
|
-
|
|
5
|
-
import type { HttpMethod, Operation } from '@kubb/oas'
|
|
6
|
-
|
|
7
|
-
type UseOperationsProps = {
|
|
8
|
-
/**
|
|
9
|
-
* Filter based on path
|
|
10
|
-
* Weight: 2
|
|
11
|
-
*/
|
|
12
|
-
path?: string
|
|
13
|
-
/**
|
|
14
|
-
* Filter based on method
|
|
15
|
-
* Weight: 1
|
|
16
|
-
*/
|
|
17
|
-
method?: HttpMethod
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* `useOperations` will return all the Operations
|
|
22
|
-
*/
|
|
23
|
-
export function useOperations({ method, path }: UseOperationsProps = {}): Operation[] {
|
|
24
|
-
const { operations } = useContext(Oas.Context)
|
|
25
|
-
|
|
26
|
-
if (!operations) {
|
|
27
|
-
throw new Error('Operations is not defined')
|
|
28
|
-
}
|
|
29
|
-
let items = operations
|
|
30
|
-
|
|
31
|
-
if (path) {
|
|
32
|
-
items = items.filter((item) => item.path === path)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (method) {
|
|
36
|
-
items = items.filter((item) => item.method === method)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return items
|
|
40
|
-
}
|