@kubb/plugin-client 5.0.0-alpha.9 → 5.0.0-beta.15

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