@kubb/plugin-client 5.0.0-alpha.3 → 5.0.0-alpha.31

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.
Files changed (42) hide show
  1. package/dist/clients/axios.d.ts +2 -2
  2. package/dist/index.cjs +1893 -74
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.ts +480 -4
  5. package/dist/index.js +1885 -77
  6. package/dist/index.js.map +1 -1
  7. package/package.json +10 -25
  8. package/src/components/ClassClient.tsx +42 -138
  9. package/src/components/Client.tsx +85 -124
  10. package/src/components/ClientLegacy.tsx +501 -0
  11. package/src/components/Operations.tsx +8 -8
  12. package/src/components/StaticClassClient.tsx +41 -135
  13. package/src/components/Url.tsx +37 -46
  14. package/src/generators/classClientGenerator.tsx +125 -148
  15. package/src/generators/clientGenerator.tsx +93 -82
  16. package/src/generators/groupedClientGenerator.tsx +47 -50
  17. package/src/generators/operationsGenerator.tsx +9 -17
  18. package/src/generators/staticClassClientGenerator.tsx +159 -164
  19. package/src/index.ts +11 -1
  20. package/src/plugin.ts +115 -108
  21. package/src/presets.ts +25 -0
  22. package/src/resolvers/resolverClient.ts +26 -0
  23. package/src/resolvers/resolverClientLegacy.ts +26 -0
  24. package/src/types.ts +105 -40
  25. package/src/utils.ts +148 -0
  26. package/dist/StaticClassClient-By-aMAe4.cjs +0 -677
  27. package/dist/StaticClassClient-By-aMAe4.cjs.map +0 -1
  28. package/dist/StaticClassClient-CCn9g9eF.js +0 -636
  29. package/dist/StaticClassClient-CCn9g9eF.js.map +0 -1
  30. package/dist/components.cjs +0 -7
  31. package/dist/components.d.ts +0 -216
  32. package/dist/components.js +0 -2
  33. package/dist/generators-C2jT7XCH.js +0 -723
  34. package/dist/generators-C2jT7XCH.js.map +0 -1
  35. package/dist/generators-qkDW17Hf.cjs +0 -753
  36. package/dist/generators-qkDW17Hf.cjs.map +0 -1
  37. package/dist/generators.cjs +0 -7
  38. package/dist/generators.d.ts +0 -512
  39. package/dist/generators.js +0 -2
  40. package/dist/types-CdM4DK1M.d.ts +0 -169
  41. package/src/components/index.ts +0 -5
  42. package/src/generators/index.ts +0 -5
package/dist/index.cjs CHANGED
@@ -1,81 +1,1912 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-ByKO4r7w.cjs");
3
- const require_StaticClassClient = require("./StaticClassClient-By-aMAe4.cjs");
4
- const require_generators = require("./generators-qkDW17Hf.cjs");
5
3
  const require_templates_clients_axios_source = require("./templates/clients/axios.source.cjs");
6
4
  const require_templates_clients_fetch_source = require("./templates/clients/fetch.source.cjs");
7
5
  const require_templates_config_source = require("./templates/config.source.cjs");
8
6
  let node_path = require("node:path");
9
7
  node_path = require_chunk.__toESM(node_path);
8
+ let _kubb_ast = require("@kubb/ast");
9
+ let _kubb_plugin_ts = require("@kubb/plugin-ts");
10
+ let _kubb_react_fabric = require("@kubb/react-fabric");
11
+ let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
10
12
  let _kubb_core = require("@kubb/core");
11
- let _kubb_plugin_oas = require("@kubb/plugin-oas");
12
13
  let _kubb_plugin_zod = require("@kubb/plugin-zod");
14
+ //#region ../../internals/utils/src/casing.ts
15
+ /**
16
+ * Shared implementation for camelCase and PascalCase conversion.
17
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
18
+ * and capitalizes each word according to `pascal`.
19
+ *
20
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
21
+ */
22
+ function toCamelOrPascal(text, pascal) {
23
+ return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
24
+ if (word.length > 1 && word === word.toUpperCase()) return word;
25
+ if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
26
+ return word.charAt(0).toUpperCase() + word.slice(1);
27
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
28
+ }
29
+ /**
30
+ * Splits `text` on `.` and applies `transformPart` to each segment.
31
+ * The last segment receives `isLast = true`, all earlier segments receive `false`.
32
+ * Segments are joined with `/` to form a file path.
33
+ *
34
+ * Only splits on dots followed by a letter so that version numbers
35
+ * embedded in operationIds (e.g. `v2025.0`) are kept intact.
36
+ */
37
+ function applyToFileParts(text, transformPart) {
38
+ const parts = text.split(/\.(?=[a-zA-Z])/);
39
+ return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
40
+ }
41
+ /**
42
+ * Converts `text` to camelCase.
43
+ * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
44
+ *
45
+ * @example
46
+ * camelCase('hello-world') // 'helloWorld'
47
+ * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
48
+ */
49
+ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
50
+ if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
51
+ prefix,
52
+ suffix
53
+ } : {}));
54
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
55
+ }
56
+ /**
57
+ * Converts `text` to PascalCase.
58
+ * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
59
+ *
60
+ * @example
61
+ * pascalCase('hello-world') // 'HelloWorld'
62
+ * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
63
+ */
64
+ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
65
+ if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
66
+ prefix,
67
+ suffix
68
+ }) : camelCase(part));
69
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
70
+ }
71
+ //#endregion
72
+ //#region ../../internals/utils/src/jsdoc.ts
73
+ /**
74
+ * Builds a JSDoc comment block from an array of lines.
75
+ * Returns `fallback` when `comments` is empty so callers always get a usable string.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * buildJSDoc(['@type string', '@example hello'])
80
+ * // '/**\n * @type string\n * @example hello\n *\/\n '
81
+ * ```
82
+ */
83
+ function buildJSDoc(comments, options = {}) {
84
+ const { indent = " * ", suffix = "\n ", fallback = " " } = options;
85
+ if (comments.length === 0) return fallback;
86
+ return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
87
+ }
88
+ //#endregion
89
+ //#region ../../internals/utils/src/reserved.ts
90
+ /**
91
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * isValidVarName('status') // true
96
+ * isValidVarName('class') // false (reserved word)
97
+ * isValidVarName('42foo') // false (starts with digit)
98
+ * ```
99
+ */
100
+ function isValidVarName(name) {
101
+ try {
102
+ new Function(`var ${name}`);
103
+ } catch {
104
+ return false;
105
+ }
106
+ return true;
107
+ }
108
+ //#endregion
109
+ //#region ../../internals/utils/src/urlPath.ts
110
+ /**
111
+ * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
112
+ *
113
+ * @example
114
+ * const p = new URLPath('/pet/{petId}')
115
+ * p.URL // '/pet/:petId'
116
+ * p.template // '`/pet/${petId}`'
117
+ */
118
+ var URLPath = class {
119
+ /**
120
+ * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
121
+ */
122
+ path;
123
+ #options;
124
+ constructor(path, options = {}) {
125
+ this.path = path;
126
+ this.#options = options;
127
+ }
128
+ /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * new URLPath('/pet/{petId}').URL // '/pet/:petId'
133
+ * ```
134
+ */
135
+ get URL() {
136
+ return this.toURLPath();
137
+ }
138
+ /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
143
+ * new URLPath('/pet/{petId}').isURL // false
144
+ * ```
145
+ */
146
+ get isURL() {
147
+ try {
148
+ return !!new URL(this.path).href;
149
+ } catch {
150
+ return false;
151
+ }
152
+ }
153
+ /**
154
+ * Converts the OpenAPI path to a TypeScript template literal string.
155
+ *
156
+ * @example
157
+ * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
158
+ * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
159
+ */
160
+ get template() {
161
+ return this.toTemplateString();
162
+ }
163
+ /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * new URLPath('/pet/{petId}').object
168
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
169
+ * ```
170
+ */
171
+ get object() {
172
+ return this.toObject();
173
+ }
174
+ /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * new URLPath('/pet/{petId}').params // { petId: 'petId' }
179
+ * new URLPath('/pet').params // undefined
180
+ * ```
181
+ */
182
+ get params() {
183
+ return this.getParams();
184
+ }
185
+ #transformParam(raw) {
186
+ const param = isValidVarName(raw) ? raw : camelCase(raw);
187
+ return this.#options.casing === "camelcase" ? camelCase(param) : param;
188
+ }
189
+ /**
190
+ * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
191
+ */
192
+ #eachParam(fn) {
193
+ for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
194
+ const raw = match[1];
195
+ fn(raw, this.#transformParam(raw));
196
+ }
197
+ }
198
+ toObject({ type = "path", replacer, stringify } = {}) {
199
+ const object = {
200
+ url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
201
+ params: this.getParams()
202
+ };
203
+ if (stringify) {
204
+ if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
205
+ if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
206
+ return `{ url: '${object.url}' }`;
207
+ }
208
+ return object;
209
+ }
210
+ /**
211
+ * Converts the OpenAPI path to a TypeScript template literal string.
212
+ * An optional `replacer` can transform each extracted parameter name before interpolation.
213
+ *
214
+ * @example
215
+ * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
216
+ */
217
+ toTemplateString({ prefix = "", replacer } = {}) {
218
+ return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
219
+ if (i % 2 === 0) return part;
220
+ const param = this.#transformParam(part);
221
+ return `\${${replacer ? replacer(param) : param}}`;
222
+ }).join("")}\``;
223
+ }
224
+ /**
225
+ * Extracts all `{param}` segments from the path and returns them as a key-value map.
226
+ * An optional `replacer` transforms each parameter name in both key and value positions.
227
+ * Returns `undefined` when no path parameters are found.
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * new URLPath('/pet/{petId}/tag/{tagId}').getParams()
232
+ * // { petId: 'petId', tagId: 'tagId' }
233
+ * ```
234
+ */
235
+ getParams(replacer) {
236
+ const params = {};
237
+ this.#eachParam((_raw, param) => {
238
+ const key = replacer ? replacer(param) : param;
239
+ params[key] = key;
240
+ });
241
+ return Object.keys(params).length > 0 ? params : void 0;
242
+ }
243
+ /** Converts the OpenAPI path to Express-style colon syntax.
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
248
+ * ```
249
+ */
250
+ toURLPath() {
251
+ return this.path.replace(/\{([^}]+)\}/g, ":$1");
252
+ }
253
+ };
254
+ //#endregion
255
+ //#region src/utils.ts
256
+ function getComments(node) {
257
+ return [
258
+ node.description && `@description ${node.description}`,
259
+ node.summary && `@summary ${node.summary}`,
260
+ node.path && `{@link ${new URLPath(node.path).URL}}`,
261
+ node.deprecated && "@deprecated"
262
+ ].filter((x) => Boolean(x)).flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((x) => Boolean(x));
263
+ }
264
+ function buildParamsMapping(originalParams, casedParams) {
265
+ const mapping = {};
266
+ let hasChanged = false;
267
+ originalParams.forEach((param, i) => {
268
+ const casedName = casedParams[i]?.name ?? param.name;
269
+ mapping[param.name] = casedName;
270
+ if (param.name !== casedName) hasChanged = true;
271
+ });
272
+ return hasChanged ? mapping : void 0;
273
+ }
274
+ function buildHeaders(contentType, hasHeaderParams) {
275
+ return [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, hasHeaderParams ? "...headers" : void 0].filter(Boolean);
276
+ }
277
+ function buildGenerics(node, tsResolver) {
278
+ const responseName = tsResolver.resolveResponseName(node);
279
+ const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
280
+ const errorNames = node.responses.filter((r) => Number.parseInt(r.statusCode, 10) >= 400).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
281
+ return [
282
+ responseName,
283
+ `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
284
+ requestName || "unknown"
285
+ ].filter(Boolean);
286
+ }
287
+ function buildClassClientParams({ node, path, baseURL, tsResolver, isFormData, headers }) {
288
+ const queryParamsName = node.parameters.filter((p) => p.in === "query").length > 0 ? tsResolver.resolveQueryParamsName(node, node.parameters.filter((p) => p.in === "query")[0]) : void 0;
289
+ const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
290
+ return _kubb_react_fabric.FunctionParams.factory({ config: {
291
+ mode: "object",
292
+ children: {
293
+ requestConfig: { mode: "inlineSpread" },
294
+ method: { value: JSON.stringify(node.method.toUpperCase()) },
295
+ url: { value: path.template },
296
+ baseURL: baseURL ? { value: JSON.stringify(baseURL) } : void 0,
297
+ params: queryParamsName ? {} : void 0,
298
+ data: requestName ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
299
+ headers: headers.length ? { value: `{ ${headers.join(", ")}, ...requestConfig.headers }` } : void 0
300
+ }
301
+ } });
302
+ }
303
+ function buildRequestDataLine({ parser, node, zodResolver }) {
304
+ const zodRequestName = zodResolver && parser === "zod" && node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0;
305
+ if (parser === "zod" && zodRequestName) return `const requestData = ${zodRequestName}.parse(data)`;
306
+ if (node.requestBody?.schema) return "const requestData = data";
307
+ return "";
308
+ }
309
+ function buildFormDataLine(isFormData, hasRequest) {
310
+ return isFormData && hasRequest ? "const formData = buildFormData(requestData)" : "";
311
+ }
312
+ function buildReturnStatement({ dataReturnType, parser, node, zodResolver }) {
313
+ const zodResponseName = zodResolver && parser === "zod" ? zodResolver.resolveResponseName?.(node) : void 0;
314
+ if (dataReturnType === "full" && parser === "zod" && zodResponseName) return `return {...res, data: ${zodResponseName}.parse(res.data)}`;
315
+ if (dataReturnType === "data" && parser === "zod" && zodResponseName) return `return ${zodResponseName}.parse(res.data)`;
316
+ if (dataReturnType === "full" && parser === "client") return "return res";
317
+ return "return res.data";
318
+ }
319
+ //#endregion
320
+ //#region src/components/Url.tsx
321
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
322
+ function getParams$2({ paramsType, paramsCasing, pathParamsType, node, tsResolver }) {
323
+ return (0, _kubb_ast.createOperationParams)({
324
+ ...node,
325
+ parameters: node.parameters.filter((p) => p.in === "path"),
326
+ requestBody: void 0
327
+ }, {
328
+ paramsType: paramsType === "object" ? "object" : "inline",
329
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
330
+ paramsCasing,
331
+ resolver: tsResolver
332
+ });
333
+ }
334
+ require_chunk.__name(getParams$2, "getParams");
335
+ function Url({ name, isExportable = true, isIndexable = true, baseURL, paramsType, paramsCasing, pathParamsType, node, tsResolver }) {
336
+ const path = new URLPath(node.path);
337
+ const paramsNode = getParams$2({
338
+ paramsType,
339
+ paramsCasing,
340
+ pathParamsType,
341
+ node,
342
+ tsResolver
343
+ });
344
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
345
+ const originalPathParams = node.parameters.filter((p) => p.in === "path");
346
+ const casedPathParams = (0, _kubb_ast.caseParams)(originalPathParams, paramsCasing);
347
+ const pathParamsMapping = paramsCasing ? buildParamsMapping(originalPathParams, casedPathParams) : void 0;
348
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
349
+ name,
350
+ isExportable,
351
+ isIndexable,
352
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
353
+ name,
354
+ export: isExportable,
355
+ params: paramsSignature,
356
+ children: [
357
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => isValidVarName(originalName) && originalName !== camelCaseName).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
358
+ pathParamsMapping && Object.keys(pathParamsMapping).length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
359
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
360
+ name: "res",
361
+ children: `{ method: '${node.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`
362
+ }),
363
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
364
+ "return res"
365
+ ]
366
+ })
367
+ });
368
+ }
369
+ Url.getParams = getParams$2;
370
+ //#endregion
371
+ //#region src/components/Client.tsx
372
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
373
+ function getParams$1({ paramsType, paramsCasing, pathParamsType, node, tsResolver, isConfigurable }) {
374
+ const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
375
+ return (0, _kubb_ast.createOperationParams)(node, {
376
+ paramsType,
377
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
378
+ paramsCasing,
379
+ resolver: tsResolver,
380
+ extraParams: isConfigurable ? [(0, _kubb_ast.createFunctionParameter)({
381
+ name: "config",
382
+ type: (0, _kubb_ast.createTypeNode)({
383
+ variant: "reference",
384
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
385
+ }),
386
+ default: "{}"
387
+ })] : []
388
+ });
389
+ }
390
+ require_chunk.__name(getParams$1, "getParams");
391
+ function Client({ name, isExportable = true, isIndexable = true, returnType, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, node, tsResolver, zodResolver, urlName, children, isConfigurable = true }) {
392
+ const path = new URLPath(node.path);
393
+ const contentType = node.requestBody?.contentType ?? "application/json";
394
+ const isFormData = contentType === "multipart/form-data";
395
+ const originalPathParams = node.parameters.filter((p) => p.in === "path");
396
+ const casedPathParams = (0, _kubb_ast.caseParams)(originalPathParams, paramsCasing);
397
+ const originalQueryParams = node.parameters.filter((p) => p.in === "query");
398
+ const casedQueryParams = (0, _kubb_ast.caseParams)(originalQueryParams, paramsCasing);
399
+ const originalHeaderParams = node.parameters.filter((p) => p.in === "header");
400
+ const casedHeaderParams = (0, _kubb_ast.caseParams)(originalHeaderParams, paramsCasing);
401
+ const pathParamsMapping = paramsCasing && !urlName ? buildParamsMapping(originalPathParams, casedPathParams) : void 0;
402
+ const queryParamsMapping = paramsCasing ? buildParamsMapping(originalQueryParams, casedQueryParams) : void 0;
403
+ const headerParamsMapping = paramsCasing ? buildParamsMapping(originalHeaderParams, casedHeaderParams) : void 0;
404
+ const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
405
+ const responseName = tsResolver.resolveResponseName(node);
406
+ const queryParamsName = originalQueryParams.length > 0 ? tsResolver.resolveQueryParamsName(node, originalQueryParams[0]) : void 0;
407
+ const headerParamsName = originalHeaderParams.length > 0 ? tsResolver.resolveHeaderParamsName(node, originalHeaderParams[0]) : void 0;
408
+ const zodResponseName = zodResolver && parser === "zod" ? zodResolver.resolveResponseName?.(node) : void 0;
409
+ const zodRequestName = zodResolver && parser === "zod" && node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0;
410
+ const errorNames = node.responses.filter((r) => {
411
+ return Number.parseInt(r.statusCode, 10) >= 400;
412
+ }).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
413
+ const headers = [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, headerParamsName ? headerParamsMapping ? "...mappedHeaders" : "...headers" : void 0].filter(Boolean);
414
+ const generics = [
415
+ responseName,
416
+ `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
417
+ requestName || "unknown"
418
+ ].filter(Boolean);
419
+ const paramsNode = getParams$1({
420
+ paramsType,
421
+ paramsCasing,
422
+ pathParamsType,
423
+ node,
424
+ tsResolver,
425
+ isConfigurable
426
+ });
427
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
428
+ const urlParamsNode = Url.getParams({
429
+ paramsType,
430
+ paramsCasing,
431
+ pathParamsType,
432
+ node,
433
+ tsResolver
434
+ });
435
+ const urlParamsCall = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" }).print(urlParamsNode) ?? "";
436
+ const clientParams = _kubb_react_fabric.FunctionParams.factory({ config: {
437
+ mode: "object",
438
+ children: {
439
+ method: { value: JSON.stringify(node.method.toUpperCase()) },
440
+ url: { value: urlName ? `${urlName}(${urlParamsCall}).url.toString()` : path.template },
441
+ baseURL: baseURL && !urlName ? { value: `\`${baseURL}\`` } : void 0,
442
+ params: queryParamsName ? queryParamsMapping ? { value: "mappedParams" } : {} : void 0,
443
+ data: requestName ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
444
+ requestConfig: isConfigurable ? { mode: "inlineSpread" } : void 0,
445
+ headers: headers.length ? { value: isConfigurable ? `{ ${headers.join(", ")}, ...requestConfig.headers }` : `{ ${headers.join(", ")} }` } : void 0
446
+ }
447
+ } });
448
+ const childrenElement = children ? children : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
449
+ dataReturnType === "full" && parser === "zod" && zodResponseName && `return {...res, data: ${zodResponseName}.parse(res.data)}`,
450
+ dataReturnType === "data" && parser === "zod" && zodResponseName && `return ${zodResponseName}.parse(res.data)`,
451
+ dataReturnType === "full" && parser === "client" && "return res",
452
+ dataReturnType === "data" && parser === "client" && "return res.data"
453
+ ] });
454
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
455
+ name,
456
+ isExportable,
457
+ isIndexable,
458
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
459
+ name,
460
+ async: true,
461
+ export: isExportable,
462
+ params: paramsSignature,
463
+ JSDoc: { comments: getComments(node) },
464
+ returnType,
465
+ children: [
466
+ isConfigurable ? "const { client: request = fetch, ...requestConfig } = config" : "",
467
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
468
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
469
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => isValidVarName(originalName) && originalName !== camelCaseName).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
470
+ pathParamsMapping && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})] }),
471
+ queryParamsMapping && queryParamsName && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
472
+ `const mappedParams = params ? { ${Object.entries(queryParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": params.${camelCaseName}`).join(", ")} } : undefined`,
473
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
474
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
475
+ ] }),
476
+ headerParamsMapping && headerParamsName && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
477
+ `const mappedHeaders = headers ? { ${Object.entries(headerParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": headers.${camelCaseName}`).join(", ")} } : undefined`,
478
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
479
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
480
+ ] }),
481
+ parser === "zod" && zodRequestName ? `const requestData = ${zodRequestName}.parse(data)` : requestName && "const requestData = data",
482
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
483
+ isFormData && requestName && "const formData = buildFormData(requestData)",
484
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
485
+ isConfigurable ? `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})` : `const res = await fetch<${generics.join(", ")}>(${clientParams.toCall()})`,
486
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
487
+ childrenElement
488
+ ]
489
+ })
490
+ })] });
491
+ }
492
+ Client.getParams = getParams$1;
493
+ //#endregion
494
+ //#region src/components/ClientLegacy.tsx
495
+ function isSchemaRequired(schema) {
496
+ if (!schema) return false;
497
+ return Array.isArray(schema.required) ? !!schema.required.length : !!schema.required;
498
+ }
499
+ function isSchemaOptional(schema) {
500
+ return !isSchemaRequired(schema);
501
+ }
502
+ function isAllOptionalDeep(schema) {
503
+ if (!schema) return true;
504
+ if (Array.isArray(schema.required) && schema.required.length > 0) return false;
505
+ if (schema.allOf) return schema.allOf.every(isAllOptionalDeep);
506
+ return true;
507
+ }
508
+ function getSchemaDefaultValue(schema) {
509
+ if (!schema || !isSchemaOptional(schema)) return void 0;
510
+ if (schema.type === "array") return "[]";
511
+ if (schema.anyOf || schema.oneOf) {
512
+ const variants = schema.anyOf || schema.oneOf;
513
+ if (!Array.isArray(variants)) return void 0;
514
+ if (variants.some(isAllOptionalDeep)) return "{}";
515
+ return;
516
+ }
517
+ if (schema.type === "object" || schema.properties) return "{}";
518
+ }
519
+ function legacyGetPathParams(operationSchema, options = {}) {
520
+ if (!operationSchema?.schema?.properties || !operationSchema.name) return {};
521
+ const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : [];
522
+ return Object.entries(operationSchema.schema.properties).reduce((acc, [name]) => {
523
+ if (!name) return acc;
524
+ let paramName = name;
525
+ if (options.casing === "camelcase") paramName = camelCase(name);
526
+ else if (!isValidVarName(name)) paramName = camelCase(name);
527
+ const accessName = options.casing === "camelcase" ? camelCase(name) : name;
528
+ acc[paramName] = {
529
+ default: void 0,
530
+ type: options.typed ? `${operationSchema.name}["${accessName}"]` : void 0,
531
+ optional: !requiredFields.includes(name)
532
+ };
533
+ return acc;
534
+ }, {});
535
+ }
536
+ function legacyGetParamsMapping(operationSchema, options = {}) {
537
+ if (!operationSchema?.schema?.properties) return void 0;
538
+ const allEntries = [];
539
+ let hasTransformation = false;
540
+ Object.entries(operationSchema.schema.properties).forEach(([originalName]) => {
541
+ let transformedName = originalName;
542
+ if (options.casing === "camelcase") transformedName = camelCase(originalName);
543
+ else if (!isValidVarName(originalName)) transformedName = camelCase(originalName);
544
+ allEntries.push([originalName, transformedName]);
545
+ if (transformedName !== originalName) hasTransformation = true;
546
+ });
547
+ if (options.casing === "camelcase" && hasTransformation) return Object.fromEntries(allEntries);
548
+ const mapping = {};
549
+ allEntries.forEach(([originalName, transformedName]) => {
550
+ if (transformedName !== originalName) mapping[originalName] = transformedName;
551
+ });
552
+ return Object.keys(mapping).length > 0 ? mapping : void 0;
553
+ }
554
+ function legacyGetComments(operation) {
555
+ return [
556
+ operation.getDescription?.() && `@description ${operation.getDescription()}`,
557
+ operation.getSummary?.() && `@summary ${operation.getSummary()}`,
558
+ operation.path && `{@link ${new URLPath(operation.path).URL}}`,
559
+ operation.isDeprecated?.() && "@deprecated"
560
+ ].filter((x) => Boolean(x)).flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((x) => Boolean(x));
561
+ }
562
+ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable }) {
563
+ if (paramsType === "object") {
564
+ const children = {
565
+ ...legacyGetPathParams(typeSchemas.pathParams, {
566
+ typed: true,
567
+ casing: paramsCasing
568
+ }),
569
+ data: typeSchemas.request?.name ? {
570
+ type: typeSchemas.request?.name,
571
+ optional: isSchemaOptional(typeSchemas.request?.schema)
572
+ } : void 0,
573
+ params: typeSchemas.queryParams?.name ? {
574
+ type: typeSchemas.queryParams?.name,
575
+ optional: isSchemaOptional(typeSchemas.queryParams?.schema)
576
+ } : void 0,
577
+ headers: typeSchemas.headerParams?.name ? {
578
+ type: typeSchemas.headerParams?.name,
579
+ optional: isSchemaOptional(typeSchemas.headerParams?.schema)
580
+ } : void 0
581
+ };
582
+ const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
583
+ return _kubb_react_fabric.FunctionParams.factory({
584
+ data: {
585
+ mode: "object",
586
+ children,
587
+ default: allChildrenAreOptional ? "{}" : void 0
588
+ },
589
+ config: isConfigurable ? {
590
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
591
+ default: "{}"
592
+ } : void 0
593
+ });
594
+ }
595
+ return _kubb_react_fabric.FunctionParams.factory({
596
+ pathParams: typeSchemas.pathParams?.name ? {
597
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
598
+ children: legacyGetPathParams(typeSchemas.pathParams, {
599
+ typed: true,
600
+ casing: paramsCasing
601
+ }),
602
+ default: getSchemaDefaultValue(typeSchemas.pathParams?.schema)
603
+ } : void 0,
604
+ data: typeSchemas.request?.name ? {
605
+ type: typeSchemas.request?.name,
606
+ optional: isSchemaOptional(typeSchemas.request?.schema)
607
+ } : void 0,
608
+ params: typeSchemas.queryParams?.name ? {
609
+ type: typeSchemas.queryParams?.name,
610
+ optional: isSchemaOptional(typeSchemas.queryParams?.schema)
611
+ } : void 0,
612
+ headers: typeSchemas.headerParams?.name ? {
613
+ type: typeSchemas.headerParams?.name,
614
+ optional: isSchemaOptional(typeSchemas.headerParams?.schema)
615
+ } : void 0,
616
+ config: isConfigurable ? {
617
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
618
+ default: "{}"
619
+ } : void 0
620
+ });
621
+ }
622
+ function ClientLegacy({ name, isExportable = true, isIndexable = true, returnType, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, urlName, children, isConfigurable = true }) {
623
+ const path = new URLPath(operation.path);
624
+ const contentType = operation.getContentType?.() ?? "application/json";
625
+ const isFormData = contentType === "multipart/form-data";
626
+ const pathParamsMapping = paramsCasing && !urlName ? legacyGetParamsMapping(typeSchemas.pathParams, { casing: paramsCasing }) : void 0;
627
+ const queryParamsMapping = paramsCasing ? legacyGetParamsMapping(typeSchemas.queryParams, { casing: paramsCasing }) : void 0;
628
+ const headerParamsMapping = paramsCasing ? legacyGetParamsMapping(typeSchemas.headerParams, { casing: paramsCasing }) : void 0;
629
+ const headers = [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, typeSchemas.headerParams?.name ? headerParamsMapping ? "...mappedHeaders" : "...headers" : void 0].filter(Boolean);
630
+ const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
631
+ const generics = [
632
+ typeSchemas.response.name,
633
+ TError,
634
+ typeSchemas.request?.name || "unknown"
635
+ ].filter(Boolean);
636
+ const params = getParams({
637
+ paramsType,
638
+ paramsCasing,
639
+ pathParamsType,
640
+ typeSchemas,
641
+ isConfigurable
642
+ });
643
+ const urlParams = UrlLegacy.getParams({
644
+ paramsType,
645
+ paramsCasing,
646
+ pathParamsType,
647
+ typeSchemas
648
+ });
649
+ const clientParams = _kubb_react_fabric.FunctionParams.factory({ config: {
650
+ mode: "object",
651
+ children: {
652
+ method: { value: JSON.stringify(operation.method.toUpperCase()) },
653
+ url: { value: urlName ? `${urlName}(${urlParams.toCall()}).url.toString()` : path.template },
654
+ baseURL: baseURL && !urlName ? { value: `\`${baseURL}\`` } : void 0,
655
+ params: typeSchemas.queryParams?.name ? queryParamsMapping ? { value: "mappedParams" } : {} : void 0,
656
+ data: typeSchemas.request?.name ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
657
+ requestConfig: isConfigurable ? { mode: "inlineSpread" } : void 0,
658
+ headers: headers.length ? { value: isConfigurable ? `{ ${headers.join(", ")}, ...requestConfig.headers }` : `{ ${headers.join(", ")} }` } : void 0
659
+ }
660
+ } });
661
+ const childrenElement = children ? children : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
662
+ dataReturnType === "full" && parser === "zod" && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`,
663
+ dataReturnType === "data" && parser === "zod" && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`,
664
+ dataReturnType === "full" && parser === "client" && "return res",
665
+ dataReturnType === "data" && parser === "client" && "return res.data"
666
+ ] });
667
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
668
+ name,
669
+ isExportable,
670
+ isIndexable,
671
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
672
+ name,
673
+ async: true,
674
+ export: isExportable,
675
+ params: params.toConstructor(),
676
+ JSDoc: { comments: legacyGetComments(operation) },
677
+ returnType,
678
+ children: [
679
+ isConfigurable ? "const { client: request = fetch, ...requestConfig } = config" : "",
680
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
681
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
682
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => originalName !== camelCaseName && isValidVarName(originalName)).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
683
+ pathParamsMapping && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})] }),
684
+ queryParamsMapping && typeSchemas.queryParams?.name && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
685
+ `const mappedParams = params ? { ${Object.entries(queryParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": params.${camelCaseName}`).join(", ")} } : undefined`,
686
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
687
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
688
+ ] }),
689
+ headerParamsMapping && typeSchemas.headerParams?.name && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
690
+ `const mappedHeaders = headers ? { ${Object.entries(headerParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": headers.${camelCaseName}`).join(", ")} } : undefined`,
691
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
692
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
693
+ ] }),
694
+ parser === "zod" && zodSchemas?.request?.name ? `const requestData = ${zodSchemas.request.name}.parse(data)` : typeSchemas?.request?.name && "const requestData = data",
695
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
696
+ isFormData && typeSchemas?.request?.name && "const formData = buildFormData(requestData)",
697
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
698
+ isConfigurable ? `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})` : `const res = await fetch<${generics.join(", ")}>(${clientParams.toCall()})`,
699
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
700
+ childrenElement
701
+ ]
702
+ })
703
+ })] });
704
+ }
705
+ ClientLegacy.getParams = getParams;
706
+ function getUrlParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
707
+ if (paramsType === "object") {
708
+ const pathParams = legacyGetPathParams(typeSchemas.pathParams, {
709
+ typed: true,
710
+ casing: paramsCasing
711
+ });
712
+ return _kubb_react_fabric.FunctionParams.factory({ data: {
713
+ mode: "object",
714
+ children: { ...pathParams }
715
+ } });
716
+ }
717
+ return _kubb_react_fabric.FunctionParams.factory({ pathParams: typeSchemas.pathParams?.name ? {
718
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
719
+ children: legacyGetPathParams(typeSchemas.pathParams, {
720
+ typed: true,
721
+ casing: paramsCasing
722
+ }),
723
+ default: getSchemaDefaultValue(typeSchemas.pathParams?.schema)
724
+ } : void 0 });
725
+ }
726
+ function UrlLegacy({ name, isExportable = true, isIndexable = true, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }) {
727
+ const path = new URLPath(operation.path);
728
+ const params = getUrlParams({
729
+ paramsType,
730
+ paramsCasing,
731
+ pathParamsType,
732
+ typeSchemas
733
+ });
734
+ const pathParamsMapping = paramsCasing ? legacyGetParamsMapping(typeSchemas.pathParams, { casing: paramsCasing }) : void 0;
735
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
736
+ name,
737
+ isExportable,
738
+ isIndexable,
739
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
740
+ name,
741
+ export: isExportable,
742
+ params: params.toConstructor(),
743
+ children: [
744
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => originalName !== camelCaseName && isValidVarName(originalName)).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
745
+ pathParamsMapping && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
746
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
747
+ name: "res",
748
+ children: `{ method: '${operation.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`
749
+ }),
750
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
751
+ "return res"
752
+ ]
753
+ })
754
+ });
755
+ }
756
+ UrlLegacy.getParams = getUrlParams;
757
+ //#endregion
758
+ //#region src/components/ClassClient.tsx
759
+ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
760
+ function generateMethod$1({ node, name, tsResolver, zodResolver, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
761
+ const path = new URLPath(node.path, { casing: paramsCasing });
762
+ const contentType = node.requestBody?.contentType ?? "application/json";
763
+ const isFormData = contentType === "multipart/form-data";
764
+ const headers = buildHeaders(contentType, !!(node.parameters.filter((p) => p.in === "header").length > 0 ? tsResolver.resolveHeaderParamsName(node, node.parameters.filter((p) => p.in === "header")[0]) : void 0));
765
+ const generics = buildGenerics(node, tsResolver);
766
+ const paramsNode = ClassClient.getParams({
767
+ paramsType,
768
+ paramsCasing,
769
+ pathParamsType,
770
+ node,
771
+ tsResolver,
772
+ isConfigurable: true
773
+ });
774
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
775
+ const clientParams = buildClassClientParams({
776
+ node,
777
+ path,
778
+ baseURL,
779
+ tsResolver,
780
+ isFormData,
781
+ headers
782
+ });
783
+ const jsdoc = buildJSDoc(getComments(node));
784
+ const requestDataLine = buildRequestDataLine({
785
+ parser,
786
+ node,
787
+ zodResolver
788
+ });
789
+ const formDataLine = buildFormDataLine(isFormData, !!node.requestBody?.schema);
790
+ const returnStatement = buildReturnStatement({
791
+ dataReturnType,
792
+ parser,
793
+ node,
794
+ zodResolver
795
+ });
796
+ return `${jsdoc}async ${name}(${paramsSignature}) {\n${[
797
+ "const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)",
798
+ "",
799
+ requestDataLine,
800
+ formDataLine,
801
+ `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
802
+ returnStatement
803
+ ].filter(Boolean).map((line) => ` ${line}`).join("\n")}\n }`;
804
+ }
805
+ require_chunk.__name(generateMethod$1, "generateMethod");
806
+ function ClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
807
+ const classCode = `export class ${name} {
808
+ #config: Partial<RequestConfig> & { client?: Client }
809
+
810
+ constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
811
+ this.#config = config
812
+ }
813
+
814
+ ${operations.map(({ node, name: methodName, tsResolver, zodResolver }) => generateMethod$1({
815
+ node,
816
+ name: methodName,
817
+ tsResolver,
818
+ zodResolver,
819
+ baseURL,
820
+ dataReturnType,
821
+ parser,
822
+ paramsType,
823
+ paramsCasing,
824
+ pathParamsType
825
+ })).join("\n\n")}
826
+ }`;
827
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File.Source, {
828
+ name,
829
+ isExportable,
830
+ isIndexable,
831
+ children: [classCode, children]
832
+ });
833
+ }
834
+ ClassClient.getParams = Client.getParams;
835
+ //#endregion
836
+ //#region src/components/WrapperClient.tsx
837
+ function WrapperClient({ name, classNames, isExportable = true, isIndexable = true }) {
838
+ const classCode = `export class ${name} {
839
+ ${classNames.map((className) => ` readonly ${camelCase(className)}: ${className}`).join("\n")}
840
+
841
+ constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
842
+ ${classNames.map((className) => ` this.${camelCase(className)} = new ${className}(config)`).join("\n")}
843
+ }
844
+ }`;
845
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
846
+ name,
847
+ isExportable,
848
+ isIndexable,
849
+ children: classCode
850
+ });
851
+ }
852
+ //#endregion
853
+ //#region src/generators/classClientGenerator.tsx
854
+ function resolveTypeImportNames$1(node, tsResolver) {
855
+ return [
856
+ node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0,
857
+ tsResolver.resolveResponseName(node),
858
+ ...node.parameters.filter((p) => p.in === "path").map((p) => tsResolver.resolvePathParamsName(node, p)),
859
+ ...node.parameters.filter((p) => p.in === "query").map((p) => tsResolver.resolveQueryParamsName(node, p)),
860
+ ...node.parameters.filter((p) => p.in === "header").map((p) => tsResolver.resolveHeaderParamsName(node, p)),
861
+ ...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
862
+ ].filter((n) => Boolean(n));
863
+ }
864
+ require_chunk.__name(resolveTypeImportNames$1, "resolveTypeImportNames");
865
+ function resolveZodImportNames$1(node, zodResolver) {
866
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
867
+ }
868
+ require_chunk.__name(resolveZodImportNames$1, "resolveZodImportNames");
869
+ const classClientGenerator = (0, _kubb_core.defineGenerator)({
870
+ name: "classClient",
871
+ operations(nodes, options) {
872
+ const { adapter, config, driver, resolver, root } = this;
873
+ const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, wrapper } = options;
874
+ const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL;
875
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
876
+ if (!pluginTs?.resolver) return null;
877
+ const tsResolver = pluginTs.resolver;
878
+ const tsPluginOptions = pluginTs.options;
879
+ const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
880
+ const zodResolver = pluginZod?.resolver;
881
+ function buildOperationData(node) {
882
+ const typeFile = tsResolver.resolveFile({
883
+ name: node.operationId,
884
+ extname: ".ts",
885
+ tag: node.tags[0] ?? "default",
886
+ path: node.path
887
+ }, {
888
+ root,
889
+ output: tsPluginOptions?.output ?? output,
890
+ group: tsPluginOptions?.group
891
+ });
892
+ const zodFile = zodResolver && pluginZod?.options ? zodResolver.resolveFile({
893
+ name: node.operationId,
894
+ extname: ".ts",
895
+ tag: node.tags[0] ?? "default",
896
+ path: node.path
897
+ }, {
898
+ root,
899
+ output: pluginZod.options.output ?? output,
900
+ group: pluginZod.options.group
901
+ }) : void 0;
902
+ return {
903
+ node,
904
+ name: resolver.resolveName(node.operationId),
905
+ tsResolver,
906
+ zodResolver,
907
+ typeFile,
908
+ zodFile
909
+ };
910
+ }
911
+ const controllers = nodes.reduce((acc, operationNode) => {
912
+ const tag = operationNode.tags[0];
913
+ const groupName = tag ? group?.name?.({ group: camelCase(tag) }) ?? pascalCase(tag) : "Client";
914
+ if (!tag && !group) {
915
+ const name = "ApiClient";
916
+ const file = resolver.resolveFile({
917
+ name,
918
+ extname: ".ts"
919
+ }, {
920
+ root,
921
+ output,
922
+ group
923
+ });
924
+ const operationData = buildOperationData(operationNode);
925
+ const previous = acc.find((item) => item.file.path === file.path);
926
+ if (previous) previous.operations.push(operationData);
927
+ else acc.push({
928
+ name,
929
+ file,
930
+ operations: [operationData]
931
+ });
932
+ } else if (tag) {
933
+ const name = groupName;
934
+ const file = resolver.resolveFile({
935
+ name,
936
+ extname: ".ts",
937
+ tag
938
+ }, {
939
+ root,
940
+ output,
941
+ group
942
+ });
943
+ const operationData = buildOperationData(operationNode);
944
+ const previous = acc.find((item) => item.file.path === file.path);
945
+ if (previous) previous.operations.push(operationData);
946
+ else acc.push({
947
+ name,
948
+ file,
949
+ operations: [operationData]
950
+ });
951
+ }
952
+ return acc;
953
+ }, []);
954
+ function collectTypeImports(ops) {
955
+ const typeImportsByFile = /* @__PURE__ */ new Map();
956
+ const typeFilesByPath = /* @__PURE__ */ new Map();
957
+ ops.forEach((op) => {
958
+ const names = resolveTypeImportNames$1(op.node, tsResolver);
959
+ if (!typeImportsByFile.has(op.typeFile.path)) typeImportsByFile.set(op.typeFile.path, /* @__PURE__ */ new Set());
960
+ const imports = typeImportsByFile.get(op.typeFile.path);
961
+ names.forEach((n) => {
962
+ imports.add(n);
963
+ });
964
+ typeFilesByPath.set(op.typeFile.path, op.typeFile);
965
+ });
966
+ return {
967
+ typeImportsByFile,
968
+ typeFilesByPath
969
+ };
970
+ }
971
+ function collectZodImports(ops) {
972
+ const zodImportsByFile = /* @__PURE__ */ new Map();
973
+ const zodFilesByPath = /* @__PURE__ */ new Map();
974
+ ops.forEach((op) => {
975
+ if (!op.zodFile || !zodResolver) return;
976
+ const names = resolveZodImportNames$1(op.node, zodResolver);
977
+ if (!zodImportsByFile.has(op.zodFile.path)) zodImportsByFile.set(op.zodFile.path, /* @__PURE__ */ new Set());
978
+ const imports = zodImportsByFile.get(op.zodFile.path);
979
+ names.forEach((n) => {
980
+ imports.add(n);
981
+ });
982
+ zodFilesByPath.set(op.zodFile.path, op.zodFile);
983
+ });
984
+ return {
985
+ zodImportsByFile,
986
+ zodFilesByPath
987
+ };
988
+ }
989
+ const files = controllers.map(({ name, file, operations: ops }) => {
990
+ const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
991
+ const { zodImportsByFile, zodFilesByPath } = parser === "zod" ? collectZodImports(ops) : {
992
+ zodImportsByFile: /* @__PURE__ */ new Map(),
993
+ zodFilesByPath: /* @__PURE__ */ new Map()
994
+ };
995
+ const hasFormData = ops.some((op) => op.node.requestBody?.contentType === "multipart/form-data");
996
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
997
+ baseName: file.baseName,
998
+ path: file.path,
999
+ meta: file.meta,
1000
+ banner: resolver.resolveBanner(adapter.rootNode, {
1001
+ output,
1002
+ config
1003
+ }),
1004
+ footer: resolver.resolveFooter(adapter.rootNode, {
1005
+ output,
1006
+ config
1007
+ }),
1008
+ children: [
1009
+ importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
1010
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1011
+ name: "fetch",
1012
+ path: importPath
1013
+ }),
1014
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1015
+ name: ["mergeConfig"],
1016
+ path: importPath
1017
+ }),
1018
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1019
+ name: [
1020
+ "Client",
1021
+ "RequestConfig",
1022
+ "ResponseErrorConfig"
1023
+ ],
1024
+ path: importPath,
1025
+ isTypeOnly: true
1026
+ })
1027
+ ] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
1028
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1029
+ name: ["fetch"],
1030
+ root: file.path,
1031
+ path: node_path.default.resolve(root, ".kubb/fetch.ts")
1032
+ }),
1033
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1034
+ name: ["mergeConfig"],
1035
+ root: file.path,
1036
+ path: node_path.default.resolve(root, ".kubb/fetch.ts")
1037
+ }),
1038
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1039
+ name: [
1040
+ "Client",
1041
+ "RequestConfig",
1042
+ "ResponseErrorConfig"
1043
+ ],
1044
+ root: file.path,
1045
+ path: node_path.default.resolve(root, ".kubb/fetch.ts"),
1046
+ isTypeOnly: true
1047
+ })
1048
+ ] }),
1049
+ hasFormData && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1050
+ name: ["buildFormData"],
1051
+ root: file.path,
1052
+ path: node_path.default.resolve(root, ".kubb/config.ts")
1053
+ }),
1054
+ Array.from(typeImportsByFile.entries()).map(([filePath, importSet]) => {
1055
+ const typeFile = typeFilesByPath.get(filePath);
1056
+ if (!typeFile) return null;
1057
+ const importNames = Array.from(importSet).filter(Boolean);
1058
+ if (importNames.length === 0) return null;
1059
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1060
+ name: importNames,
1061
+ root: file.path,
1062
+ path: typeFile.path,
1063
+ isTypeOnly: true
1064
+ }, filePath);
1065
+ }),
1066
+ parser === "zod" && Array.from(zodImportsByFile.entries()).map(([filePath, importSet]) => {
1067
+ const zodFile = zodFilesByPath.get(filePath);
1068
+ if (!zodFile) return null;
1069
+ const importNames = Array.from(importSet).filter(Boolean);
1070
+ if (importNames.length === 0) return null;
1071
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1072
+ name: importNames,
1073
+ root: file.path,
1074
+ path: zodFile.path
1075
+ }, filePath);
1076
+ }),
1077
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(ClassClient, {
1078
+ name,
1079
+ operations: ops,
1080
+ baseURL,
1081
+ dataReturnType,
1082
+ pathParamsType,
1083
+ paramsCasing,
1084
+ paramsType,
1085
+ parser
1086
+ })
1087
+ ]
1088
+ }, file.path);
1089
+ });
1090
+ if (wrapper) {
1091
+ const wrapperFile = resolver.resolveFile({
1092
+ name: wrapper.className,
1093
+ extname: ".ts"
1094
+ }, {
1095
+ root,
1096
+ output,
1097
+ group
1098
+ });
1099
+ files.push(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1100
+ baseName: wrapperFile.baseName,
1101
+ path: wrapperFile.path,
1102
+ meta: wrapperFile.meta,
1103
+ banner: resolver.resolveBanner(adapter.rootNode, {
1104
+ output,
1105
+ config
1106
+ }),
1107
+ footer: resolver.resolveFooter(adapter.rootNode, {
1108
+ output,
1109
+ config
1110
+ }),
1111
+ children: [
1112
+ importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1113
+ name: ["Client", "RequestConfig"],
1114
+ path: importPath,
1115
+ isTypeOnly: true
1116
+ }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1117
+ name: ["Client", "RequestConfig"],
1118
+ root: wrapperFile.path,
1119
+ path: node_path.default.resolve(root, ".kubb/fetch.ts"),
1120
+ isTypeOnly: true
1121
+ }),
1122
+ controllers.map(({ name, file }) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1123
+ name: [name],
1124
+ root: wrapperFile.path,
1125
+ path: file.path
1126
+ }, name)),
1127
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(WrapperClient, {
1128
+ name: wrapper.className,
1129
+ classNames: controllers.map(({ name }) => name)
1130
+ })
1131
+ ]
1132
+ }, wrapperFile.path));
1133
+ }
1134
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric_jsx_runtime.Fragment, { children: files });
1135
+ }
1136
+ });
1137
+ //#endregion
1138
+ //#region src/generators/clientGenerator.tsx
1139
+ const clientGenerator = (0, _kubb_core.defineGenerator)({
1140
+ name: "client",
1141
+ operation(node, options) {
1142
+ const { adapter, config, driver, resolver, root } = this;
1143
+ const { output, urlType, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, group } = options;
1144
+ const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL;
1145
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1146
+ if (!pluginTs?.resolver) return null;
1147
+ const tsResolver = pluginTs.resolver;
1148
+ const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
1149
+ const zodResolver = pluginZod?.resolver;
1150
+ const casedParams = (0, _kubb_ast.caseParams)(node.parameters, paramsCasing);
1151
+ const pathParams = casedParams.filter((p) => p.in === "path");
1152
+ const queryParams = casedParams.filter((p) => p.in === "query");
1153
+ const headerParams = casedParams.filter((p) => p.in === "header");
1154
+ const importedTypeNames = [
1155
+ ...pathParams.map((p) => tsResolver.resolvePathParamsName(node, p)),
1156
+ ...queryParams.map((p) => tsResolver.resolveQueryParamsName(node, p)),
1157
+ ...headerParams.map((p) => tsResolver.resolveHeaderParamsName(node, p)),
1158
+ node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0,
1159
+ tsResolver.resolveResponseName(node),
1160
+ ...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
1161
+ ].filter(Boolean);
1162
+ const importedZodNames = zodResolver && parser === "zod" ? [zodResolver.resolveResponseName?.(node), node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter(Boolean) : [];
1163
+ const meta = {
1164
+ name: resolver.resolveName(node.operationId),
1165
+ urlName: `get${resolver.resolveName(node.operationId).charAt(0).toUpperCase()}${resolver.resolveName(node.operationId).slice(1)}Url`,
1166
+ file: resolver.resolveFile({
1167
+ name: node.operationId,
1168
+ extname: ".ts",
1169
+ tag: node.tags[0] ?? "default",
1170
+ path: node.path
1171
+ }, {
1172
+ root,
1173
+ output,
1174
+ group
1175
+ }),
1176
+ fileTs: tsResolver.resolveFile({
1177
+ name: node.operationId,
1178
+ extname: ".ts",
1179
+ tag: node.tags[0] ?? "default",
1180
+ path: node.path
1181
+ }, {
1182
+ root,
1183
+ output: pluginTs.options?.output ?? output,
1184
+ group: pluginTs.options?.group
1185
+ }),
1186
+ fileZod: zodResolver && pluginZod?.options ? zodResolver.resolveFile({
1187
+ name: node.operationId,
1188
+ extname: ".ts",
1189
+ tag: node.tags[0] ?? "default",
1190
+ path: node.path
1191
+ }, {
1192
+ root,
1193
+ output: pluginZod.options.output ?? output,
1194
+ group: pluginZod.options.group
1195
+ }) : void 0
1196
+ };
1197
+ const isFormData = node.requestBody?.contentType === "multipart/form-data";
1198
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1199
+ baseName: meta.file.baseName,
1200
+ path: meta.file.path,
1201
+ meta: meta.file.meta,
1202
+ banner: resolver.resolveBanner(adapter.rootNode, {
1203
+ output,
1204
+ config
1205
+ }),
1206
+ footer: resolver.resolveFooter(adapter.rootNode, {
1207
+ output,
1208
+ config
1209
+ }),
1210
+ children: [
1211
+ importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1212
+ name: "fetch",
1213
+ path: importPath
1214
+ }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1215
+ name: [
1216
+ "Client",
1217
+ "RequestConfig",
1218
+ "ResponseErrorConfig"
1219
+ ],
1220
+ path: importPath,
1221
+ isTypeOnly: true
1222
+ })] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1223
+ name: ["fetch"],
1224
+ root: meta.file.path,
1225
+ path: node_path.default.resolve(root, ".kubb/fetch.ts")
1226
+ }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1227
+ name: [
1228
+ "Client",
1229
+ "RequestConfig",
1230
+ "ResponseErrorConfig"
1231
+ ],
1232
+ root: meta.file.path,
1233
+ path: node_path.default.resolve(root, ".kubb/fetch.ts"),
1234
+ isTypeOnly: true
1235
+ })] }),
1236
+ isFormData && node.requestBody?.schema && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1237
+ name: ["buildFormData"],
1238
+ root: meta.file.path,
1239
+ path: node_path.default.resolve(root, ".kubb/config.ts")
1240
+ }),
1241
+ meta.fileZod && importedZodNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1242
+ name: importedZodNames,
1243
+ root: meta.file.path,
1244
+ path: meta.fileZod.path
1245
+ }),
1246
+ meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1247
+ name: Array.from(new Set(importedTypeNames)),
1248
+ root: meta.file.path,
1249
+ path: meta.fileTs.path,
1250
+ isTypeOnly: true
1251
+ }),
1252
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Url, {
1253
+ name: meta.urlName,
1254
+ baseURL,
1255
+ pathParamsType,
1256
+ paramsCasing,
1257
+ paramsType,
1258
+ node,
1259
+ tsResolver,
1260
+ isIndexable: urlType === "export",
1261
+ isExportable: urlType === "export"
1262
+ }),
1263
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Client, {
1264
+ name: meta.name,
1265
+ urlName: meta.urlName,
1266
+ baseURL,
1267
+ dataReturnType,
1268
+ pathParamsType,
1269
+ paramsCasing,
1270
+ paramsType,
1271
+ node,
1272
+ tsResolver,
1273
+ zodResolver,
1274
+ parser
1275
+ })
1276
+ ]
1277
+ });
1278
+ }
1279
+ });
1280
+ //#endregion
1281
+ //#region src/generators/groupedClientGenerator.tsx
1282
+ const groupedClientGenerator = (0, _kubb_core.defineGenerator)({
1283
+ name: "groupedClient",
1284
+ operations(nodes, options) {
1285
+ const { config, resolver, adapter, root } = this;
1286
+ const { output, group } = options;
1287
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric_jsx_runtime.Fragment, { children: nodes.reduce((acc, operationNode) => {
1288
+ if (group?.type === "tag") {
1289
+ const tag = operationNode.tags[0];
1290
+ const name = tag ? group?.name?.({ group: camelCase(tag) }) : void 0;
1291
+ if (!tag || !name) return acc;
1292
+ const file = resolver.resolveFile({
1293
+ name,
1294
+ extname: ".ts",
1295
+ tag
1296
+ }, {
1297
+ root,
1298
+ output,
1299
+ group
1300
+ });
1301
+ const clientFile = resolver.resolveFile({
1302
+ name: operationNode.operationId,
1303
+ extname: ".ts",
1304
+ tag: operationNode.tags[0] ?? "default",
1305
+ path: operationNode.path
1306
+ }, {
1307
+ root,
1308
+ output,
1309
+ group
1310
+ });
1311
+ const client = {
1312
+ name: resolver.resolveName(operationNode.operationId),
1313
+ file: clientFile
1314
+ };
1315
+ const previous = acc.find((item) => item.file.path === file.path);
1316
+ if (previous) previous.clients.push(client);
1317
+ else acc.push({
1318
+ name,
1319
+ file,
1320
+ clients: [client]
1321
+ });
1322
+ }
1323
+ return acc;
1324
+ }, []).map(({ name, file, clients }) => {
1325
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1326
+ baseName: file.baseName,
1327
+ path: file.path,
1328
+ meta: file.meta,
1329
+ banner: resolver.resolveBanner(adapter.rootNode, {
1330
+ output,
1331
+ config
1332
+ }),
1333
+ footer: resolver.resolveFooter(adapter.rootNode, {
1334
+ output,
1335
+ config
1336
+ }),
1337
+ children: [clients.map((client) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1338
+ name: [client.name],
1339
+ root: file.path,
1340
+ path: client.file.path
1341
+ }, client.name)), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1342
+ name,
1343
+ isExportable: true,
1344
+ isIndexable: true,
1345
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
1346
+ export: true,
1347
+ name,
1348
+ children: `return { ${clients.map((client) => client.name).join(", ")} }`
1349
+ })
1350
+ })]
1351
+ }, file.path);
1352
+ }) });
1353
+ }
1354
+ });
1355
+ //#endregion
1356
+ //#region src/components/Operations.tsx
1357
+ function Operations({ name, nodes }) {
1358
+ const operationsObject = {};
1359
+ nodes.forEach((node) => {
1360
+ operationsObject[node.operationId] = {
1361
+ path: new URLPath(node.path).URL,
1362
+ method: node.method.toLowerCase()
1363
+ };
1364
+ });
1365
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1366
+ name,
1367
+ isExportable: true,
1368
+ isIndexable: true,
1369
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
1370
+ name,
1371
+ export: true,
1372
+ children: JSON.stringify(operationsObject, void 0, 2)
1373
+ })
1374
+ });
1375
+ }
1376
+ //#endregion
1377
+ //#region src/generators/operationsGenerator.tsx
1378
+ const operationsGenerator = (0, _kubb_core.defineGenerator)({
1379
+ name: "client",
1380
+ operations(nodes, options) {
1381
+ const { config, resolver, adapter, root } = this;
1382
+ const { output, group } = options;
1383
+ const name = "operations";
1384
+ const file = resolver.resolveFile({
1385
+ name,
1386
+ extname: ".ts"
1387
+ }, {
1388
+ root,
1389
+ output,
1390
+ group
1391
+ });
1392
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File, {
1393
+ baseName: file.baseName,
1394
+ path: file.path,
1395
+ meta: file.meta,
1396
+ banner: resolver.resolveBanner(adapter.rootNode, {
1397
+ output,
1398
+ config
1399
+ }),
1400
+ footer: resolver.resolveFooter(adapter.rootNode, {
1401
+ output,
1402
+ config
1403
+ }),
1404
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Operations, {
1405
+ name,
1406
+ nodes
1407
+ })
1408
+ });
1409
+ }
1410
+ });
1411
+ //#endregion
1412
+ //#region src/components/StaticClassClient.tsx
1413
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1414
+ function generateMethod({ node, name, tsResolver, zodResolver, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
1415
+ const path = new URLPath(node.path, { casing: paramsCasing });
1416
+ const contentType = node.requestBody?.contentType ?? "application/json";
1417
+ const isFormData = contentType === "multipart/form-data";
1418
+ const headers = buildHeaders(contentType, !!(node.parameters.filter((p) => p.in === "header").length > 0 ? tsResolver.resolveHeaderParamsName(node, node.parameters.filter((p) => p.in === "header")[0]) : void 0));
1419
+ const generics = buildGenerics(node, tsResolver);
1420
+ const paramsNode = Client.getParams({
1421
+ paramsType,
1422
+ paramsCasing,
1423
+ pathParamsType,
1424
+ node,
1425
+ tsResolver,
1426
+ isConfigurable: true
1427
+ });
1428
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1429
+ const clientParams = buildClassClientParams({
1430
+ node,
1431
+ path,
1432
+ baseURL,
1433
+ tsResolver,
1434
+ isFormData,
1435
+ headers
1436
+ });
1437
+ const jsdoc = buildJSDoc(getComments(node));
1438
+ const requestDataLine = buildRequestDataLine({
1439
+ parser,
1440
+ node,
1441
+ zodResolver
1442
+ });
1443
+ const formDataLine = buildFormDataLine(isFormData, !!node.requestBody?.schema);
1444
+ const returnStatement = buildReturnStatement({
1445
+ dataReturnType,
1446
+ parser,
1447
+ node,
1448
+ zodResolver
1449
+ });
1450
+ return `${jsdoc} static async ${name}(${paramsSignature}) {\n${[
1451
+ "const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)",
1452
+ "",
1453
+ requestDataLine,
1454
+ formDataLine,
1455
+ `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
1456
+ returnStatement
1457
+ ].filter(Boolean).map((line) => ` ${line}`).join("\n")}\n }`;
1458
+ }
1459
+ function StaticClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
1460
+ const classCode = `export class ${name} {\n static #config: Partial<RequestConfig> & { client?: Client } = {}\n\n${operations.map(({ node, name: methodName, tsResolver, zodResolver }) => generateMethod({
1461
+ node,
1462
+ name: methodName,
1463
+ tsResolver,
1464
+ zodResolver,
1465
+ baseURL,
1466
+ dataReturnType,
1467
+ parser,
1468
+ paramsType,
1469
+ paramsCasing,
1470
+ pathParamsType
1471
+ })).join("\n\n")}\n}`;
1472
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File.Source, {
1473
+ name,
1474
+ isExportable,
1475
+ isIndexable,
1476
+ children: [classCode, children]
1477
+ });
1478
+ }
1479
+ StaticClassClient.getParams = Client.getParams;
1480
+ //#endregion
1481
+ //#region src/generators/staticClassClientGenerator.tsx
1482
+ function resolveTypeImportNames(node, tsResolver) {
1483
+ return [
1484
+ node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0,
1485
+ tsResolver.resolveResponseName(node),
1486
+ ...node.parameters.filter((p) => p.in === "path").map((p) => tsResolver.resolvePathParamsName(node, p)),
1487
+ ...node.parameters.filter((p) => p.in === "query").map((p) => tsResolver.resolveQueryParamsName(node, p)),
1488
+ ...node.parameters.filter((p) => p.in === "header").map((p) => tsResolver.resolveHeaderParamsName(node, p)),
1489
+ ...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
1490
+ ].filter((n) => Boolean(n));
1491
+ }
1492
+ function resolveZodImportNames(node, zodResolver) {
1493
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
1494
+ }
1495
+ const staticClassClientGenerator = (0, _kubb_core.defineGenerator)({
1496
+ name: "staticClassClient",
1497
+ operations(nodes, options) {
1498
+ const { adapter, config, driver, resolver, root } = this;
1499
+ const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath } = options;
1500
+ const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL;
1501
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1502
+ if (!pluginTs?.resolver) return null;
1503
+ const tsResolver = pluginTs.resolver;
1504
+ const tsPluginOptions = pluginTs.options;
1505
+ const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
1506
+ const zodResolver = pluginZod?.resolver;
1507
+ function buildOperationData(node) {
1508
+ const typeFile = tsResolver.resolveFile({
1509
+ name: node.operationId,
1510
+ extname: ".ts",
1511
+ tag: node.tags[0] ?? "default",
1512
+ path: node.path
1513
+ }, {
1514
+ root,
1515
+ output: tsPluginOptions?.output ?? output,
1516
+ group: tsPluginOptions?.group
1517
+ });
1518
+ const zodFile = zodResolver && pluginZod?.options ? zodResolver.resolveFile({
1519
+ name: node.operationId,
1520
+ extname: ".ts",
1521
+ tag: node.tags[0] ?? "default",
1522
+ path: node.path
1523
+ }, {
1524
+ root,
1525
+ output: pluginZod.options.output ?? output,
1526
+ group: pluginZod.options.group
1527
+ }) : void 0;
1528
+ return {
1529
+ node,
1530
+ name: resolver.resolveName(node.operationId),
1531
+ tsResolver,
1532
+ zodResolver,
1533
+ typeFile,
1534
+ zodFile
1535
+ };
1536
+ }
1537
+ const controllers = nodes.reduce((acc, operationNode) => {
1538
+ const tag = operationNode.tags[0];
1539
+ const groupName = tag ? group?.name?.({ group: camelCase(tag) }) ?? pascalCase(tag) : "Client";
1540
+ if (!tag && !group) {
1541
+ const name = "ApiClient";
1542
+ const file = resolver.resolveFile({
1543
+ name,
1544
+ extname: ".ts"
1545
+ }, {
1546
+ root,
1547
+ output,
1548
+ group
1549
+ });
1550
+ const operationData = buildOperationData(operationNode);
1551
+ const previous = acc.find((item) => item.file.path === file.path);
1552
+ if (previous) previous.operations.push(operationData);
1553
+ else acc.push({
1554
+ name,
1555
+ file,
1556
+ operations: [operationData]
1557
+ });
1558
+ } else if (tag) {
1559
+ const name = groupName;
1560
+ const file = resolver.resolveFile({
1561
+ name,
1562
+ extname: ".ts",
1563
+ tag
1564
+ }, {
1565
+ root,
1566
+ output,
1567
+ group
1568
+ });
1569
+ const operationData = buildOperationData(operationNode);
1570
+ const previous = acc.find((item) => item.file.path === file.path);
1571
+ if (previous) previous.operations.push(operationData);
1572
+ else acc.push({
1573
+ name,
1574
+ file,
1575
+ operations: [operationData]
1576
+ });
1577
+ }
1578
+ return acc;
1579
+ }, []);
1580
+ function collectTypeImports(ops) {
1581
+ const typeImportsByFile = /* @__PURE__ */ new Map();
1582
+ const typeFilesByPath = /* @__PURE__ */ new Map();
1583
+ ops.forEach((op) => {
1584
+ const names = resolveTypeImportNames(op.node, tsResolver);
1585
+ if (!typeImportsByFile.has(op.typeFile.path)) typeImportsByFile.set(op.typeFile.path, /* @__PURE__ */ new Set());
1586
+ const imports = typeImportsByFile.get(op.typeFile.path);
1587
+ names.forEach((n) => {
1588
+ imports.add(n);
1589
+ });
1590
+ typeFilesByPath.set(op.typeFile.path, op.typeFile);
1591
+ });
1592
+ return {
1593
+ typeImportsByFile,
1594
+ typeFilesByPath
1595
+ };
1596
+ }
1597
+ function collectZodImports(ops) {
1598
+ const zodImportsByFile = /* @__PURE__ */ new Map();
1599
+ const zodFilesByPath = /* @__PURE__ */ new Map();
1600
+ ops.forEach((op) => {
1601
+ if (!op.zodFile || !zodResolver) return;
1602
+ const names = resolveZodImportNames(op.node, zodResolver);
1603
+ if (!zodImportsByFile.has(op.zodFile.path)) zodImportsByFile.set(op.zodFile.path, /* @__PURE__ */ new Set());
1604
+ const imports = zodImportsByFile.get(op.zodFile.path);
1605
+ names.forEach((n) => {
1606
+ imports.add(n);
1607
+ });
1608
+ zodFilesByPath.set(op.zodFile.path, op.zodFile);
1609
+ });
1610
+ return {
1611
+ zodImportsByFile,
1612
+ zodFilesByPath
1613
+ };
1614
+ }
1615
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric_jsx_runtime.Fragment, { children: controllers.map(({ name, file, operations: ops }) => {
1616
+ const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
1617
+ const { zodImportsByFile, zodFilesByPath } = parser === "zod" ? collectZodImports(ops) : {
1618
+ zodImportsByFile: /* @__PURE__ */ new Map(),
1619
+ zodFilesByPath: /* @__PURE__ */ new Map()
1620
+ };
1621
+ const hasFormData = ops.some((op) => op.node.requestBody?.contentType === "multipart/form-data");
1622
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1623
+ baseName: file.baseName,
1624
+ path: file.path,
1625
+ meta: file.meta,
1626
+ banner: resolver.resolveBanner(adapter.rootNode, {
1627
+ output,
1628
+ config
1629
+ }),
1630
+ footer: resolver.resolveFooter(adapter.rootNode, {
1631
+ output,
1632
+ config
1633
+ }),
1634
+ children: [
1635
+ importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
1636
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1637
+ name: "fetch",
1638
+ path: importPath
1639
+ }),
1640
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1641
+ name: ["mergeConfig"],
1642
+ path: importPath
1643
+ }),
1644
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1645
+ name: [
1646
+ "Client",
1647
+ "RequestConfig",
1648
+ "ResponseErrorConfig"
1649
+ ],
1650
+ path: importPath,
1651
+ isTypeOnly: true
1652
+ })
1653
+ ] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
1654
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1655
+ name: ["fetch"],
1656
+ root: file.path,
1657
+ path: node_path.default.resolve(root, ".kubb/fetch.ts")
1658
+ }),
1659
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1660
+ name: ["mergeConfig"],
1661
+ root: file.path,
1662
+ path: node_path.default.resolve(root, ".kubb/fetch.ts")
1663
+ }),
1664
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1665
+ name: [
1666
+ "Client",
1667
+ "RequestConfig",
1668
+ "ResponseErrorConfig"
1669
+ ],
1670
+ root: file.path,
1671
+ path: node_path.default.resolve(root, ".kubb/fetch.ts"),
1672
+ isTypeOnly: true
1673
+ })
1674
+ ] }),
1675
+ hasFormData && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1676
+ name: ["buildFormData"],
1677
+ root: file.path,
1678
+ path: node_path.default.resolve(root, ".kubb/config.ts")
1679
+ }),
1680
+ Array.from(typeImportsByFile.entries()).map(([filePath, importSet]) => {
1681
+ const typeFile = typeFilesByPath.get(filePath);
1682
+ if (!typeFile) return null;
1683
+ const importNames = Array.from(importSet).filter(Boolean);
1684
+ if (importNames.length === 0) return null;
1685
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1686
+ name: importNames,
1687
+ root: file.path,
1688
+ path: typeFile.path,
1689
+ isTypeOnly: true
1690
+ }, filePath);
1691
+ }),
1692
+ parser === "zod" && Array.from(zodImportsByFile.entries()).map(([filePath, importSet]) => {
1693
+ const zodFile = zodFilesByPath.get(filePath);
1694
+ if (!zodFile) return null;
1695
+ const importNames = Array.from(importSet).filter(Boolean);
1696
+ if (importNames.length === 0) return null;
1697
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1698
+ name: importNames,
1699
+ root: file.path,
1700
+ path: zodFile.path
1701
+ }, filePath);
1702
+ }),
1703
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(StaticClassClient, {
1704
+ name,
1705
+ operations: ops,
1706
+ baseURL,
1707
+ dataReturnType,
1708
+ pathParamsType,
1709
+ paramsCasing,
1710
+ paramsType,
1711
+ parser
1712
+ })
1713
+ ]
1714
+ }, file.path);
1715
+ }) });
1716
+ }
1717
+ });
1718
+ //#endregion
1719
+ //#region package.json
1720
+ var version = "5.0.0-alpha.31";
1721
+ //#endregion
1722
+ //#region src/resolvers/resolverClient.ts
1723
+ /**
1724
+ * Resolver for `@kubb/plugin-client` that provides the default naming
1725
+ * and path-resolution helpers used by the plugin.
1726
+ *
1727
+ * @example
1728
+ * ```ts
1729
+ * import { resolverClient } from '@kubb/plugin-client'
1730
+ *
1731
+ * resolverClient.default('list pets', 'function') // -> 'listPets'
1732
+ * resolverClient.resolveName('show pet by id') // -> 'showPetById'
1733
+ * ```
1734
+ */
1735
+ const resolverClient = (0, _kubb_core.defineResolver)(() => ({
1736
+ name: "default",
1737
+ pluginName: "plugin-client",
1738
+ default(name, type) {
1739
+ return camelCase(name, { isFile: type === "file" });
1740
+ },
1741
+ resolveName(name) {
1742
+ return this.default(name, "function");
1743
+ }
1744
+ }));
1745
+ //#endregion
1746
+ //#region src/resolvers/resolverClientLegacy.ts
1747
+ /**
1748
+ * Legacy resolver for `@kubb/plugin-client` that provides backward-compatible
1749
+ * naming conventions matching the v4 behavior.
1750
+ *
1751
+ * @example
1752
+ * ```ts
1753
+ * import { resolverClientLegacy } from '@kubb/plugin-client'
1754
+ *
1755
+ * resolverClientLegacy.default('list pets', 'function') // -> 'listPets'
1756
+ * resolverClientLegacy.resolveName('show pet by id') // -> 'showPetById'
1757
+ * ```
1758
+ */
1759
+ const resolverClientLegacy = (0, _kubb_core.defineResolver)(() => ({
1760
+ name: "kubbV4",
1761
+ pluginName: "plugin-client",
1762
+ default(name, type) {
1763
+ return camelCase(name, { isFile: type === "file" });
1764
+ },
1765
+ resolveName(name) {
1766
+ return this.default(name, "function");
1767
+ }
1768
+ }));
1769
+ //#endregion
1770
+ //#region src/presets.ts
1771
+ /**
1772
+ * Built-in preset registry for `@kubb/plugin-client`.
1773
+ *
1774
+ * - `default` — uses `resolverClient` with v5 naming conventions.
1775
+ * - `kubbV4` — uses `resolverClientLegacy` with backward-compatible naming.
1776
+ *
1777
+ * Note: Unlike plugin-ts/plugin-zod, generators are not defined here because
1778
+ * plugin-client selects generators dynamically based on `clientType`, `group`,
1779
+ * and `operations` options. Generator selection happens in `plugin.ts`.
1780
+ */
1781
+ const presets = (0, _kubb_core.definePresets)({
1782
+ default: {
1783
+ name: "default",
1784
+ resolver: resolverClient
1785
+ },
1786
+ kubbV4: {
1787
+ name: "kubbV4",
1788
+ resolver: resolverClientLegacy
1789
+ }
1790
+ });
1791
+ //#endregion
13
1792
  //#region src/plugin.ts
1793
+ /**
1794
+ * Canonical plugin name for `@kubb/plugin-client`, used to identify the plugin
1795
+ * in driver lookups and warnings.
1796
+ */
14
1797
  const pluginClientName = "plugin-client";
15
- const pluginClient = (0, _kubb_core.definePlugin)((options) => {
1798
+ /**
1799
+ * The `@kubb/plugin-client` plugin factory.
1800
+ *
1801
+ * Generates type-safe HTTP client functions (or classes) from an OpenAPI/AST `RootNode`.
1802
+ * Walks operations, delegates rendering to the active generators,
1803
+ * and writes barrel files based on `output.barrelType`.
1804
+ *
1805
+ * @example
1806
+ * ```ts
1807
+ * import { pluginClient } from '@kubb/plugin-client'
1808
+ *
1809
+ * export default defineConfig({
1810
+ * plugins: [pluginClient({ output: { path: 'clients' } })],
1811
+ * })
1812
+ * ```
1813
+ */
1814
+ const pluginClient = (0, _kubb_core.createPlugin)((options) => {
16
1815
  const { output = {
17
1816
  path: "clients",
18
1817
  barrelType: "named"
19
- }, group, urlType = false, exclude = [], include, override = [], transformers = {}, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, baseURL, paramsCasing, clientType = "function", parser = "client", client = "axios", importPath, contentType, bundle = false, wrapper } = options;
1818
+ }, group, exclude = [], include, override = [], urlType = false, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, paramsCasing, clientType = "function", parser = "client", client = "axios", importPath, bundle = false, wrapper, baseURL, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer } = options;
20
1819
  const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : void 0);
21
- const defaultGenerators = [
22
- clientType === "staticClass" ? require_generators.staticClassClientGenerator : clientType === "class" ? require_generators.classClientGenerator : require_generators.clientGenerator,
23
- group && clientType === "function" ? require_generators.groupedClientGenerator : void 0,
24
- operations ? require_generators.operationsGenerator : void 0
25
- ].filter((x) => Boolean(x));
26
- const generators = options.generators ?? defaultGenerators;
1820
+ const preset = (0, _kubb_core.getPreset)({
1821
+ preset: compatibilityPreset,
1822
+ presets,
1823
+ resolver: userResolver,
1824
+ transformer: userTransformer,
1825
+ generators: options.generators ?? [
1826
+ clientType === "staticClass" ? staticClassClientGenerator : clientType === "class" ? classClientGenerator : clientGenerator,
1827
+ group && clientType === "function" ? groupedClientGenerator : void 0,
1828
+ operations ? operationsGenerator : void 0
1829
+ ].filter((x) => Boolean(x))
1830
+ });
1831
+ const mergedGenerator = (0, _kubb_core.mergeGenerators)(preset.generators ?? []);
1832
+ let resolveNameWarning = false;
1833
+ let resolvePathWarning = false;
27
1834
  return {
28
1835
  name: pluginClientName,
29
- options: {
30
- client,
31
- clientType,
32
- bundle,
33
- output,
34
- group,
35
- parser,
36
- dataReturnType,
37
- importPath: resolvedImportPath,
38
- paramsType,
39
- paramsCasing,
40
- pathParamsType,
41
- baseURL,
42
- urlType,
43
- wrapper
1836
+ version,
1837
+ get resolver() {
1838
+ return preset.resolver;
1839
+ },
1840
+ get transformer() {
1841
+ return preset.transformer;
44
1842
  },
45
- pre: [_kubb_plugin_oas.pluginOasName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter(Boolean),
1843
+ get options() {
1844
+ return {
1845
+ client,
1846
+ clientType,
1847
+ bundle,
1848
+ output,
1849
+ exclude,
1850
+ include,
1851
+ override,
1852
+ group: group ? {
1853
+ ...group,
1854
+ name: group.name ? group.name : (ctx) => {
1855
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1856
+ return `${camelCase(ctx.group)}Controller`;
1857
+ }
1858
+ } : void 0,
1859
+ parser,
1860
+ dataReturnType,
1861
+ importPath: resolvedImportPath,
1862
+ baseURL,
1863
+ paramsType,
1864
+ paramsCasing,
1865
+ pathParamsType,
1866
+ urlType,
1867
+ wrapper,
1868
+ resolver: preset.resolver
1869
+ };
1870
+ },
1871
+ pre: [_kubb_plugin_ts.pluginTsName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter(Boolean),
46
1872
  resolvePath(baseName, pathMode, options) {
47
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
48
- if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
49
- /**
50
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
51
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
52
- */
53
- return node_path.default.resolve(root, output.path);
54
- if (group && (options?.group?.path || options?.group?.tag)) {
55
- const groupName = group?.name ? group.name : (ctx) => {
56
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
57
- return `${require_StaticClassClient.camelCase(ctx.group)}Controller`;
58
- };
59
- return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
1873
+ if (!resolvePathWarning) {
1874
+ this.warn("Do not use resolvePath for pluginClient, use resolverClient.resolvePath instead");
1875
+ resolvePathWarning = true;
60
1876
  }
61
- return node_path.default.resolve(root, output.path, baseName);
1877
+ return this.plugin.resolver.resolvePath({
1878
+ baseName,
1879
+ pathMode,
1880
+ tag: options?.group?.tag,
1881
+ path: options?.group?.path
1882
+ }, {
1883
+ root: this.root,
1884
+ output,
1885
+ group: this.plugin.options.group
1886
+ });
62
1887
  },
63
1888
  resolveName(name, type) {
64
- const resolvedName = require_StaticClassClient.camelCase(name, { isFile: type === "file" });
65
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
66
- return resolvedName;
1889
+ if (!resolveNameWarning) {
1890
+ this.warn("Do not use resolveName for pluginClient, use resolverClient.default instead");
1891
+ resolveNameWarning = true;
1892
+ }
1893
+ return this.plugin.resolver.default(name, type);
67
1894
  },
68
- async install() {
69
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
70
- const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
71
- const oas = await this.getOas();
72
- const baseURL = await this.getBaseURL();
73
- if (bundle && !this.plugin.options.importPath) await this.addFile({
1895
+ async operation(node, options) {
1896
+ return mergedGenerator.operation?.call(this, node, options);
1897
+ },
1898
+ async operations(nodes, options) {
1899
+ return mergedGenerator.operations?.call(this, nodes, options);
1900
+ },
1901
+ async buildStart() {
1902
+ const { plugin } = this;
1903
+ const root = this.root;
1904
+ if (bundle && !plugin.options.importPath) await this.addFile({
74
1905
  baseName: "fetch.ts",
75
1906
  path: node_path.default.resolve(root, ".kubb/fetch.ts"),
76
1907
  sources: [{
77
1908
  name: "fetch",
78
- value: this.plugin.options.client === "fetch" ? require_templates_clients_fetch_source.source : require_templates_clients_axios_source.source,
1909
+ value: plugin.options.client === "fetch" ? require_templates_clients_fetch_source.source : require_templates_clients_axios_source.source,
79
1910
  isExportable: true,
80
1911
  isIndexable: true
81
1912
  }],
@@ -94,34 +1925,22 @@ const pluginClient = (0, _kubb_core.definePlugin)((options) => {
94
1925
  imports: [],
95
1926
  exports: []
96
1927
  });
97
- const files = await new _kubb_plugin_oas.OperationGenerator(baseURL ? {
98
- ...this.plugin.options,
99
- baseURL
100
- } : this.plugin.options, {
101
- fabric: this.fabric,
102
- oas,
103
- pluginManager: this.pluginManager,
104
- events: this.events,
105
- plugin: this.plugin,
106
- contentType,
107
- exclude,
108
- include,
109
- override,
110
- mode
111
- }).build(...generators);
112
- await this.upsertFile(...files);
113
- const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
114
- type: output.barrelType ?? "named",
115
- root,
116
- output,
117
- meta: { pluginName: this.plugin.name }
118
- });
119
- await this.upsertFile(...barrelFiles);
120
1928
  }
121
1929
  };
122
1930
  });
123
1931
  //#endregion
1932
+ exports.Client = Client;
1933
+ exports.ClientLegacy = ClientLegacy;
1934
+ exports.UrlLegacy = UrlLegacy;
1935
+ exports.classClientGenerator = classClientGenerator;
1936
+ exports.clientGenerator = clientGenerator;
1937
+ exports.groupedClientGenerator = groupedClientGenerator;
1938
+ exports.operationsGenerator = operationsGenerator;
124
1939
  exports.pluginClient = pluginClient;
125
1940
  exports.pluginClientName = pluginClientName;
1941
+ exports.presets = presets;
1942
+ exports.resolverClient = resolverClient;
1943
+ exports.resolverClientLegacy = resolverClientLegacy;
1944
+ exports.staticClassClientGenerator = staticClassClientGenerator;
126
1945
 
127
1946
  //# sourceMappingURL=index.cjs.map