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

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 +1818 -97
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.ts +330 -4
  16. package/dist/index.js +1804 -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 +776 -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,1848 @@
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
+ function resolveOperationTypeNames(node, resolver, options = {}) {
405
+ const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
406
+ const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
407
+ const exclude = new Set(options.exclude ?? []);
408
+ const paramNames = [
409
+ ...path.map((param) => resolver.resolvePathParamsName(node, param)),
410
+ ...query.map((param) => resolver.resolveQueryParamsName(node, param)),
411
+ ...header.map((param) => resolver.resolveHeaderParamsName(node, param))
412
+ ];
413
+ const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0, resolver.resolveResponseName(node)];
414
+ return (options.order === "body-response-first" ? [
415
+ ...bodyAndResponseNames,
416
+ ...paramNames,
417
+ ...responseStatusNames
418
+ ] : [
419
+ ...paramNames,
420
+ ...bodyAndResponseNames,
421
+ ...responseStatusNames
422
+ ]).filter((name) => Boolean(name) && !exclude.has(name));
423
+ }
424
+ //#endregion
425
+ //#region ../../internals/shared/src/params.ts
426
+ function buildParamsMapping(originalParams, mappedParams) {
427
+ const mapping = {};
428
+ let hasChanged = false;
429
+ originalParams.forEach((param, i) => {
430
+ const mappedName = mappedParams[i]?.name ?? param.name;
431
+ mapping[param.name] = mappedName;
432
+ if (param.name !== mappedName) hasChanged = true;
433
+ });
434
+ return hasChanged ? mapping : void 0;
435
+ }
436
+ //#endregion
437
+ //#region src/functionParams.ts
438
+ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
439
+ const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
440
+ function isGroup(spec) {
441
+ return "children" in spec;
442
+ }
443
+ function createType(type) {
444
+ return type ? _kubb_core.ast.createParamsType({
445
+ variant: "reference",
446
+ name: type
447
+ }) : void 0;
448
+ }
449
+ function createDeclarationLeaf(name, spec) {
450
+ if (spec.default !== void 0) return _kubb_core.ast.createFunctionParameter({
451
+ name,
452
+ type: createType(spec.type),
453
+ default: spec.default,
454
+ rest: spec.mode === "inlineSpread"
455
+ });
456
+ return _kubb_core.ast.createFunctionParameter({
457
+ name,
458
+ type: createType(spec.type),
459
+ optional: !!spec.optional,
460
+ rest: spec.mode === "inlineSpread"
461
+ });
462
+ }
463
+ function createDeclarationParam(name, spec) {
464
+ if (isGroup(spec)) return _kubb_core.ast.createParameterGroup({
465
+ inline: spec.mode === "inlineSpread",
466
+ default: spec.default,
467
+ properties: Object.entries(spec.children).filter(([, child]) => child !== void 0).map(([childName, child]) => createDeclarationLeaf(childName, child))
468
+ });
469
+ return createDeclarationLeaf(name, spec);
470
+ }
471
+ function createCallParam(name, spec) {
472
+ if (isGroup(spec)) return _kubb_core.ast.createParameterGroup({
473
+ inline: spec.mode === "inlineSpread",
474
+ properties: Object.entries(spec.children).filter(([, child]) => child !== void 0).map(([childName, child]) => _kubb_core.ast.createFunctionParameter({
475
+ name: child?.mode === "inlineSpread" ? spec.mode === "inlineSpread" ? child.value ?? childName : `...${child.value ?? childName}` : child?.value ? `${childName}: ${child.value}` : childName,
476
+ rest: spec.mode === "inlineSpread" && child?.mode === "inlineSpread"
477
+ }))
478
+ });
479
+ return _kubb_core.ast.createFunctionParameter({
480
+ name: spec.value ?? name,
481
+ rest: spec.mode === "inlineSpread"
482
+ });
483
+ }
484
+ /**
485
+ * Creates function parameter builders for generating function signatures and calls.
486
+ * Returns utilities to output constructor signatures (`toConstructor()`) or call expressions (`toCall()`).
487
+ */
488
+ function createFunctionParams(params) {
489
+ const entries = Object.entries(params).filter(([, spec]) => spec !== void 0);
490
+ return {
491
+ toConstructor() {
492
+ return declarationPrinter$4.print(_kubb_core.ast.createFunctionParameters({ params: entries.map(([name, spec]) => createDeclarationParam(name, spec)) })) ?? "";
493
+ },
494
+ toCall() {
495
+ return callPrinter.print(_kubb_core.ast.createFunctionParameters({ params: entries.map(([name, spec]) => createCallParam(name, spec)) })) ?? "";
496
+ }
497
+ };
498
+ }
499
+ //#endregion
500
+ //#region src/components/Url.tsx
501
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
502
+ function buildUrlParamsNode({ paramsType, paramsCasing, pathParamsType, node, tsResolver }) {
503
+ const urlNode = {
504
+ ...node,
505
+ parameters: node.parameters.filter((p) => p.in === "path"),
506
+ requestBody: void 0
507
+ };
508
+ return _kubb_core.ast.createOperationParams(urlNode, {
509
+ paramsType: paramsType === "object" ? "object" : "inline",
510
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
511
+ paramsCasing,
512
+ resolver: tsResolver
513
+ });
514
+ }
515
+ function Url({ name, isExportable = true, isIndexable = true, baseURL, paramsType, paramsCasing, pathParamsType, node, tsResolver }) {
516
+ const path = new URLPath(node.path);
517
+ const paramsNode = buildUrlParamsNode({
518
+ paramsType,
519
+ paramsCasing,
520
+ pathParamsType,
521
+ node,
522
+ tsResolver
523
+ });
524
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
525
+ const { path: originalPathParams } = getOperationParameters(node);
526
+ const { path: casedPathParams } = getOperationParameters(node, { paramsCasing });
527
+ const pathParamsMapping = paramsCasing ? buildParamsMapping(originalPathParams, casedPathParams) : void 0;
528
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
529
+ name,
530
+ isExportable,
531
+ isIndexable,
532
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.Function, {
533
+ name,
534
+ export: isExportable,
535
+ params: paramsSignature,
536
+ children: [
537
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => isValidVarName(originalName) && originalName !== camelCaseName).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
538
+ pathParamsMapping && Object.keys(pathParamsMapping).length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {}),
539
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Const, {
540
+ name: "res",
541
+ children: `{ method: '${node.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`
542
+ }),
543
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {}),
544
+ "return res"
545
+ ]
546
+ })
547
+ });
548
+ }
549
+ //#endregion
550
+ //#region src/components/Client.tsx
551
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
552
+ function buildClientParamsNode({ paramsType, paramsCasing, pathParamsType, node, tsResolver, isConfigurable }) {
553
+ return _kubb_core.ast.createOperationParams(node, {
554
+ paramsType,
555
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
556
+ paramsCasing,
557
+ resolver: tsResolver,
558
+ extraParams: [...isConfigurable ? [_kubb_core.ast.createFunctionParameter({
559
+ name: "config",
560
+ type: _kubb_core.ast.createParamsType({
561
+ variant: "reference",
562
+ name: buildRequestConfigType(node, tsResolver)
563
+ }),
564
+ default: "{}"
565
+ })] : []]
566
+ });
567
+ }
568
+ function Client({ name, isExportable = true, isIndexable = true, returnType, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, node, tsResolver, zodResolver, urlName, children, isConfigurable = true }) {
569
+ const path = new URLPath(node.path);
570
+ const { defaultContentType: contentType, isMultipleContentTypes, hasFormData } = getContentTypeInfo(node);
571
+ const isFormData = !isMultipleContentTypes && contentType === "multipart/form-data";
572
+ const { path: originalPathParams, query: originalQueryParams, header: originalHeaderParams } = getOperationParameters(node);
573
+ const { path: casedPathParams, query: casedQueryParams, header: casedHeaderParams } = getOperationParameters(node, { paramsCasing });
574
+ const pathParamsMapping = paramsCasing && !urlName ? buildParamsMapping(originalPathParams, casedPathParams) : void 0;
575
+ const queryParamsMapping = paramsCasing ? buildParamsMapping(originalQueryParams, casedQueryParams) : void 0;
576
+ const headerParamsMapping = paramsCasing ? buildParamsMapping(originalHeaderParams, casedHeaderParams) : void 0;
577
+ const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : void 0;
578
+ const responseName = tsResolver.resolveResponseName(node);
579
+ const queryParamsName = originalQueryParams.length > 0 ? tsResolver.resolveQueryParamsName(node, originalQueryParams[0]) : void 0;
580
+ const headerParamsName = originalHeaderParams.length > 0 ? tsResolver.resolveHeaderParamsName(node, originalHeaderParams[0]) : void 0;
581
+ const zodResponseName = zodResolver && parser === "zod" ? zodResolver.resolveResponseName?.(node) : void 0;
582
+ const zodRequestName = zodResolver && parser === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0;
583
+ const errorNames = node.responses.filter((r) => {
584
+ return Number.parseInt(r.statusCode, 10) >= 400;
585
+ }).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
586
+ const headers = [!isMultipleContentTypes && contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, headerParamsName ? headerParamsMapping ? "...mappedHeaders" : "...headers" : void 0].filter(Boolean);
587
+ const generics = [
588
+ responseName,
589
+ `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
590
+ requestName || "unknown"
591
+ ].filter(Boolean);
592
+ const paramsNode = buildClientParamsNode({
593
+ paramsType,
594
+ paramsCasing,
595
+ pathParamsType,
596
+ node,
597
+ tsResolver,
598
+ isConfigurable
599
+ });
600
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
601
+ const urlParamsNode = buildUrlParamsNode({
602
+ paramsType,
603
+ paramsCasing,
604
+ pathParamsType,
605
+ node,
606
+ tsResolver
607
+ });
608
+ const urlParamsCall = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" }).print(urlParamsNode) ?? "";
609
+ const clientParams = createFunctionParams({ config: {
610
+ mode: "object",
611
+ children: {
612
+ method: { value: JSON.stringify(node.method.toUpperCase()) },
613
+ url: { value: urlName ? `${urlName}(${urlParamsCall}).url.toString()` : path.template },
614
+ baseURL: baseURL && !urlName ? { value: `\`${baseURL}\`` } : void 0,
615
+ params: queryParamsName ? queryParamsMapping ? { value: "mappedParams" } : {} : void 0,
616
+ data: requestName ? { value: isMultipleContentTypes && hasFormData ? "contentType === 'multipart/form-data' ? formData as FormData : requestData" : isFormData ? "formData as FormData" : "requestData" } : void 0,
617
+ contentType: isConfigurable && isMultipleContentTypes ? {} : void 0,
618
+ requestConfig: isConfigurable ? { mode: "inlineSpread" } : void 0,
619
+ headers: headers.length ? { value: isConfigurable ? `{ ${headers.join(", ")}, ...requestConfig.headers }` : `{ ${headers.join(", ")} }` } : void 0
620
+ }
621
+ } });
622
+ const childrenElement = children ? children : /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
623
+ dataReturnType === "full" && parser === "zod" && zodResponseName && `return {...res, data: ${zodResponseName}.parse(res.data)}`,
624
+ dataReturnType === "data" && parser === "zod" && zodResponseName && `return ${zodResponseName}.parse(res.data)`,
625
+ dataReturnType === "full" && parser === "client" && "return res",
626
+ dataReturnType === "data" && parser === "client" && "return res.data"
627
+ ] });
628
+ 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, {
629
+ name,
630
+ isExportable,
631
+ isIndexable,
632
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.Function, {
633
+ name,
634
+ async: true,
635
+ export: isExportable,
636
+ params: paramsSignature,
637
+ JSDoc: { comments: buildOperationComments(node, {
638
+ link: "urlPath",
639
+ linkPosition: "beforeDeprecated",
640
+ splitLines: true
641
+ }) },
642
+ returnType,
643
+ children: [
644
+ isConfigurable ? `const { client: request = fetch, ${isMultipleContentTypes ? `contentType = ${JSON.stringify(contentType)}, ` : ""}...requestConfig } = config` : "",
645
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {}),
646
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {}),
647
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => isValidVarName(originalName) && originalName !== camelCaseName).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
648
+ 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", {})] }),
649
+ queryParamsMapping && queryParamsName && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
650
+ `const mappedParams = params ? { ${Object.entries(queryParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": params.${camelCaseName}`).join(", ")} } : undefined`,
651
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {}),
652
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {})
653
+ ] }),
654
+ headerParamsMapping && headerParamsName && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
655
+ `const mappedHeaders = headers ? { ${Object.entries(headerParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": headers.${camelCaseName}`).join(", ")} } : undefined`,
656
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {}),
657
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {})
658
+ ] }),
659
+ parser === "zod" && zodRequestName ? `const requestData = ${zodRequestName}.parse(data)` : requestName && "const requestData = data",
660
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {}),
661
+ (isFormData || isMultipleContentTypes && hasFormData) && requestName && "const formData = buildFormData(requestData)",
662
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {}),
663
+ isConfigurable ? `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})` : `const res = await fetch<${generics.join(", ")}>(${clientParams.toCall()})`,
664
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)("br", {}),
665
+ childrenElement
666
+ ]
667
+ })
668
+ })] });
669
+ }
670
+ //#endregion
671
+ //#region src/utils.ts
672
+ /**
673
+ * Builds HTTP headers array for a client request.
674
+ * Includes Content-Type (if not default) and spreads header parameters if present.
675
+ */
676
+ function buildHeaders(contentType, hasHeaderParams) {
677
+ return [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, hasHeaderParams ? "...headers" : void 0].filter(Boolean);
678
+ }
679
+ /**
680
+ * Builds TypeScript generic parameters for a client method.
681
+ * Includes response type, error type, and optional request type.
682
+ */
683
+ function buildGenerics(node, tsResolver) {
684
+ const responseName = tsResolver.resolveResponseName(node);
685
+ const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : void 0;
686
+ const errorNames = node.responses.filter((r) => Number.parseInt(r.statusCode, 10) >= 400).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
687
+ return [
688
+ responseName,
689
+ `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
690
+ requestName || "unknown"
691
+ ].filter(Boolean);
692
+ }
693
+ /**
694
+ * Builds the parameters object for a class-based client method.
695
+ * Includes URL, method, base URL, headers, and request/response data.
696
+ */
697
+ function buildClassClientParams({ node, path, baseURL, tsResolver, isFormData, isMultipleContentTypes, hasFormData, headers }) {
698
+ const { query: queryParams } = getOperationParameters(node);
699
+ const queryParamsName = queryParams.length > 0 ? tsResolver.resolveQueryParamsName(node, queryParams[0]) : void 0;
700
+ const requestName = node.requestBody?.content?.[0]?.schema ? tsResolver.resolveDataName(node) : void 0;
701
+ return createFunctionParams({ config: {
702
+ mode: "object",
703
+ children: {
704
+ requestConfig: { mode: "inlineSpread" },
705
+ method: { value: JSON.stringify(node.method.toUpperCase()) },
706
+ url: { value: path.template },
707
+ baseURL: baseURL ? { value: JSON.stringify(baseURL) } : void 0,
708
+ params: queryParamsName ? {} : void 0,
709
+ data: requestName ? { value: isMultipleContentTypes && hasFormData ? "contentType === 'multipart/form-data' ? formData as FormData : requestData" : isFormData ? "formData as FormData" : "requestData" } : void 0,
710
+ contentType: isMultipleContentTypes ? {} : void 0,
711
+ headers: headers.length ? { value: `{ ${headers.join(", ")}, ...requestConfig.headers }` } : void 0
712
+ }
713
+ } });
714
+ }
715
+ /**
716
+ * Builds the request data parsing line for client methods.
717
+ * Applies Zod validation if configured, otherwise uses data directly.
718
+ */
719
+ function buildRequestDataLine({ parser, node, zodResolver }) {
720
+ const zodRequestName = zodResolver && parser === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0;
721
+ if (parser === "zod" && zodRequestName) return `const requestData = ${zodRequestName}.parse(data)`;
722
+ if (node.requestBody?.content?.[0]?.schema) return "const requestData = data";
723
+ return "";
724
+ }
725
+ /**
726
+ * Builds the form data conversion line for file upload requests.
727
+ * Returns empty string if not applicable.
728
+ */
729
+ function buildFormDataLine(isFormData, hasRequest) {
730
+ return isFormData && hasRequest ? "const formData = buildFormData(requestData)" : "";
731
+ }
732
+ /**
733
+ * Builds the return statement for a client method.
734
+ * Applies Zod validation to response data if configured, otherwise returns raw response.
735
+ */
736
+ function buildReturnStatement({ dataReturnType, parser, node, zodResolver }) {
737
+ const zodResponseName = zodResolver && parser === "zod" ? zodResolver.resolveResponseName?.(node) : void 0;
738
+ if (dataReturnType === "full" && parser === "zod" && zodResponseName) return `return {...res, data: ${zodResponseName}.parse(res.data)}`;
739
+ if (dataReturnType === "data" && parser === "zod" && zodResponseName) return `return ${zodResponseName}.parse(res.data)`;
740
+ if (dataReturnType === "full" && parser === "client") return "return res";
741
+ return "return res.data";
742
+ }
743
+ //#endregion
744
+ //#region src/components/ClassClient.tsx
745
+ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
746
+ function generateMethod$1({ node, name, tsResolver, zodResolver, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
747
+ const path = new URLPath(node.path, { casing: paramsCasing });
748
+ const { defaultContentType: contentType, isMultipleContentTypes, hasFormData } = getContentTypeInfo(node);
749
+ const isFormData = !isMultipleContentTypes && contentType === "multipart/form-data";
750
+ const { header: headerParams } = getOperationParameters(node);
751
+ const headerParamsName = headerParams.length > 0 ? tsResolver.resolveHeaderParamsName(node, headerParams[0]) : void 0;
752
+ const headers = isMultipleContentTypes ? headerParamsName ? ["...headers"] : [] : buildHeaders(contentType, !!headerParamsName);
753
+ const generics = buildGenerics(node, tsResolver);
754
+ const paramsNode = buildClientParamsNode({
755
+ paramsType,
756
+ paramsCasing,
757
+ pathParamsType,
758
+ node,
759
+ tsResolver,
760
+ isConfigurable: true
761
+ });
762
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
763
+ const clientParams = buildClassClientParams({
764
+ node,
765
+ path,
766
+ baseURL,
767
+ tsResolver,
768
+ isFormData,
769
+ isMultipleContentTypes,
770
+ hasFormData,
771
+ headers
772
+ });
773
+ const jsdoc = buildJSDoc(buildOperationComments(node, {
774
+ link: "urlPath",
775
+ linkPosition: "beforeDeprecated",
776
+ splitLines: true
777
+ }));
778
+ const requestDataLine = buildRequestDataLine({
779
+ parser,
780
+ node,
781
+ zodResolver
782
+ });
783
+ const formDataLine = buildFormDataLine(isFormData || isMultipleContentTypes && hasFormData, !!node.requestBody?.content?.[0]?.schema);
784
+ const returnStatement = buildReturnStatement({
785
+ dataReturnType,
786
+ parser,
787
+ node,
788
+ zodResolver
789
+ });
790
+ return `${jsdoc}async ${name}(${paramsSignature}) {\n${[
791
+ `const { client: request = fetch, ${isMultipleContentTypes ? `contentType = ${JSON.stringify(contentType)}, ` : ""}...requestConfig } = mergeConfig(this.#config, config)`,
792
+ "",
793
+ requestDataLine,
794
+ formDataLine,
795
+ `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
796
+ returnStatement
797
+ ].filter(Boolean).map((line) => ` ${line}`).join("\n")}\n }`;
798
+ }
799
+ require_chunk.__name(generateMethod$1, "generateMethod");
800
+ function ClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
801
+ const classCode = `export class ${name} {
802
+ #config: Partial<RequestConfig> & { client?: Client }
803
+
804
+ constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
805
+ this.#config = config
806
+ }
807
+
808
+ ${operations.map(({ node, name: methodName, tsResolver, zodResolver }) => generateMethod$1({
809
+ node,
810
+ name: methodName,
811
+ tsResolver,
812
+ zodResolver,
813
+ baseURL,
814
+ dataReturnType,
815
+ parser,
816
+ paramsType,
817
+ paramsCasing,
818
+ pathParamsType
819
+ })).join("\n\n")}
820
+ }`;
821
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File.Source, {
822
+ name,
823
+ isExportable,
824
+ isIndexable,
825
+ children: [classCode, children]
826
+ });
827
+ }
828
+ //#endregion
829
+ //#region src/components/WrapperClient.tsx
830
+ function WrapperClient({ name, controllers, isExportable = true, isIndexable = true }) {
831
+ const classCode = `export class ${name} {
832
+ ${controllers.map(({ className, propertyName }) => ` readonly ${propertyName}: ${className}`).join("\n")}
833
+
834
+ constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
835
+ ${controllers.map(({ className, propertyName }) => ` this.${propertyName} = new ${className}(config)`).join("\n")}
836
+ }
837
+ }`;
838
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
839
+ name,
840
+ isExportable,
841
+ isIndexable,
842
+ children: classCode
843
+ });
844
+ }
845
+ //#endregion
846
+ //#region src/generators/classClientGenerator.tsx
847
+ function resolveTypeImportNames$1(node, tsResolver) {
848
+ return resolveOperationTypeNames(node, tsResolver, { order: "body-response-first" });
849
+ }
850
+ require_chunk.__name(resolveTypeImportNames$1, "resolveTypeImportNames");
851
+ function resolveZodImportNames$1(node, zodResolver) {
852
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
853
+ }
854
+ require_chunk.__name(resolveZodImportNames$1, "resolveZodImportNames");
855
+ const classClientGenerator = (0, _kubb_core.defineGenerator)({
856
+ name: "classClient",
857
+ renderer: _kubb_renderer_jsx.jsxRenderer,
858
+ operations(nodes, ctx) {
859
+ const { adapter, config, driver, resolver, root } = ctx;
860
+ const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, sdk } = ctx.options;
861
+ const baseURL = ctx.options.baseURL ?? adapter.inputNode?.meta?.baseURL;
862
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
863
+ if (!pluginTs) return null;
864
+ const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
865
+ const tsPluginOptions = pluginTs.options;
866
+ const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
867
+ const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : void 0;
868
+ function buildOperationData(node) {
869
+ const typeFile = tsResolver.resolveFile({
870
+ name: node.operationId,
871
+ extname: ".ts",
872
+ tag: node.tags[0] ?? "default",
873
+ path: node.path
874
+ }, {
875
+ root,
876
+ output: tsPluginOptions?.output ?? output,
877
+ group: tsPluginOptions?.group
878
+ });
879
+ const zodFile = zodResolver && pluginZod?.options ? zodResolver.resolveFile({
880
+ name: node.operationId,
881
+ extname: ".ts",
882
+ tag: node.tags[0] ?? "default",
883
+ path: node.path
884
+ }, {
885
+ root,
886
+ output: pluginZod.options?.output ?? output,
887
+ group: pluginZod.options?.group
888
+ }) : void 0;
889
+ return {
890
+ node,
891
+ name: resolver.resolveName(node.operationId),
892
+ tsResolver,
893
+ zodResolver,
894
+ typeFile,
895
+ zodFile
896
+ };
897
+ }
898
+ const controllers = nodes.reduce((acc, operationNode) => {
899
+ const tag = operationNode.tags[0];
900
+ const groupName = tag ? group?.name?.({ group: camelCase(tag) }) ?? resolver.resolveGroupName(tag) : resolver.resolveGroupName("Client");
901
+ if (!tag && !group) {
902
+ const name = resolver.resolveClassName("ApiClient");
903
+ const file = resolver.resolveFile({
904
+ name,
905
+ extname: ".ts"
906
+ }, {
907
+ root,
908
+ output,
909
+ group
910
+ });
911
+ const operationData = buildOperationData(operationNode);
912
+ const previous = acc.find((item) => item.file.path === file.path);
913
+ if (previous) previous.operations.push(operationData);
914
+ else acc.push({
915
+ name,
916
+ propertyName: resolver.resolveClientPropertyName(name),
917
+ file,
918
+ operations: [operationData]
919
+ });
920
+ } else if (tag) {
921
+ const name = groupName;
922
+ const file = resolver.resolveFile({
923
+ name,
924
+ extname: ".ts",
925
+ tag
926
+ }, {
927
+ root,
928
+ output,
929
+ group
930
+ });
931
+ const operationData = buildOperationData(operationNode);
932
+ const previous = acc.find((item) => item.file.path === file.path);
933
+ if (previous) previous.operations.push(operationData);
934
+ else acc.push({
935
+ name,
936
+ propertyName: resolver.resolveClientPropertyName(name),
937
+ file,
938
+ operations: [operationData]
939
+ });
940
+ }
941
+ return acc;
942
+ }, []);
943
+ function collectTypeImports(ops) {
944
+ const typeImportsByFile = /* @__PURE__ */ new Map();
945
+ const typeFilesByPath = /* @__PURE__ */ new Map();
946
+ ops.forEach((op) => {
947
+ const names = resolveTypeImportNames$1(op.node, tsResolver);
948
+ if (!typeImportsByFile.has(op.typeFile.path)) typeImportsByFile.set(op.typeFile.path, /* @__PURE__ */ new Set());
949
+ const imports = typeImportsByFile.get(op.typeFile.path);
950
+ names.forEach((n) => {
951
+ imports.add(n);
952
+ });
953
+ typeFilesByPath.set(op.typeFile.path, op.typeFile);
954
+ });
955
+ return {
956
+ typeImportsByFile,
957
+ typeFilesByPath
958
+ };
959
+ }
960
+ function collectZodImports(ops) {
961
+ const zodImportsByFile = /* @__PURE__ */ new Map();
962
+ const zodFilesByPath = /* @__PURE__ */ new Map();
963
+ ops.forEach((op) => {
964
+ if (!op.zodFile || !zodResolver) return;
965
+ const names = resolveZodImportNames$1(op.node, zodResolver);
966
+ if (!zodImportsByFile.has(op.zodFile.path)) zodImportsByFile.set(op.zodFile.path, /* @__PURE__ */ new Set());
967
+ const imports = zodImportsByFile.get(op.zodFile.path);
968
+ names.forEach((n) => {
969
+ imports.add(n);
970
+ });
971
+ zodFilesByPath.set(op.zodFile.path, op.zodFile);
972
+ });
973
+ return {
974
+ zodImportsByFile,
975
+ zodFilesByPath
976
+ };
977
+ }
978
+ const files = controllers.map(({ name, file, operations: ops }) => {
979
+ const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
980
+ const { zodImportsByFile, zodFilesByPath } = parser === "zod" ? collectZodImports(ops) : {
981
+ zodImportsByFile: /* @__PURE__ */ new Map(),
982
+ zodFilesByPath: /* @__PURE__ */ new Map()
983
+ };
984
+ const hasFormData = ops.some((op) => op.node.requestBody?.content?.some((e) => e.contentType === "multipart/form-data") ?? false);
985
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
986
+ baseName: file.baseName,
987
+ path: file.path,
988
+ meta: file.meta,
989
+ banner: resolver.resolveBanner(adapter.inputNode, {
990
+ output,
991
+ config
992
+ }),
993
+ footer: resolver.resolveFooter(adapter.inputNode, {
994
+ output,
995
+ config
996
+ }),
997
+ children: [
998
+ importPath ? /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
999
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1000
+ name: "fetch",
1001
+ path: importPath
1002
+ }),
1003
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1004
+ name: ["mergeConfig"],
1005
+ path: importPath
1006
+ }),
1007
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1008
+ name: [
1009
+ "Client",
1010
+ "RequestConfig",
1011
+ "ResponseErrorConfig"
1012
+ ],
1013
+ path: importPath,
1014
+ isTypeOnly: true
1015
+ })
1016
+ ] }) : /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
1017
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1018
+ name: ["fetch"],
1019
+ root: file.path,
1020
+ path: node_path.default.resolve(root, ".kubb/client.ts")
1021
+ }),
1022
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1023
+ name: ["mergeConfig"],
1024
+ root: file.path,
1025
+ path: node_path.default.resolve(root, ".kubb/client.ts")
1026
+ }),
1027
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1028
+ name: [
1029
+ "Client",
1030
+ "RequestConfig",
1031
+ "ResponseErrorConfig"
1032
+ ],
1033
+ root: file.path,
1034
+ path: node_path.default.resolve(root, ".kubb/client.ts"),
1035
+ isTypeOnly: true
1036
+ })
1037
+ ] }),
1038
+ hasFormData && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1039
+ name: ["buildFormData"],
1040
+ root: file.path,
1041
+ path: node_path.default.resolve(root, ".kubb/config.ts")
1042
+ }),
1043
+ Array.from(typeImportsByFile.entries()).map(([filePath, importSet]) => {
1044
+ const typeFile = typeFilesByPath.get(filePath);
1045
+ if (!typeFile) return null;
1046
+ const importNames = Array.from(importSet).filter(Boolean);
1047
+ if (importNames.length === 0) return null;
1048
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1049
+ name: importNames,
1050
+ root: file.path,
1051
+ path: typeFile.path,
1052
+ isTypeOnly: true
1053
+ }, filePath);
1054
+ }),
1055
+ parser === "zod" && Array.from(zodImportsByFile.entries()).map(([filePath, importSet]) => {
1056
+ const zodFile = zodFilesByPath.get(filePath);
1057
+ if (!zodFile) 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: zodFile.path
1064
+ }, filePath);
1065
+ }),
1066
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(ClassClient, {
1067
+ name,
1068
+ operations: ops,
1069
+ baseURL,
1070
+ dataReturnType,
1071
+ pathParamsType,
1072
+ paramsCasing,
1073
+ paramsType,
1074
+ parser
1075
+ })
1076
+ ]
1077
+ }, file.path);
1078
+ });
1079
+ if (sdk) {
1080
+ const sdkFile = resolver.resolveFile({
1081
+ name: sdk.className,
1082
+ extname: ".ts"
1083
+ }, {
1084
+ root,
1085
+ output,
1086
+ group
1087
+ });
1088
+ files.push(/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
1089
+ baseName: sdkFile.baseName,
1090
+ path: sdkFile.path,
1091
+ meta: sdkFile.meta,
1092
+ banner: resolver.resolveBanner(adapter.inputNode, {
1093
+ output,
1094
+ config
1095
+ }),
1096
+ footer: resolver.resolveFooter(adapter.inputNode, {
1097
+ output,
1098
+ config
1099
+ }),
1100
+ children: [
1101
+ importPath ? /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1102
+ name: ["Client", "RequestConfig"],
1103
+ path: importPath,
1104
+ isTypeOnly: true
1105
+ }) : /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1106
+ name: ["Client", "RequestConfig"],
1107
+ root: sdkFile.path,
1108
+ path: node_path.default.resolve(root, ".kubb/client.ts"),
1109
+ isTypeOnly: true
1110
+ }),
1111
+ controllers.map(({ name, file }) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1112
+ name: [name],
1113
+ root: sdkFile.path,
1114
+ path: file.path
1115
+ }, name)),
1116
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(WrapperClient, {
1117
+ name: sdk.className,
1118
+ controllers: controllers.map(({ name, propertyName }) => ({
1119
+ className: name,
1120
+ propertyName
1121
+ }))
1122
+ })
1123
+ ]
1124
+ }, sdkFile.path));
1125
+ }
1126
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: files });
1127
+ }
1128
+ });
1129
+ //#endregion
1130
+ //#region src/generators/clientGenerator.tsx
1131
+ const clientGenerator = (0, _kubb_core.defineGenerator)({
1132
+ name: "client",
1133
+ renderer: _kubb_renderer_jsx.jsxRenderer,
1134
+ operation(node, ctx) {
1135
+ const { adapter, config, driver, resolver, root } = ctx;
1136
+ const { output, urlType, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, group } = ctx.options;
1137
+ const baseURL = ctx.options.baseURL ?? adapter.inputNode?.meta?.baseURL;
1138
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1139
+ if (!pluginTs) return null;
1140
+ const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1141
+ const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
1142
+ const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : void 0;
1143
+ const importedTypeNames = resolveOperationTypeNames(node, tsResolver, { paramsCasing });
1144
+ const importedZodNames = zodResolver && parser === "zod" ? [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((name) => Boolean(name)) : [];
1145
+ const meta = {
1146
+ name: resolver.resolveName(node.operationId),
1147
+ urlName: resolver.resolveUrlName(node),
1148
+ file: resolver.resolveFile({
1149
+ name: node.operationId,
1150
+ extname: ".ts",
1151
+ tag: node.tags[0] ?? "default",
1152
+ path: node.path
1153
+ }, {
1154
+ root,
1155
+ output,
1156
+ group
1157
+ }),
1158
+ fileTs: tsResolver.resolveFile({
1159
+ name: node.operationId,
1160
+ extname: ".ts",
1161
+ tag: node.tags[0] ?? "default",
1162
+ path: node.path
1163
+ }, {
1164
+ root,
1165
+ output: pluginTs.options?.output ?? output,
1166
+ group: pluginTs.options?.group
1167
+ }),
1168
+ fileZod: zodResolver && pluginZod?.options ? zodResolver.resolveFile({
1169
+ name: node.operationId,
1170
+ extname: ".ts",
1171
+ tag: node.tags[0] ?? "default",
1172
+ path: node.path
1173
+ }, {
1174
+ root,
1175
+ output: pluginZod.options.output ?? output,
1176
+ group: pluginZod.options?.group
1177
+ }) : void 0
1178
+ };
1179
+ const hasFormData = node.requestBody?.content?.some((e) => e.contentType === "multipart/form-data") ?? false;
1180
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
1181
+ baseName: meta.file.baseName,
1182
+ path: meta.file.path,
1183
+ meta: meta.file.meta,
1184
+ banner: resolver.resolveBanner(adapter.inputNode, {
1185
+ output,
1186
+ config
1187
+ }),
1188
+ footer: resolver.resolveFooter(adapter.inputNode, {
1189
+ output,
1190
+ config
1191
+ }),
1192
+ children: [
1193
+ 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, {
1194
+ name: "fetch",
1195
+ path: importPath
1196
+ }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1197
+ name: [
1198
+ "Client",
1199
+ "RequestConfig",
1200
+ "ResponseErrorConfig"
1201
+ ],
1202
+ path: importPath,
1203
+ isTypeOnly: true
1204
+ })] }) : /* @__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, {
1205
+ name: ["fetch"],
1206
+ root: meta.file.path,
1207
+ path: node_path.default.resolve(root, ".kubb/client.ts")
1208
+ }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1209
+ name: [
1210
+ "Client",
1211
+ "RequestConfig",
1212
+ "ResponseErrorConfig"
1213
+ ],
1214
+ root: meta.file.path,
1215
+ path: node_path.default.resolve(root, ".kubb/client.ts"),
1216
+ isTypeOnly: true
1217
+ })] }),
1218
+ hasFormData && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1219
+ name: ["buildFormData"],
1220
+ root: meta.file.path,
1221
+ path: node_path.default.resolve(root, ".kubb/config.ts")
1222
+ }),
1223
+ meta.fileZod && importedZodNames.length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1224
+ name: importedZodNames,
1225
+ root: meta.file.path,
1226
+ path: meta.fileZod.path
1227
+ }),
1228
+ meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1229
+ name: Array.from(new Set(importedTypeNames)),
1230
+ root: meta.file.path,
1231
+ path: meta.fileTs.path,
1232
+ isTypeOnly: true
1233
+ }),
1234
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Url, {
1235
+ name: meta.urlName,
1236
+ baseURL,
1237
+ pathParamsType,
1238
+ paramsCasing,
1239
+ paramsType,
1240
+ node,
1241
+ tsResolver,
1242
+ isIndexable: urlType === "export",
1243
+ isExportable: urlType === "export"
1244
+ }),
1245
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Client, {
1246
+ name: meta.name,
1247
+ urlName: meta.urlName,
1248
+ baseURL,
1249
+ dataReturnType,
1250
+ pathParamsType,
1251
+ paramsCasing,
1252
+ paramsType,
1253
+ node,
1254
+ tsResolver,
1255
+ zodResolver,
1256
+ parser
1257
+ })
1258
+ ]
1259
+ });
1260
+ }
1261
+ });
1262
+ //#endregion
1263
+ //#region src/generators/groupedClientGenerator.tsx
1264
+ const groupedClientGenerator = (0, _kubb_core.defineGenerator)({
1265
+ name: "groupedClient",
1266
+ renderer: _kubb_renderer_jsx.jsxRenderer,
1267
+ operations(nodes, ctx) {
1268
+ const { config, resolver, adapter, root } = ctx;
1269
+ const { output, group } = ctx.options;
1270
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: nodes.reduce((acc, operationNode) => {
1271
+ if (group?.type === "tag") {
1272
+ const tag = operationNode.tags[0];
1273
+ const name = tag ? group?.name?.({ group: camelCase(tag) }) : void 0;
1274
+ if (!tag || !name) return acc;
1275
+ const file = resolver.resolveFile({
1276
+ name,
1277
+ extname: ".ts",
1278
+ tag
1279
+ }, {
1280
+ root,
1281
+ output,
1282
+ group
1283
+ });
1284
+ const clientFile = resolver.resolveFile({
1285
+ name: operationNode.operationId,
1286
+ extname: ".ts",
1287
+ tag: operationNode.tags[0] ?? "default",
1288
+ path: operationNode.path
1289
+ }, {
1290
+ root,
1291
+ output,
1292
+ group
1293
+ });
1294
+ const client = {
1295
+ name: resolver.resolveName(operationNode.operationId),
1296
+ file: clientFile
1297
+ };
1298
+ const previous = acc.find((item) => item.file.path === file.path);
1299
+ if (previous) previous.clients.push(client);
1300
+ else acc.push({
1301
+ name,
1302
+ file,
1303
+ clients: [client]
1304
+ });
1305
+ }
1306
+ return acc;
1307
+ }, []).map(({ name, file, clients }) => {
1308
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
1309
+ baseName: file.baseName,
1310
+ path: file.path,
1311
+ meta: file.meta,
1312
+ banner: resolver.resolveBanner(adapter.inputNode, {
1313
+ output,
1314
+ config
1315
+ }),
1316
+ footer: resolver.resolveFooter(adapter.inputNode, {
1317
+ output,
1318
+ config
1319
+ }),
1320
+ children: [clients.map((client) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1321
+ name: [client.name],
1322
+ root: file.path,
1323
+ path: client.file.path
1324
+ }, client.name)), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1325
+ name,
1326
+ isExportable: true,
1327
+ isIndexable: true,
1328
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1329
+ export: true,
1330
+ name,
1331
+ children: `return { ${clients.map((client) => client.name).join(", ")} }`
1332
+ })
1333
+ })]
1334
+ }, file.path);
1335
+ }) });
1336
+ }
1337
+ });
1338
+ //#endregion
1339
+ //#region src/components/Operations.tsx
1340
+ function Operations({ name, nodes }) {
1341
+ const operationsObject = {};
1342
+ nodes.forEach((node) => {
1343
+ operationsObject[node.operationId] = {
1344
+ path: new URLPath(node.path).URL,
1345
+ method: node.method.toLowerCase()
1346
+ };
1347
+ });
1348
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1349
+ name,
1350
+ isExportable: true,
1351
+ isIndexable: true,
1352
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Const, {
1353
+ name,
1354
+ export: true,
1355
+ children: JSON.stringify(operationsObject, void 0, 2)
1356
+ })
1357
+ });
1358
+ }
1359
+ //#endregion
1360
+ //#region src/generators/operationsGenerator.tsx
1361
+ const operationsGenerator = (0, _kubb_core.defineGenerator)({
1362
+ name: "client",
1363
+ renderer: _kubb_renderer_jsx.jsxRenderer,
1364
+ operations(nodes, ctx) {
1365
+ const { config, resolver, adapter, root } = ctx;
1366
+ const { output, group } = ctx.options;
1367
+ const name = "operations";
1368
+ const file = resolver.resolveFile({
1369
+ name,
1370
+ extname: ".ts"
1371
+ }, {
1372
+ root,
1373
+ output,
1374
+ group
1375
+ });
1376
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File, {
1377
+ baseName: file.baseName,
1378
+ path: file.path,
1379
+ meta: file.meta,
1380
+ banner: resolver.resolveBanner(adapter.inputNode, {
1381
+ output,
1382
+ config
1383
+ }),
1384
+ footer: resolver.resolveFooter(adapter.inputNode, {
1385
+ output,
1386
+ config
1387
+ }),
1388
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(Operations, {
1389
+ name,
1390
+ nodes
1391
+ })
1392
+ });
1393
+ }
1394
+ });
1395
+ //#endregion
1396
+ //#region src/components/StaticClassClient.tsx
1397
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1398
+ function generateMethod({ node, name, tsResolver, zodResolver, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
1399
+ const path = new URLPath(node.path, { casing: paramsCasing });
1400
+ const { defaultContentType: contentType, isMultipleContentTypes, hasFormData } = getContentTypeInfo(node);
1401
+ const isFormData = !isMultipleContentTypes && contentType === "multipart/form-data";
1402
+ const { header: headerParams } = getOperationParameters(node);
1403
+ const headerParamsName = headerParams.length > 0 ? tsResolver.resolveHeaderParamsName(node, headerParams[0]) : void 0;
1404
+ const headers = isMultipleContentTypes ? headerParamsName ? ["...headers"] : [] : buildHeaders(contentType, !!headerParamsName);
1405
+ const generics = buildGenerics(node, tsResolver);
1406
+ const paramsNode = buildClientParamsNode({
1407
+ paramsType,
1408
+ paramsCasing,
1409
+ pathParamsType,
1410
+ node,
1411
+ tsResolver,
1412
+ isConfigurable: true
1413
+ });
1414
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1415
+ const clientParams = buildClassClientParams({
1416
+ node,
1417
+ path,
1418
+ baseURL,
1419
+ tsResolver,
1420
+ isFormData,
1421
+ isMultipleContentTypes,
1422
+ hasFormData,
1423
+ headers
1424
+ });
1425
+ const jsdoc = buildJSDoc(buildOperationComments(node, {
1426
+ link: "urlPath",
1427
+ linkPosition: "beforeDeprecated",
1428
+ splitLines: true
1429
+ }));
1430
+ const requestDataLine = buildRequestDataLine({
1431
+ parser,
1432
+ node,
1433
+ zodResolver
1434
+ });
1435
+ const formDataLine = buildFormDataLine(isFormData || isMultipleContentTypes && hasFormData, !!node.requestBody?.content?.[0]?.schema);
1436
+ const returnStatement = buildReturnStatement({
1437
+ dataReturnType,
1438
+ parser,
1439
+ node,
1440
+ zodResolver
1441
+ });
1442
+ return `${jsdoc} static async ${name}(${paramsSignature}) {\n${[
1443
+ `const { client: request = fetch, ${isMultipleContentTypes ? `contentType = ${JSON.stringify(contentType)}, ` : ""}...requestConfig } = mergeConfig(this.#config, config)`,
1444
+ "",
1445
+ requestDataLine,
1446
+ formDataLine,
1447
+ `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
1448
+ returnStatement
1449
+ ].filter(Boolean).map((line) => ` ${line}`).join("\n")}\n }`;
1450
+ }
1451
+ function StaticClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
1452
+ const classCode = `export class ${name} {\n static #config: Partial<RequestConfig> & { client?: Client } = {}\n\n${operations.map(({ node, name: methodName, tsResolver, zodResolver }) => generateMethod({
1453
+ node,
1454
+ name: methodName,
1455
+ tsResolver,
1456
+ zodResolver,
1457
+ baseURL,
1458
+ dataReturnType,
1459
+ parser,
1460
+ paramsType,
1461
+ paramsCasing,
1462
+ pathParamsType
1463
+ })).join("\n\n")}\n}`;
1464
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File.Source, {
1465
+ name,
1466
+ isExportable,
1467
+ isIndexable,
1468
+ children: [classCode, children]
1469
+ });
1470
+ }
1471
+ //#endregion
1472
+ //#region src/generators/staticClassClientGenerator.tsx
1473
+ function resolveTypeImportNames(node, tsResolver) {
1474
+ return resolveOperationTypeNames(node, tsResolver, { order: "body-response-first" });
1475
+ }
1476
+ function resolveZodImportNames(node, zodResolver) {
1477
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
1478
+ }
1479
+ const staticClassClientGenerator = (0, _kubb_core.defineGenerator)({
1480
+ name: "staticClassClient",
1481
+ renderer: _kubb_renderer_jsx.jsxRenderer,
1482
+ operations(nodes, ctx) {
1483
+ const { adapter, config, driver, resolver, root } = ctx;
1484
+ const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath } = ctx.options;
1485
+ const baseURL = ctx.options.baseURL ?? adapter.inputNode?.meta?.baseURL;
1486
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1487
+ if (!pluginTs) return null;
1488
+ const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
1489
+ const tsPluginOptions = pluginTs.options;
1490
+ const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
1491
+ const zodResolver = pluginZod ? driver.getResolver(_kubb_plugin_zod.pluginZodName) : void 0;
1492
+ function buildOperationData(node) {
1493
+ const typeFile = tsResolver.resolveFile({
1494
+ name: node.operationId,
1495
+ extname: ".ts",
1496
+ tag: node.tags[0] ?? "default",
1497
+ path: node.path
1498
+ }, {
1499
+ root,
1500
+ output: tsPluginOptions?.output ?? output,
1501
+ group: tsPluginOptions?.group
1502
+ });
1503
+ const zodFile = zodResolver && pluginZod?.options ? zodResolver.resolveFile({
1504
+ name: node.operationId,
1505
+ extname: ".ts",
1506
+ tag: node.tags[0] ?? "default",
1507
+ path: node.path
1508
+ }, {
1509
+ root,
1510
+ output: pluginZod.options?.output ?? output,
1511
+ group: pluginZod.options?.group
1512
+ }) : void 0;
1513
+ return {
1514
+ node,
1515
+ name: resolver.resolveName(node.operationId),
1516
+ tsResolver,
1517
+ zodResolver,
1518
+ typeFile,
1519
+ zodFile
1520
+ };
1521
+ }
1522
+ const controllers = nodes.reduce((acc, operationNode) => {
1523
+ const tag = operationNode.tags[0];
1524
+ const groupName = tag ? group?.name?.({ group: camelCase(tag) }) ?? resolver.resolveGroupName(tag) : resolver.resolveGroupName("Client");
1525
+ if (!tag && !group) {
1526
+ const name = resolver.resolveClassName("ApiClient");
1527
+ const file = resolver.resolveFile({
1528
+ name,
1529
+ extname: ".ts"
1530
+ }, {
1531
+ root,
1532
+ output,
1533
+ group
1534
+ });
1535
+ const operationData = buildOperationData(operationNode);
1536
+ const previous = acc.find((item) => item.file.path === file.path);
1537
+ if (previous) previous.operations.push(operationData);
1538
+ else acc.push({
1539
+ name,
1540
+ file,
1541
+ operations: [operationData]
1542
+ });
1543
+ } else if (tag) {
1544
+ const name = groupName;
1545
+ const file = resolver.resolveFile({
1546
+ name,
1547
+ extname: ".ts",
1548
+ tag
1549
+ }, {
1550
+ root,
1551
+ output,
1552
+ group
1553
+ });
1554
+ const operationData = buildOperationData(operationNode);
1555
+ const previous = acc.find((item) => item.file.path === file.path);
1556
+ if (previous) previous.operations.push(operationData);
1557
+ else acc.push({
1558
+ name,
1559
+ file,
1560
+ operations: [operationData]
1561
+ });
1562
+ }
1563
+ return acc;
1564
+ }, []);
1565
+ function collectTypeImports(ops) {
1566
+ const typeImportsByFile = /* @__PURE__ */ new Map();
1567
+ const typeFilesByPath = /* @__PURE__ */ new Map();
1568
+ ops.forEach((op) => {
1569
+ const names = resolveTypeImportNames(op.node, tsResolver);
1570
+ if (!typeImportsByFile.has(op.typeFile.path)) typeImportsByFile.set(op.typeFile.path, /* @__PURE__ */ new Set());
1571
+ const imports = typeImportsByFile.get(op.typeFile.path);
1572
+ names.forEach((n) => {
1573
+ imports.add(n);
1574
+ });
1575
+ typeFilesByPath.set(op.typeFile.path, op.typeFile);
1576
+ });
1577
+ return {
1578
+ typeImportsByFile,
1579
+ typeFilesByPath
1580
+ };
1581
+ }
1582
+ function collectZodImports(ops) {
1583
+ const zodImportsByFile = /* @__PURE__ */ new Map();
1584
+ const zodFilesByPath = /* @__PURE__ */ new Map();
1585
+ ops.forEach((op) => {
1586
+ if (!op.zodFile || !zodResolver) return;
1587
+ const names = resolveZodImportNames(op.node, zodResolver);
1588
+ if (!zodImportsByFile.has(op.zodFile.path)) zodImportsByFile.set(op.zodFile.path, /* @__PURE__ */ new Set());
1589
+ const imports = zodImportsByFile.get(op.zodFile.path);
1590
+ names.forEach((n) => {
1591
+ imports.add(n);
1592
+ });
1593
+ zodFilesByPath.set(op.zodFile.path, op.zodFile);
1594
+ });
1595
+ return {
1596
+ zodImportsByFile,
1597
+ zodFilesByPath
1598
+ };
1599
+ }
1600
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: controllers.map(({ name, file, operations: ops }) => {
1601
+ const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
1602
+ const { zodImportsByFile, zodFilesByPath } = parser === "zod" ? collectZodImports(ops) : {
1603
+ zodImportsByFile: /* @__PURE__ */ new Map(),
1604
+ zodFilesByPath: /* @__PURE__ */ new Map()
1605
+ };
1606
+ const hasFormData = ops.some((op) => op.node.requestBody?.content?.some((e) => e.contentType === "multipart/form-data") ?? false);
1607
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
1608
+ baseName: file.baseName,
1609
+ path: file.path,
1610
+ meta: file.meta,
1611
+ banner: resolver.resolveBanner(adapter.inputNode, {
1612
+ output,
1613
+ config
1614
+ }),
1615
+ footer: resolver.resolveFooter(adapter.inputNode, {
1616
+ output,
1617
+ config
1618
+ }),
1619
+ children: [
1620
+ importPath ? /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
1621
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1622
+ name: "fetch",
1623
+ path: importPath
1624
+ }),
1625
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1626
+ name: ["mergeConfig"],
1627
+ path: importPath
1628
+ }),
1629
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1630
+ name: [
1631
+ "Client",
1632
+ "RequestConfig",
1633
+ "ResponseErrorConfig"
1634
+ ],
1635
+ path: importPath,
1636
+ isTypeOnly: true
1637
+ })
1638
+ ] }) : /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
1639
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1640
+ name: ["fetch"],
1641
+ root: file.path,
1642
+ path: node_path.default.resolve(root, ".kubb/client.ts")
1643
+ }),
1644
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1645
+ name: ["mergeConfig"],
1646
+ root: file.path,
1647
+ path: node_path.default.resolve(root, ".kubb/client.ts")
1648
+ }),
1649
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1650
+ name: [
1651
+ "Client",
1652
+ "RequestConfig",
1653
+ "ResponseErrorConfig"
1654
+ ],
1655
+ root: file.path,
1656
+ path: node_path.default.resolve(root, ".kubb/client.ts"),
1657
+ isTypeOnly: true
1658
+ })
1659
+ ] }),
1660
+ hasFormData && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1661
+ name: ["buildFormData"],
1662
+ root: file.path,
1663
+ path: node_path.default.resolve(root, ".kubb/config.ts")
1664
+ }),
1665
+ Array.from(typeImportsByFile.entries()).map(([filePath, importSet]) => {
1666
+ const typeFile = typeFilesByPath.get(filePath);
1667
+ if (!typeFile) return null;
1668
+ const importNames = Array.from(importSet).filter(Boolean);
1669
+ if (importNames.length === 0) return null;
1670
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
1671
+ name: importNames,
1672
+ root: file.path,
1673
+ path: typeFile.path,
1674
+ isTypeOnly: true
1675
+ }, filePath);
1676
+ }),
1677
+ parser === "zod" && Array.from(zodImportsByFile.entries()).map(([filePath, importSet]) => {
1678
+ const zodFile = zodFilesByPath.get(filePath);
1679
+ if (!zodFile) 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: zodFile.path
1686
+ }, filePath);
1687
+ }),
1688
+ /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(StaticClassClient, {
1689
+ name,
1690
+ operations: ops,
1691
+ baseURL,
1692
+ dataReturnType,
1693
+ pathParamsType,
1694
+ paramsCasing,
1695
+ paramsType,
1696
+ parser
1697
+ })
1698
+ ]
1699
+ }, file.path);
1700
+ }) });
1701
+ }
1702
+ });
1703
+ //#endregion
1704
+ //#region src/resolvers/resolverClient.ts
1705
+ /**
1706
+ * Naming convention resolver for client plugin.
1707
+ *
1708
+ * Provides default naming helpers using camelCase for functions and file paths.
1709
+ *
1710
+ * @example
1711
+ * `resolverClient.default('list pets', 'function') // → 'listPets'`
1712
+ */
1713
+ const resolverClient = (0, _kubb_core.defineResolver)(() => ({
1714
+ name: "default",
1715
+ pluginName: "plugin-client",
1716
+ default(name, type) {
1717
+ return camelCase(name, { isFile: type === "file" });
1718
+ },
1719
+ resolveName(name) {
1720
+ return this.default(name, "function");
1721
+ },
1722
+ resolvePathName(name, type) {
1723
+ return this.default(name, type);
1724
+ },
1725
+ resolveClassName(name) {
1726
+ return pascalCase(name);
1727
+ },
1728
+ resolveGroupName(name) {
1729
+ return pascalCase(name);
1730
+ },
1731
+ resolveClientPropertyName(name) {
1732
+ return camelCase(name);
1733
+ },
1734
+ resolveUrlName(node) {
1735
+ const name = this.resolveName(node.operationId);
1736
+ return `get${name.charAt(0).toUpperCase()}${name.slice(1)}Url`;
1737
+ }
1738
+ }));
1739
+ //#endregion
13
1740
  //#region src/plugin.ts
1741
+ /**
1742
+ * Canonical plugin name for `@kubb/plugin-client`, used in driver lookups and warnings.
1743
+ */
14
1744
  const pluginClientName = "plugin-client";
15
- const pluginClient = (0, _kubb_core.createPlugin)((options) => {
1745
+ /**
1746
+ * Generates type-safe HTTP client functions or classes from an OpenAPI specification.
1747
+ * Creates client APIs by walking operations and delegating to generators.
1748
+ * Writes barrel files based on the configured `barrelType`.
1749
+ *
1750
+ * @example Client generator
1751
+ * ```ts
1752
+ * import pluginClient from '@kubb/plugin-client'
1753
+ * export default defineConfig({
1754
+ * plugins: [pluginClient({ output: { path: 'clients' } })]
1755
+ * })
1756
+ * ```
1757
+ */
1758
+ const pluginClient = (0, _kubb_core.definePlugin)((options) => {
16
1759
  const { output = {
17
1760
  path: "clients",
18
1761
  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;
1762
+ }, 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
1763
  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
1764
+ const selectedGenerators = options.generators ?? [
1765
+ clientType === "staticClass" ? staticClassClientGenerator : clientType === "class" ? classClientGenerator : clientGenerator,
1766
+ group && clientType === "function" ? groupedClientGenerator : void 0,
1767
+ operations ? operationsGenerator : void 0
25
1768
  ].filter((x) => Boolean(x));
26
- const generators = options.generators ?? defaultGenerators;
1769
+ const groupConfig = group ? {
1770
+ ...group,
1771
+ name: group.name ? group.name : (ctx) => {
1772
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1773
+ return `${camelCase(ctx.group)}Controller`;
1774
+ }
1775
+ } : void 0;
27
1776
  return {
28
1777
  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: []
1778
+ options,
1779
+ dependencies: [_kubb_plugin_ts.pluginTsName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter((dependency) => Boolean(dependency)),
1780
+ hooks: { "kubb:plugin:setup"(ctx) {
1781
+ const resolver = userResolver ? {
1782
+ ...resolverClient,
1783
+ ...userResolver
1784
+ } : resolverClient;
1785
+ ctx.setOptions({
1786
+ client,
1787
+ clientType,
1788
+ bundle,
1789
+ output,
1790
+ exclude,
1791
+ include,
1792
+ override,
1793
+ group: groupConfig,
1794
+ parser,
1795
+ dataReturnType,
1796
+ importPath: resolvedImportPath,
1797
+ baseURL,
1798
+ paramsType,
1799
+ paramsCasing,
1800
+ pathParamsType,
1801
+ urlType,
1802
+ sdk,
1803
+ resolver
84
1804
  });
85
- await this.addFile({
1805
+ ctx.setResolver(resolver);
1806
+ if (userTransformer) ctx.setTransformer(userTransformer);
1807
+ for (const gen of selectedGenerators) ctx.addGenerator(gen);
1808
+ const root = node_path$1.default.resolve(ctx.config.root, ctx.config.output.path);
1809
+ if (!resolvedImportPath?.startsWith(".")) {
1810
+ const isInlineSource = bundle && !resolvedImportPath;
1811
+ ctx.injectFile({
1812
+ baseName: "client.ts",
1813
+ path: node_path$1.default.resolve(root, ".kubb/client.ts"),
1814
+ sources: [_kubb_core.ast.createSource({
1815
+ name: "client",
1816
+ nodes: isInlineSource ? [_kubb_core.ast.createText(client === "fetch" ? require_templates_clients_fetch_source.source : require_templates_clients_axios_source.source)] : [],
1817
+ isExportable: true,
1818
+ isIndexable: true
1819
+ })],
1820
+ exports: !isInlineSource && resolvedImportPath ? [_kubb_core.ast.createExport({ path: resolvedImportPath })] : []
1821
+ });
1822
+ }
1823
+ ctx.injectFile({
86
1824
  baseName: "config.ts",
87
- path: node_path.default.resolve(root, ".kubb/config.ts"),
88
- sources: [{
1825
+ path: node_path$1.default.resolve(root, ".kubb/config.ts"),
1826
+ sources: [_kubb_core.ast.createSource({
89
1827
  name: "config",
90
- value: require_templates_config_source.source,
1828
+ nodes: [_kubb_core.ast.createText(require_templates_config_source.source)],
91
1829
  isExportable: false,
92
1830
  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 }
1831
+ })]
118
1832
  });
119
- await this.upsertFile(...barrelFiles);
120
- }
1833
+ } }
121
1834
  };
122
1835
  });
123
1836
  //#endregion
1837
+ exports.Client = Client;
1838
+ exports.classClientGenerator = classClientGenerator;
1839
+ exports.clientGenerator = clientGenerator;
1840
+ exports.default = pluginClient;
1841
+ exports.groupedClientGenerator = groupedClientGenerator;
1842
+ exports.operationsGenerator = operationsGenerator;
124
1843
  exports.pluginClient = pluginClient;
125
1844
  exports.pluginClientName = pluginClientName;
1845
+ exports.resolverClient = resolverClient;
1846
+ exports.staticClassClientGenerator = staticClassClientGenerator;
126
1847
 
127
1848
  //# sourceMappingURL=index.cjs.map