@kubb/plugin-client 3.4.5 → 3.5.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.
@@ -0,0 +1,174 @@
1
+ import { Url, Client, Operations } from './chunk-HVZSAZQR.js';
2
+ import { createReactGenerator } from '@kubb/plugin-oas';
3
+ import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks';
4
+ import { getBanner, getFooter } from '@kubb/plugin-oas/utils';
5
+ import { pluginTsName } from '@kubb/plugin-ts';
6
+ import { pluginZodName } from '@kubb/plugin-zod';
7
+ import { useApp, File, Function } from '@kubb/react';
8
+ import { jsxs, jsx } from '@kubb/react/jsx-runtime';
9
+ import { camelCase } from '@kubb/core/transformers';
10
+
11
+ var clientGenerator = createReactGenerator({
12
+ name: "client",
13
+ Operation({ options, operation }) {
14
+ const {
15
+ plugin: {
16
+ options: { output }
17
+ }
18
+ } = useApp();
19
+ const oas = useOas();
20
+ const { getSchemas, getName, getFile } = useOperationManager();
21
+ const client = {
22
+ name: getName(operation, { type: "function" }),
23
+ file: getFile(operation)
24
+ };
25
+ const url = {
26
+ name: getName(operation, { type: "function", suffix: "url", prefix: "get" }),
27
+ file: getFile(operation)
28
+ };
29
+ const type = {
30
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
31
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: "type" })
32
+ };
33
+ const zod = {
34
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
35
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: "function" })
36
+ };
37
+ return /* @__PURE__ */ jsxs(
38
+ File,
39
+ {
40
+ baseName: client.file.baseName,
41
+ path: client.file.path,
42
+ meta: client.file.meta,
43
+ banner: getBanner({ oas, output }),
44
+ footer: getFooter({ oas, output }),
45
+ children: [
46
+ /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.importPath }),
47
+ /* @__PURE__ */ jsx(File.Import, { name: ["RequestConfig", "ResponseErrorConfig"], path: options.importPath, isTypeOnly: true }),
48
+ options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, { name: [zod.schemas.response.name], root: client.file.path, path: zod.file.path }),
49
+ /* @__PURE__ */ jsx(
50
+ File.Import,
51
+ {
52
+ name: [
53
+ type.schemas.request?.name,
54
+ type.schemas.response.name,
55
+ type.schemas.pathParams?.name,
56
+ type.schemas.queryParams?.name,
57
+ type.schemas.headerParams?.name,
58
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
59
+ ].filter(Boolean),
60
+ root: client.file.path,
61
+ path: type.file.path,
62
+ isTypeOnly: true
63
+ }
64
+ ),
65
+ /* @__PURE__ */ jsx(
66
+ Url,
67
+ {
68
+ name: url.name,
69
+ baseURL: options.baseURL,
70
+ pathParamsType: options.pathParamsType,
71
+ paramsCasing: options.paramsCasing,
72
+ paramsType: options.paramsType,
73
+ typeSchemas: type.schemas,
74
+ operation
75
+ }
76
+ ),
77
+ /* @__PURE__ */ jsx(
78
+ Client,
79
+ {
80
+ name: client.name,
81
+ urlName: url.name,
82
+ baseURL: options.baseURL,
83
+ dataReturnType: options.dataReturnType,
84
+ pathParamsType: options.pathParamsType,
85
+ paramsCasing: options.paramsCasing,
86
+ paramsType: options.paramsType,
87
+ typeSchemas: type.schemas,
88
+ operation,
89
+ parser: options.parser,
90
+ zodSchemas: zod.schemas
91
+ }
92
+ )
93
+ ]
94
+ }
95
+ );
96
+ }
97
+ });
98
+ var operationsGenerator = createReactGenerator({
99
+ name: "client",
100
+ Operations({ operations }) {
101
+ const {
102
+ pluginManager,
103
+ plugin: {
104
+ key: pluginKey,
105
+ options: { output }
106
+ }
107
+ } = useApp();
108
+ const oas = useOas();
109
+ const name = "operations";
110
+ const file = pluginManager.getFile({ name, extname: ".ts", pluginKey });
111
+ return /* @__PURE__ */ jsx(File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: getBanner({ oas, output }), footer: getFooter({ oas, output }), children: /* @__PURE__ */ jsx(Operations, { name, operations }) });
112
+ }
113
+ });
114
+ var groupedClientGenerator = createReactGenerator({
115
+ name: "groupedClient",
116
+ Operations({ operations }) {
117
+ const {
118
+ pluginManager,
119
+ plugin: { options, key: pluginKey }
120
+ } = useApp();
121
+ const oas = useOas();
122
+ const { getName, getFile, getGroup } = useOperationManager();
123
+ const controllers = operations.reduce(
124
+ (acc, operation) => {
125
+ if (options.group?.type === "tag") {
126
+ const group = getGroup(operation);
127
+ const name = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) : void 0;
128
+ if (!group?.tag || !name) {
129
+ return acc;
130
+ }
131
+ const file = pluginManager.getFile({
132
+ name,
133
+ extname: ".ts",
134
+ pluginKey,
135
+ options: { group }
136
+ });
137
+ const client = {
138
+ name: getName(operation, { type: "function" }),
139
+ file: getFile(operation)
140
+ };
141
+ const previousFile = acc.find((item) => item.file.path === file.path);
142
+ if (previousFile) {
143
+ previousFile.clients.push(client);
144
+ } else {
145
+ acc.push({ name, file, clients: [client] });
146
+ }
147
+ }
148
+ return acc;
149
+ },
150
+ []
151
+ );
152
+ return controllers.map(({ name, file, clients }) => {
153
+ return /* @__PURE__ */ jsxs(
154
+ File,
155
+ {
156
+ baseName: file.baseName,
157
+ path: file.path,
158
+ meta: file.meta,
159
+ banner: getBanner({ oas, output: options.output }),
160
+ footer: getFooter({ oas, output: options.output }),
161
+ children: [
162
+ clients.map((client) => /* @__PURE__ */ jsx(File.Import, { name: [client.name], root: file.path, path: client.file.path }, client.name)),
163
+ /* @__PURE__ */ jsx(File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsx(Function, { export: true, name, children: `return { ${clients.map((client) => client.name).join(", ")} }` }) })
164
+ ]
165
+ },
166
+ file.path
167
+ );
168
+ });
169
+ }
170
+ });
171
+
172
+ export { clientGenerator, groupedClientGenerator, operationsGenerator };
173
+ //# sourceMappingURL=chunk-HMHER7HU.js.map
174
+ //# sourceMappingURL=chunk-HMHER7HU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/clientGenerator.tsx","../src/generators/operationsGenerator.tsx","../src/generators/groupedClientGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","jsx","File","getBanner","getFooter","useOperationManager","jsxs"],"mappings":";;;;;;;;;;AAUO,IAAM,kBAAkB,oBAAmC,CAAA;AAAA,EAChE,IAAM,EAAA,QAAA;AAAA,EACN,SAAU,CAAA,EAAE,OAAS,EAAA,SAAA,EAAa,EAAA;AAChC,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO;AAAA;AACpB,QACE,MAAqB,EAAA;AACzB,IAAA,MAAM,MAAM,MAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAY,mBAAoB,EAAA;AAE7D,IAAA,MAAM,MAAS,GAAA;AAAA,MACb,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA;AAAA,MAC7C,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,GAAM,GAAA;AAAA,MACV,IAAA,EAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,MAAQ,EAAA,KAAA,EAAO,MAAQ,EAAA,KAAA,EAAO,CAAA;AAAA,MAC3E,IAAA,EAAM,QAAQ,SAAS;AAAA,KACzB;AAEA,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,YAAY,GAAG,CAAA;AAAA,MACtD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW,EAAE,SAAA,EAAW,CAAC,YAAY,CAAA,EAAG,IAAM,EAAA,MAAA,EAAQ;AAAA,KAC5E;AAEA,IAAA,MAAM,GAAM,GAAA;AAAA,MACV,IAAA,EAAM,QAAQ,SAAW,EAAA,EAAE,WAAW,CAAC,aAAa,GAAG,CAAA;AAAA,MACvD,OAAA,EAAS,UAAW,CAAA,SAAA,EAAW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IAAA;AAAA,UACX,MAAM,IAAK,CAAA,IAAA;AAAA,UACX,QAAQC,SAAU,CAAA,EAAE,KAAK,MAAQ,EAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA,UACjD,QAAQC,SAAU,CAAA,EAAE,KAAK,MAAQ,EAAA,OAAA,CAAQ,QAAQ,CAAA;AAAA,UAEhD,QAAA,EAAA;AAAA,YAAQ,OAAA,CAAA,GAAA,CAAI,CAAC,MACZ,qBAAAH,IAACC,IAAK,CAAA,MAAA,EAAL,EAA8B,IAAA,EAAM,CAAC,MAAA,CAAO,IAAI,CAAG,EAAA,IAAA,EAAM,KAAK,IAAM,EAAA,IAAA,EAAM,OAAO,IAAK,CAAA,IAAA,EAAA,EAArE,MAAO,CAAA,IAAoE,CAC9F,CAAA;AAAA,4BAEDD,GAAAA,CAACC,IAAK,CAAA,MAAA,EAAL,EAAY,IAAA,EAAY,YAAY,EAAA,IAAA,EAAC,WAAW,EAAA,IAAA,EAC/C,QAAAD,kBAAAA,GAAAA,CAAC,QAAS,EAAA,EAAA,MAAA,EAAM,IAAC,EAAA,IAAA,EACd,QAAY,EAAA,CAAA,SAAA,EAAA,OAAA,CAAQ,GAAI,CAAA,CAAC,MAAW,KAAA,MAAA,CAAO,IAAI,CAAA,CAAE,IAAK,CAAA,IAAI,CAAC,CAAA,EAAA,CAAA,EAC9D,CACF,EAAA;AAAA;AAAA,SAAA;AAAA,QAfK,IAAK,CAAA;AAAA,OAgBZ;AAAA,KAEH,CAAA;AAAA;AAEL,CAAC","file":"chunk-HMHER7HU.js","sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport { Url } from '../components/Url.tsx'\nimport type { PluginClient } from '../types'\n\nexport const clientGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginClient>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const client = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const url = {\n name: getName(operation, { type: 'function', suffix: 'url', prefix: 'get' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n return (\n <File\n baseName={client.file.baseName}\n path={client.file.path}\n meta={client.file.meta}\n banner={getBanner({ oas, output })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={'client'} path={options.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.importPath} isTypeOnly />\n {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={client.file.path} path={zod.file.path} />}\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={client.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <Url\n name={url.name}\n baseURL={options.baseURL}\n pathParamsType={options.pathParamsType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n typeSchemas={type.schemas}\n operation={operation}\n />\n\n <Client\n name={client.name}\n urlName={url.name}\n baseURL={options.baseURL}\n dataReturnType={options.dataReturnType}\n pathParamsType={options.pathParamsType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n typeSchemas={type.schemas}\n operation={operation}\n parser={options.parser}\n zodSchemas={zod.schemas}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginClient>()\n const oas = useOas()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>\n <Operations name={name} operations={operations} />\n </File>\n )\n },\n})\n","import { camelCase } from '@kubb/core/transformers'\nimport type * as KubbFile from '@kubb/fs/types'\n\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, Function, useApp } from '@kubb/react'\nimport type { PluginClient } from '../types'\n\nexport const groupedClientGenerator = createReactGenerator<PluginClient>({\n name: 'groupedClient',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: { options, key: pluginKey },\n } = useApp<PluginClient>()\n const oas = useOas()\n const { getName, getFile, getGroup } = useOperationManager()\n\n const controllers = operations.reduce(\n (acc, operation) => {\n if (options.group?.type === 'tag') {\n const group = getGroup(operation)\n const name = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) : undefined\n\n if (!group?.tag || !name) {\n return acc\n }\n\n const file = pluginManager.getFile({\n name,\n extname: '.ts',\n pluginKey,\n options: { group },\n })\n\n const client = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const previousFile = acc.find((item) => item.file.path === file.path)\n\n if (previousFile) {\n previousFile.clients.push(client)\n } else {\n acc.push({ name, file, clients: [client] })\n }\n }\n\n return acc\n },\n [] as Array<{ name: string; file: KubbFile.File; clients: Array<{ name: string; file: KubbFile.File }> }>,\n )\n\n return controllers.map(({ name, file, clients }) => {\n return (\n <File\n key={file.path}\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: options.output })}\n footer={getFooter({ oas, output: options.output })}\n >\n {clients.map((client) => (\n <File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />\n ))}\n\n <File.Source name={name} isExportable isIndexable>\n <Function export name={name}>\n {`return { ${clients.map((client) => client.name).join(', ')} }`}\n </Function>\n </File.Source>\n </File>\n )\n })\n },\n})\n"]}
@@ -0,0 +1,178 @@
1
+ 'use strict';
2
+
3
+ var chunkGUUH6APU_cjs = require('./chunk-GUUH6APU.cjs');
4
+ var pluginOas = require('@kubb/plugin-oas');
5
+ var hooks = require('@kubb/plugin-oas/hooks');
6
+ var utils = require('@kubb/plugin-oas/utils');
7
+ var pluginTs = require('@kubb/plugin-ts');
8
+ var pluginZod = require('@kubb/plugin-zod');
9
+ var react = require('@kubb/react');
10
+ var jsxRuntime = require('@kubb/react/jsx-runtime');
11
+ var transformers = require('@kubb/core/transformers');
12
+
13
+ var clientGenerator = pluginOas.createReactGenerator({
14
+ name: "client",
15
+ Operation({ options, operation }) {
16
+ const {
17
+ plugin: {
18
+ options: { output }
19
+ }
20
+ } = react.useApp();
21
+ const oas = hooks.useOas();
22
+ const { getSchemas, getName, getFile } = hooks.useOperationManager();
23
+ const client = {
24
+ name: getName(operation, { type: "function" }),
25
+ file: getFile(operation)
26
+ };
27
+ const url = {
28
+ name: getName(operation, { type: "function", suffix: "url", prefix: "get" }),
29
+ file: getFile(operation)
30
+ };
31
+ const type = {
32
+ file: getFile(operation, { pluginKey: [pluginTs.pluginTsName] }),
33
+ schemas: getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" })
34
+ };
35
+ const zod = {
36
+ file: getFile(operation, { pluginKey: [pluginZod.pluginZodName] }),
37
+ schemas: getSchemas(operation, { pluginKey: [pluginZod.pluginZodName], type: "function" })
38
+ };
39
+ return /* @__PURE__ */ jsxRuntime.jsxs(
40
+ react.File,
41
+ {
42
+ baseName: client.file.baseName,
43
+ path: client.file.path,
44
+ meta: client.file.meta,
45
+ banner: utils.getBanner({ oas, output }),
46
+ footer: utils.getFooter({ oas, output }),
47
+ children: [
48
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: options.importPath }),
49
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["RequestConfig", "ResponseErrorConfig"], path: options.importPath, isTypeOnly: true }),
50
+ options.parser === "zod" && /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [zod.schemas.response.name], root: client.file.path, path: zod.file.path }),
51
+ /* @__PURE__ */ jsxRuntime.jsx(
52
+ react.File.Import,
53
+ {
54
+ name: [
55
+ type.schemas.request?.name,
56
+ type.schemas.response.name,
57
+ type.schemas.pathParams?.name,
58
+ type.schemas.queryParams?.name,
59
+ type.schemas.headerParams?.name,
60
+ ...type.schemas.statusCodes?.map((item) => item.name) || []
61
+ ].filter(Boolean),
62
+ root: client.file.path,
63
+ path: type.file.path,
64
+ isTypeOnly: true
65
+ }
66
+ ),
67
+ /* @__PURE__ */ jsxRuntime.jsx(
68
+ chunkGUUH6APU_cjs.Url,
69
+ {
70
+ name: url.name,
71
+ baseURL: options.baseURL,
72
+ pathParamsType: options.pathParamsType,
73
+ paramsCasing: options.paramsCasing,
74
+ paramsType: options.paramsType,
75
+ typeSchemas: type.schemas,
76
+ operation
77
+ }
78
+ ),
79
+ /* @__PURE__ */ jsxRuntime.jsx(
80
+ chunkGUUH6APU_cjs.Client,
81
+ {
82
+ name: client.name,
83
+ urlName: url.name,
84
+ baseURL: options.baseURL,
85
+ dataReturnType: options.dataReturnType,
86
+ pathParamsType: options.pathParamsType,
87
+ paramsCasing: options.paramsCasing,
88
+ paramsType: options.paramsType,
89
+ typeSchemas: type.schemas,
90
+ operation,
91
+ parser: options.parser,
92
+ zodSchemas: zod.schemas
93
+ }
94
+ )
95
+ ]
96
+ }
97
+ );
98
+ }
99
+ });
100
+ var operationsGenerator = pluginOas.createReactGenerator({
101
+ name: "client",
102
+ Operations({ operations }) {
103
+ const {
104
+ pluginManager,
105
+ plugin: {
106
+ key: pluginKey,
107
+ options: { output }
108
+ }
109
+ } = react.useApp();
110
+ const oas = hooks.useOas();
111
+ const name = "operations";
112
+ const file = pluginManager.getFile({ name, extname: ".ts", pluginKey });
113
+ return /* @__PURE__ */ jsxRuntime.jsx(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, banner: utils.getBanner({ oas, output }), footer: utils.getFooter({ oas, output }), children: /* @__PURE__ */ jsxRuntime.jsx(chunkGUUH6APU_cjs.Operations, { name, operations }) });
114
+ }
115
+ });
116
+ var groupedClientGenerator = pluginOas.createReactGenerator({
117
+ name: "groupedClient",
118
+ Operations({ operations }) {
119
+ const {
120
+ pluginManager,
121
+ plugin: { options, key: pluginKey }
122
+ } = react.useApp();
123
+ const oas = hooks.useOas();
124
+ const { getName, getFile, getGroup } = hooks.useOperationManager();
125
+ const controllers = operations.reduce(
126
+ (acc, operation) => {
127
+ if (options.group?.type === "tag") {
128
+ const group = getGroup(operation);
129
+ const name = group?.tag ? options.group?.name?.({ group: transformers.camelCase(group.tag) }) : void 0;
130
+ if (!group?.tag || !name) {
131
+ return acc;
132
+ }
133
+ const file = pluginManager.getFile({
134
+ name,
135
+ extname: ".ts",
136
+ pluginKey,
137
+ options: { group }
138
+ });
139
+ const client = {
140
+ name: getName(operation, { type: "function" }),
141
+ file: getFile(operation)
142
+ };
143
+ const previousFile = acc.find((item) => item.file.path === file.path);
144
+ if (previousFile) {
145
+ previousFile.clients.push(client);
146
+ } else {
147
+ acc.push({ name, file, clients: [client] });
148
+ }
149
+ }
150
+ return acc;
151
+ },
152
+ []
153
+ );
154
+ return controllers.map(({ name, file, clients }) => {
155
+ return /* @__PURE__ */ jsxRuntime.jsxs(
156
+ react.File,
157
+ {
158
+ baseName: file.baseName,
159
+ path: file.path,
160
+ meta: file.meta,
161
+ banner: utils.getBanner({ oas, output: options.output }),
162
+ footer: utils.getFooter({ oas, output: options.output }),
163
+ children: [
164
+ clients.map((client) => /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: [client.name], root: file.path, path: client.file.path }, client.name)),
165
+ /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { export: true, name, children: `return { ${clients.map((client) => client.name).join(", ")} }` }) })
166
+ ]
167
+ },
168
+ file.path
169
+ );
170
+ });
171
+ }
172
+ });
173
+
174
+ exports.clientGenerator = clientGenerator;
175
+ exports.groupedClientGenerator = groupedClientGenerator;
176
+ exports.operationsGenerator = operationsGenerator;
177
+ //# sourceMappingURL=chunk-RWN7DR6M.cjs.map
178
+ //# sourceMappingURL=chunk-RWN7DR6M.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/generators/clientGenerator.tsx","../src/generators/operationsGenerator.tsx","../src/generators/groupedClientGenerator.tsx"],"names":["createReactGenerator","useApp","useOas","useOperationManager","pluginTsName","pluginZodName","jsxs","File","getBanner","getFooter","jsx","Url","Client","Operations","camelCase","Function"],"mappings":";;;;;;;;;;;;AAUO,IAAM,kBAAkBA,8BAAmC,CAAA;AAAA,EAChE,IAAM,EAAA,QAAA;AAAA,EACN,SAAU,CAAA,EAAE,OAAS,EAAA,SAAA,EAAa,EAAA;AAChC,IAAM,MAAA;AAAA,MACJ,MAAQ,EAAA;AAAA,QACN,OAAA,EAAS,EAAE,MAAO;AAAA;AACpB,QACEC,YAAqB,EAAA;AACzB,IAAA,MAAM,MAAMC,YAAO,EAAA;AACnB,IAAA,MAAM,EAAE,UAAA,EAAY,OAAS,EAAA,OAAA,KAAYC,yBAAoB,EAAA;AAE7D,IAAA,MAAM,MAAS,GAAA;AAAA,MACb,MAAM,OAAQ,CAAA,SAAA,EAAW,EAAE,IAAA,EAAM,YAAY,CAAA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AAY,EAAA,IAAA,EAAC,WAAW,EAAA,IAAA,EAC/C,QAAAG,kBAAAA,cAAAA,CAACK,cAAS,EAAA,EAAA,MAAA,EAAM,IAAC,EAAA,IAAA,EACd,QAAY,EAAA,CAAA,SAAA,EAAA,OAAA,CAAQ,GAAI,CAAA,CAAC,MAAW,KAAA,MAAA,CAAO,IAAI,CAAA,CAAE,IAAK,CAAA,IAAI,CAAC,CAAA,EAAA,CAAA,EAC9D,CACF,EAAA;AAAA;AAAA,SAAA;AAAA,QAfK,IAAK,CAAA;AAAA,OAgBZ;AAAA,KAEH,CAAA;AAAA;AAEL,CAAC","file":"chunk-RWN7DR6M.cjs","sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport { Url } from '../components/Url.tsx'\nimport type { PluginClient } from '../types'\n\nexport const clientGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operation({ options, operation }) {\n const {\n plugin: {\n options: { output },\n },\n } = useApp<PluginClient>()\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const client = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const url = {\n name: getName(operation, { type: 'function', suffix: 'url', prefix: 'get' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n const zod = {\n file: getFile(operation, { pluginKey: [pluginZodName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),\n }\n\n return (\n <File\n baseName={client.file.baseName}\n path={client.file.path}\n meta={client.file.meta}\n banner={getBanner({ oas, output })}\n footer={getFooter({ oas, output })}\n >\n <File.Import name={'client'} path={options.importPath} />\n <File.Import name={['RequestConfig', 'ResponseErrorConfig']} path={options.importPath} isTypeOnly />\n {options.parser === 'zod' && <File.Import name={[zod.schemas.response.name]} root={client.file.path} path={zod.file.path} />}\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={client.file.path}\n path={type.file.path}\n isTypeOnly\n />\n\n <Url\n name={url.name}\n baseURL={options.baseURL}\n pathParamsType={options.pathParamsType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n typeSchemas={type.schemas}\n operation={operation}\n />\n\n <Client\n name={client.name}\n urlName={url.name}\n baseURL={options.baseURL}\n dataReturnType={options.dataReturnType}\n pathParamsType={options.pathParamsType}\n paramsCasing={options.paramsCasing}\n paramsType={options.paramsType}\n typeSchemas={type.schemas}\n operation={operation}\n parser={options.parser}\n zodSchemas={zod.schemas}\n />\n </File>\n )\n },\n})\n","import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, useApp } from '@kubb/react'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const operationsGenerator = createReactGenerator<PluginClient>({\n name: 'client',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: {\n key: pluginKey,\n options: { output },\n },\n } = useApp<PluginClient>()\n const oas = useOas()\n\n const name = 'operations'\n const file = pluginManager.getFile({ name, extname: '.ts', pluginKey })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta} banner={getBanner({ oas, output })} footer={getFooter({ oas, output })}>\n <Operations name={name} operations={operations} />\n </File>\n )\n },\n})\n","import { camelCase } from '@kubb/core/transformers'\nimport type * as KubbFile from '@kubb/fs/types'\n\nimport { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { File, Function, useApp } from '@kubb/react'\nimport type { PluginClient } from '../types'\n\nexport const groupedClientGenerator = createReactGenerator<PluginClient>({\n name: 'groupedClient',\n Operations({ operations }) {\n const {\n pluginManager,\n plugin: { options, key: pluginKey },\n } = useApp<PluginClient>()\n const oas = useOas()\n const { getName, getFile, getGroup } = useOperationManager()\n\n const controllers = operations.reduce(\n (acc, operation) => {\n if (options.group?.type === 'tag') {\n const group = getGroup(operation)\n const name = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) : undefined\n\n if (!group?.tag || !name) {\n return acc\n }\n\n const file = pluginManager.getFile({\n name,\n extname: '.ts',\n pluginKey,\n options: { group },\n })\n\n const client = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const previousFile = acc.find((item) => item.file.path === file.path)\n\n if (previousFile) {\n previousFile.clients.push(client)\n } else {\n acc.push({ name, file, clients: [client] })\n }\n }\n\n return acc\n },\n [] as Array<{ name: string; file: KubbFile.File; clients: Array<{ name: string; file: KubbFile.File }> }>,\n )\n\n return controllers.map(({ name, file, clients }) => {\n return (\n <File\n key={file.path}\n baseName={file.baseName}\n path={file.path}\n meta={file.meta}\n banner={getBanner({ oas, output: options.output })}\n footer={getFooter({ oas, output: options.output })}\n >\n {clients.map((client) => (\n <File.Import key={client.name} name={[client.name]} root={file.path} path={client.file.path} />\n ))}\n\n <File.Source name={name} isExportable isIndexable>\n <Function export name={name}>\n {`return { ${clients.map((client) => client.name).join(', ')} }`}\n </Function>\n </File.Source>\n </File>\n )\n })\n },\n})\n"]}
@@ -1,7 +1,7 @@
1
1
  import { Operation } from '@kubb/oas';
2
2
  import { OperationSchemas } from '@kubb/plugin-oas';
3
3
  import { FunctionParams } from '@kubb/react';
4
- import { P as PluginClient } from './types-P398e_Yv.cjs';
4
+ import { P as PluginClient } from './types-CP1y6jDc.cjs';
5
5
  import '@kubb/core';
6
6
 
7
7
  type Props$1 = {
@@ -1,7 +1,7 @@
1
1
  import { Operation } from '@kubb/oas';
2
2
  import { OperationSchemas } from '@kubb/plugin-oas';
3
3
  import { FunctionParams } from '@kubb/react';
4
- import { P as PluginClient } from './types-P398e_Yv.js';
4
+ import { P as PluginClient } from './types-CP1y6jDc.js';
5
5
  import '@kubb/core';
6
6
 
7
7
  type Props$1 = {
@@ -1,21 +1,21 @@
1
1
  'use strict';
2
2
 
3
- var chunkYARG5LEI_cjs = require('./chunk-YARG5LEI.cjs');
3
+ var chunkRWN7DR6M_cjs = require('./chunk-RWN7DR6M.cjs');
4
4
  require('./chunk-GUUH6APU.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, "clientGenerator", {
9
9
  enumerable: true,
10
- get: function () { return chunkYARG5LEI_cjs.clientGenerator; }
10
+ get: function () { return chunkRWN7DR6M_cjs.clientGenerator; }
11
11
  });
12
12
  Object.defineProperty(exports, "groupedClientGenerator", {
13
13
  enumerable: true,
14
- get: function () { return chunkYARG5LEI_cjs.groupedClientGenerator; }
14
+ get: function () { return chunkRWN7DR6M_cjs.groupedClientGenerator; }
15
15
  });
16
16
  Object.defineProperty(exports, "operationsGenerator", {
17
17
  enumerable: true,
18
- get: function () { return chunkYARG5LEI_cjs.operationsGenerator; }
18
+ get: function () { return chunkRWN7DR6M_cjs.operationsGenerator; }
19
19
  });
20
20
  //# sourceMappingURL=generators.cjs.map
21
21
  //# sourceMappingURL=generators.cjs.map
@@ -1,6 +1,7 @@
1
1
  import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginClient } from './types-P398e_Yv.cjs';
2
+ import { P as PluginClient } from './types-CP1y6jDc.cjs';
3
3
  import '@kubb/core';
4
+ import '@kubb/oas';
4
5
 
5
6
  declare const clientGenerator: _kubb_plugin_oas.Generator<PluginClient>;
6
7
 
@@ -1,6 +1,7 @@
1
1
  import * as _kubb_plugin_oas from '@kubb/plugin-oas';
2
- import { P as PluginClient } from './types-P398e_Yv.js';
2
+ import { P as PluginClient } from './types-CP1y6jDc.js';
3
3
  import '@kubb/core';
4
+ import '@kubb/oas';
4
5
 
5
6
  declare const clientGenerator: _kubb_plugin_oas.Generator<PluginClient>;
6
7
 
@@ -1,4 +1,4 @@
1
- export { clientGenerator, groupedClientGenerator, operationsGenerator } from './chunk-6IVTF2W4.js';
1
+ export { clientGenerator, groupedClientGenerator, operationsGenerator } from './chunk-HMHER7HU.js';
2
2
  import './chunk-HVZSAZQR.js';
3
3
  //# sourceMappingURL=generators.js.map
4
4
  //# sourceMappingURL=generators.js.map
package/dist/index.cjs CHANGED
@@ -1,17 +1,122 @@
1
1
  'use strict';
2
2
 
3
- var chunkYARG5LEI_cjs = require('./chunk-YARG5LEI.cjs');
3
+ var chunkRWN7DR6M_cjs = require('./chunk-RWN7DR6M.cjs');
4
4
  require('./chunk-GUUH6APU.cjs');
5
+ var path = require('path');
6
+ var core = require('@kubb/core');
7
+ var transformers = require('@kubb/core/transformers');
8
+ var pluginOas = require('@kubb/plugin-oas');
9
+ var pluginZod = require('@kubb/plugin-zod');
5
10
 
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
6
12
 
13
+ var path__default = /*#__PURE__*/_interopDefault(path);
7
14
 
8
- Object.defineProperty(exports, "pluginClient", {
9
- enumerable: true,
10
- get: function () { return chunkYARG5LEI_cjs.pluginClient; }
11
- });
12
- Object.defineProperty(exports, "pluginClientName", {
13
- enumerable: true,
14
- get: function () { return chunkYARG5LEI_cjs.pluginClientName; }
15
+ var pluginClientName = "plugin-client";
16
+ var pluginClient = core.createPlugin((options) => {
17
+ const {
18
+ output = { path: "clients", barrelType: "named" },
19
+ group,
20
+ exclude = [],
21
+ include,
22
+ override = [],
23
+ transformers: transformers$1 = {},
24
+ dataReturnType = "data",
25
+ pathParamsType = "inline",
26
+ paramsType = "inline",
27
+ operations = false,
28
+ baseURL,
29
+ paramsCasing,
30
+ generators = [chunkRWN7DR6M_cjs.clientGenerator, group ? chunkRWN7DR6M_cjs.groupedClientGenerator : void 0, operations ? chunkRWN7DR6M_cjs.operationsGenerator : void 0].filter(Boolean),
31
+ parser = "client",
32
+ client = "axios",
33
+ importPath = client === "fetch" ? "@kubb/plugin-client/clients/fetch" : "@kubb/plugin-client/clients/axios"
34
+ } = options;
35
+ return {
36
+ name: pluginClientName,
37
+ options: {
38
+ output,
39
+ group,
40
+ parser,
41
+ dataReturnType,
42
+ importPath,
43
+ paramsType,
44
+ paramsCasing,
45
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType,
46
+ baseURL
47
+ },
48
+ pre: [pluginOas.pluginOasName, parser === "zod" ? pluginZod.pluginZodName : void 0].filter(Boolean),
49
+ resolvePath(baseName, pathMode, options2) {
50
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
51
+ const mode = pathMode ?? core.FileManager.getMode(path__default.default.resolve(root, output.path));
52
+ if (mode === "single") {
53
+ return path__default.default.resolve(root, output.path);
54
+ }
55
+ if (group && (options2?.group?.path || options2?.group?.tag)) {
56
+ const groupName = group?.name ? group.name : (ctx) => {
57
+ if (group?.type === "path") {
58
+ return `${ctx.group.split("/")[1]}`;
59
+ }
60
+ return `${transformers.camelCase(ctx.group)}Controller`;
61
+ };
62
+ return path__default.default.resolve(
63
+ root,
64
+ output.path,
65
+ groupName({
66
+ group: group.type === "path" ? options2.group.path : options2.group.tag
67
+ }),
68
+ baseName
69
+ );
70
+ }
71
+ return path__default.default.resolve(root, output.path, baseName);
72
+ },
73
+ resolveName(name, type) {
74
+ const resolvedName = transformers.camelCase(name, { isFile: type === "file" });
75
+ if (type) {
76
+ return transformers$1?.name?.(resolvedName, type) || resolvedName;
77
+ }
78
+ return resolvedName;
79
+ },
80
+ async buildStart() {
81
+ const [swaggerPlugin] = core.PluginManager.getDependedPlugins(this.plugins, [pluginOas.pluginOasName]);
82
+ const oas = await swaggerPlugin.context.getOas();
83
+ const root = path__default.default.resolve(this.config.root, this.config.output.path);
84
+ const mode = core.FileManager.getMode(path__default.default.resolve(root, output.path));
85
+ const baseURL2 = await swaggerPlugin.context.getBaseURL();
86
+ const operationGenerator = new pluginOas.OperationGenerator(
87
+ baseURL2 ? {
88
+ ...this.plugin.options,
89
+ baseURL: baseURL2
90
+ } : this.plugin.options,
91
+ {
92
+ oas,
93
+ pluginManager: this.pluginManager,
94
+ plugin: this.plugin,
95
+ contentType: swaggerPlugin.context.contentType,
96
+ exclude,
97
+ include,
98
+ override,
99
+ mode
100
+ }
101
+ );
102
+ const files = await operationGenerator.build(...generators);
103
+ await this.addFile(...files);
104
+ const barrelFiles = await this.fileManager.getBarrelFiles({
105
+ type: output.barrelType ?? "named",
106
+ root,
107
+ output,
108
+ files: this.fileManager.files,
109
+ meta: {
110
+ pluginKey: this.plugin.key
111
+ },
112
+ logger: this.logger
113
+ });
114
+ await this.addFile(...barrelFiles);
115
+ }
116
+ };
15
117
  });
118
+
119
+ exports.pluginClient = pluginClient;
120
+ exports.pluginClientName = pluginClientName;
16
121
  //# sourceMappingURL=index.cjs.map
17
122
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs"}
1
+ {"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","clientGenerator","groupedClientGenerator","operationsGenerator","pluginOasName","pluginZodName","options","path","FileManager","camelCase","PluginManager","baseURL","OperationGenerator"],"mappings":";;;;;;;;;;;;;;AAcO,IAAM,gBAAmB,GAAA;AAEnB,IAAA,YAAA,GAAeA,iBAA2B,CAAA,CAAC,OAAY,KAAA;AAClE,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,SAAA,EAAW,YAAY,OAAQ,EAAA;AAAA,IAChD,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,kBACZC,iBAAe,EAAC;AAAA,IAChB,cAAiB,GAAA,MAAA;AAAA,IACjB,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AAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { pluginZodName } from '@kubb/plugin-zod'\nimport { operationsGenerator } from './generators'\nimport { clientGenerator } from './generators/clientGenerator.tsx'\nimport { groupedClientGenerator } from './generators/groupedClientGenerator.tsx'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = createPlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n paramsType = 'inline',\n operations = false,\n baseURL,\n paramsCasing,\n generators = [clientGenerator, group ? groupedClientGenerator : undefined, operations ? operationsGenerator : undefined].filter(Boolean),\n parser = 'client',\n client = 'axios',\n importPath = client === 'fetch' ? '@kubb/plugin-client/clients/fetch' : '@kubb/plugin-client/clients/axios',\n } = options\n\n return {\n name: pluginClientName,\n options: {\n output,\n group,\n parser,\n dataReturnType,\n importPath,\n paramsType,\n paramsCasing,\n pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,\n baseURL,\n },\n pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (group && (options?.group?.path || options?.group?.tag)) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(\n root,\n output.path,\n groupName({\n group: group.type === 'path' ? options.group.path! : options.group.tag!,\n }),\n baseName,\n )\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n const operationGenerator = new OperationGenerator(\n baseURL\n ? {\n ...this.plugin.options,\n baseURL,\n }\n : this.plugin.options,\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build(...generators)\n\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginClient } from './types-P398e_Yv.cjs';
2
+ import { O as Options, P as PluginClient } from './types-CP1y6jDc.cjs';
3
+ import '@kubb/oas';
3
4
  import '@kubb/plugin-oas';
4
5
 
5
6
  declare const pluginClientName = "plugin-client";