@kubb/plugin-client 5.0.0-beta.22 → 5.0.0-beta.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -50,9 +50,10 @@ type ResolverClient = Resolver & {
50
50
  */
51
51
  type ClientImportPath = {
52
52
  /**
53
- * Which client should be used to do the HTTP calls.
54
- * - 'axios' uses axios client for HTTP requests.
55
- * - 'fetch' uses native fetch API for HTTP requests.
53
+ * HTTP client used by the generated code.
54
+ * - `'axios'` imports from `@kubb/plugin-client/clients/axios`. Requires `axios` at runtime.
55
+ * - `'fetch'` imports from `@kubb/plugin-client/clients/fetch`. Uses the global `fetch`.
56
+ *
56
57
  * @default 'axios'
57
58
  */
58
59
  client?: 'axios' | 'fetch';
@@ -60,9 +61,12 @@ type ClientImportPath = {
60
61
  } | {
61
62
  client?: never;
62
63
  /**
63
- * Client import path for API calls.
64
- * Used as `import client from '${importPath}'`.
65
- * Accepts relative and absolute paths; path changes are not performed.
64
+ * Path to a custom client module. Generated files import their HTTP runtime from here
65
+ * instead of `@kubb/plugin-client/clients/{client}`. Accepts both relative paths and
66
+ * bare module specifiers; the value is used as-is.
67
+ *
68
+ * @note When combined with a query plugin, the module must export `Client`,
69
+ * `RequestConfig`, and `ResponseErrorConfig` types.
66
70
  */
67
71
  importPath: string;
68
72
  /**
@@ -82,115 +86,123 @@ type ClientImportPath = {
82
86
  */
83
87
  type ParamsTypeOptions = {
84
88
  /**
85
- * All parameters path, query, headers, and body are merged into a single
89
+ * Every operation parameter (path, query, headers, body) is wrapped in a single
86
90
  * destructured object argument.
87
- * - 'object' returns the params and pathParams as an object.
88
- * @default 'inline'
89
91
  */
90
92
  paramsType: 'object';
91
93
  /**
92
94
  * `pathParamsType` has no effect when `paramsType` is `'object'`.
93
- * Path params are already inside the single destructured object.
95
+ * Path params already live inside the single destructured object.
94
96
  */
95
97
  pathParamsType?: never;
96
98
  } | {
97
99
  /**
98
- * Each parameter group is emitted as a separate function argument.
99
- * - 'inline' returns the params as comma separated params.
100
+ * Each parameter group is emitted as a separate positional function argument.
101
+ *
100
102
  * @default 'inline'
101
103
  */
102
104
  paramsType?: 'inline';
103
105
  /**
104
- * Controls how path parameters are arranged within the inline argument list.
105
- * - 'object' groups path params into a destructured object: `{ petId }: PathParams`.
106
- * - 'inline' emits each path param as its own argument: `petId: string`.
106
+ * How URL path parameters are arranged inside the inline argument list.
107
+ * - `'object'` groups them into one destructured object: `{ petId }: PathParams`.
108
+ * - `'inline'` emits each path param as its own argument: `petId: string`.
109
+ *
107
110
  * @default 'inline'
108
111
  */
109
112
  pathParamsType?: 'object' | 'inline';
110
113
  };
111
114
  type Options = {
112
115
  /**
113
- * Specify the export location for the files and define the behavior of the output.
114
- * @default { path: 'clients', barrelType: 'named' }
116
+ * Where the generated client files are written and how they are exported.
117
+ *
118
+ * @default { path: 'clients', barrel: { type: 'named' } }
115
119
  */
116
120
  output?: Output;
117
121
  /**
118
- * Group the clients based on the provided name.
122
+ * Split generated files into subfolders based on the operation's tag.
119
123
  */
120
124
  group?: Group;
121
125
  /**
122
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
126
+ * Skip operations matching at least one entry in the list.
123
127
  */
124
128
  exclude?: Array<Exclude>;
125
129
  /**
126
- * Array containing include parameters to include tags/operations/methods/paths.
130
+ * Restrict generation to operations matching at least one entry in the list.
127
131
  */
128
132
  include?: Array<Include>;
129
133
  /**
130
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
134
+ * Apply a different options object to operations matching a pattern.
131
135
  */
132
136
  override?: Array<Override<ResolvedOptions>>;
133
137
  /**
134
- * Create `operations.ts` file with all operations grouped by methods.
138
+ * Emit an `operations.ts` file that re-exports every generated function grouped by HTTP method.
139
+ *
135
140
  * @default false
136
141
  */
137
142
  operations?: boolean;
138
143
  /**
139
- * Export urls that are used by operation x.
140
- * - 'export' makes them part of your barrel file.
141
- * - false does not make them exportable.
144
+ * Whether to also export the URL builder helpers (`get<Operation>Url`).
145
+ * - `'export'` exposes them via the barrel.
146
+ * - `false` keeps them private.
147
+ *
142
148
  * @default false
143
- * @example getGetPetByIdUrl
144
149
  */
145
150
  urlType?: 'export' | false;
146
151
  /**
147
- * Allows you to set a custom base url for all generated calls.
152
+ * Base URL prepended to every request. When omitted, falls back to the adapter's
153
+ * server URL (typically `servers[0].url`).
148
154
  */
149
155
  baseURL?: string;
150
156
  /**
151
- * ReturnType that is used when calling the client.
152
- * - 'data' returns ResponseConfig[data].
153
- * - 'full' returns ResponseConfig.
157
+ * Shape of the value returned by each generated client function.
158
+ * - `'data'` only the response body.
159
+ * - `'full'` the full response config (body, status, headers, request).
160
+ *
154
161
  * @default 'data'
155
162
  */
156
163
  dataReturnType?: 'data' | 'full';
157
164
  /**
158
- * How to style your params, by default no casing is applied.
159
- * - 'camelcase' uses camelCase for pathParams, queryParams and headerParams names
160
- * @note response types (data/body) are not affected by this option
165
+ * Rename parameter properties in the generated client (path, query, headers).
166
+ * The HTTP request still uses the original spec names; Kubb writes the mapping for you.
167
+ *
168
+ * @note Use the same value on `@kubb/plugin-ts` so types stay compatible.
161
169
  */
162
170
  paramsCasing?: 'camelcase';
163
171
  /**
164
- * Which parser can be used before returning the data.
165
- * - 'client' returns the data as-is from the client.
166
- * - 'zod' uses @kubb/plugin-zod to parse the data.
172
+ * Validator applied to response bodies before they are returned to the caller.
173
+ * - `'client'` no validation. Trusts the API.
174
+ * - `'zod'` pipes responses through schemas from `@kubb/plugin-zod`.
175
+ *
167
176
  * @default 'client'
168
177
  */
169
178
  parser?: 'client' | 'zod';
170
179
  /**
171
- * How to generate the client code.
172
- * - 'function' generates standalone functions for each operation.
173
- * - 'class' generates a class with methods for each operation.
174
- * - 'staticClass' generates a class with static methods for each operation.
180
+ * Shape of the generated client.
181
+ * - `'function'` one standalone async function per operation.
182
+ * - `'class'` one class per tag with instance methods.
183
+ * - `'staticClass'` one class per tag with static methods.
184
+ *
175
185
  * @default 'function'
186
+ * @note Only `'function'` is compatible with query plugins.
176
187
  */
177
188
  clientType?: 'function' | 'class' | 'staticClass';
178
189
  /**
179
- * Bundle the selected client into the generated `.kubb` directory.
180
- * When disabled the generated clients will import the shared runtime from `@kubb/plugin-client/clients/*`.
190
+ * Copy the HTTP client runtime into the generated output so consumers do not need
191
+ * `@kubb/plugin-client` at runtime. When `false`, generated files import from
192
+ * `@kubb/plugin-client/clients/{client}`.
193
+ *
181
194
  * @default false
182
- * In version 5 of Kubb this is by default true
183
195
  */
184
196
  bundle?: boolean;
185
197
  /**
186
- * Generate an SDK facade class that composes all tag-based client classes into a single entry point.
187
- * Setting this option automatically enables `clientType: 'class'`.
198
+ * Generate a single SDK class composing every tag-based client into one entry point.
199
+ * Automatically enables `clientType: 'class'`.
200
+ *
188
201
  * @example
189
202
  * ```ts
190
203
  * pluginClient({
191
204
  * sdk: { className: 'PetStoreSDK' },
192
205
  * })
193
- * // Generates a class with a shared constructor config and one property per tag:
194
206
  * // class PetStoreSDK {
195
207
  * // readonly petController: petController
196
208
  * // readonly storeController: storeController
@@ -200,22 +212,23 @@ type Options = {
200
212
  */
201
213
  sdk?: {
202
214
  /**
203
- * Name of the generated SDK facade class.
215
+ * Name of the generated SDK facade class. Also the file name.
204
216
  */
205
217
  className: string;
206
218
  };
207
219
  /**
208
- * Override individual resolver methods. Any method you omit falls back to the
209
- * preset resolver's implementation. Use `this.default(...)` to call it.
220
+ * Override how names and file paths are built for the generated client.
221
+ * Methods you omit fall back to the default resolver. `this` is bound to the
222
+ * full resolver, so `this.default(name)` delegates to the built-in implementation.
210
223
  */
211
224
  resolver?: Partial<ResolverClient> & ThisType<ResolverClient>;
212
225
  /**
213
- * Single AST visitor applied to each node before printing.
214
- * Return `null` or `undefined` from a method to leave the node unchanged.
226
+ * AST visitor applied to each operation node before code is printed.
227
+ * Return `null` or `undefined` to leave the node unchanged.
215
228
  */
216
229
  transformer?: ast.Visitor;
217
230
  /**
218
- * Define some generators next to the client generators.
231
+ * Custom generators that run alongside the built-in client generators.
219
232
  */
220
233
  generators?: Array<Generator<PluginClient>>;
221
234
  } & ClientImportPath & ParamsTypeOptions;
@@ -224,7 +237,7 @@ type ResolvedOptions = {
224
237
  exclude: Array<Exclude>;
225
238
  include: Array<Include> | undefined;
226
239
  override: Array<Override<ResolvedOptions>>;
227
- group: Group | undefined;
240
+ group: Group | null;
228
241
  client: Options['client'];
229
242
  clientType: NonNullable<Options['clientType']>;
230
243
  bundle: NonNullable<Options['bundle']>;
@@ -264,7 +277,7 @@ type Props = {
264
277
  parser: PluginClient['resolvedOptions']['parser'] | undefined;
265
278
  node: ast.OperationNode;
266
279
  tsResolver: ResolverTs;
267
- zodResolver?: ResolverZod;
280
+ zodResolver?: ResolverZod | null;
268
281
  children?: KubbReactNode;
269
282
  };
270
283
  declare function Client({
@@ -287,35 +300,76 @@ declare function Client({
287
300
  }: Props): KubbReactNode;
288
301
  //#endregion
289
302
  //#region src/generators/classClientGenerator.d.ts
303
+ /**
304
+ * Built-in `operations` generator for `@kubb/plugin-client` when
305
+ * `clientType: 'class'`. Emits one class per tag, with one instance method
306
+ * per operation and a shared constructor for request configuration.
307
+ */
290
308
  declare const classClientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
291
309
  //#endregion
292
310
  //#region src/generators/clientGenerator.d.ts
311
+ /**
312
+ * Built-in operation generator for `@kubb/plugin-client`. Emits one async
313
+ * function per OpenAPI operation, plus the matching URL helper. Used when
314
+ * `clientType: 'function'` (the default).
315
+ */
293
316
  declare const clientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
294
317
  //#endregion
295
318
  //#region src/generators/groupedClientGenerator.d.ts
319
+ /**
320
+ * Emits one aggregate file per tag/group when `group` is configured. Each
321
+ * file re-exports every client function for that group, so callers can
322
+ * `import { petController } from './gen/clients'` instead of importing
323
+ * each operation individually.
324
+ */
296
325
  declare const groupedClientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
297
326
  //#endregion
298
327
  //#region src/generators/operationsGenerator.d.ts
328
+ /**
329
+ * Generates an `operations.ts` file that re-exports every operation grouped
330
+ * by HTTP method. Enabled when `pluginClient({ operations: true })`. Useful
331
+ * for building meta-tooling on top of the generated client (route
332
+ * registries, API explorers).
333
+ */
299
334
  declare const operationsGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
300
335
  //#endregion
301
336
  //#region src/generators/staticClassClientGenerator.d.ts
337
+ /**
338
+ * Built-in `operations` generator for `@kubb/plugin-client` when
339
+ * `clientType: 'staticClass'`. Emits one class per tag, with a static method
340
+ * per operation so callers can use `Pet.getPetById(...)` without
341
+ * instantiating the class.
342
+ */
302
343
  declare const staticClassClientGenerator: _$_kubb_core0.Generator<PluginClient, unknown>;
303
344
  //#endregion
304
345
  //#region src/plugin.d.ts
305
346
  /**
306
- * Canonical plugin name for `@kubb/plugin-client`, used in driver lookups and warnings.
347
+ * Canonical plugin name for `@kubb/plugin-client`. Used for driver lookups and
348
+ * cross-plugin dependency references.
307
349
  */
308
350
  declare const pluginClientName = "plugin-client";
309
351
  /**
310
- * Generates type-safe HTTP client functions or classes from an OpenAPI specification.
311
- * Creates client APIs by walking operations and delegating to generators.
312
- * Writes barrel files based on the configured `barrelType`.
352
+ * Generates one HTTP client function per OpenAPI operation. Each function has
353
+ * typed path params, query params, body, and response, so callers use the API
354
+ * like any other typed function. Ships with `axios` and `fetch` runtimes; bring
355
+ * your own by setting `importPath`.
313
356
  *
314
- * @example Client generator
357
+ * @example
315
358
  * ```ts
316
- * import pluginClient from '@kubb/plugin-client'
359
+ * import { defineConfig } from 'kubb'
360
+ * import { pluginTs } from '@kubb/plugin-ts'
361
+ * import { pluginClient } from '@kubb/plugin-client'
362
+ *
317
363
  * export default defineConfig({
318
- * plugins: [pluginClient({ output: { path: 'clients' } })]
364
+ * input: { path: './petStore.yaml' },
365
+ * output: { path: './src/gen' },
366
+ * plugins: [
367
+ * pluginTs(),
368
+ * pluginClient({
369
+ * output: { path: './clients' },
370
+ * client: 'fetch',
371
+ * }),
372
+ * ],
319
373
  * })
320
374
  * ```
321
375
  */
@@ -323,12 +377,18 @@ declare const pluginClient: (options?: Options | undefined) => _$_kubb_core0.Plu
323
377
  //#endregion
324
378
  //#region src/resolvers/resolverClient.d.ts
325
379
  /**
326
- * Naming convention resolver for client plugin.
380
+ * Default resolver used by `@kubb/plugin-client`. Decides the names and file
381
+ * paths for every generated client function or class. Functions and files use
382
+ * camelCase; classes and tag groups use PascalCase.
327
383
  *
328
- * Provides default naming helpers using camelCase for functions and file paths.
384
+ * @example Resolve client function and class names
385
+ * ```ts
386
+ * import { resolverClient } from '@kubb/plugin-client'
329
387
  *
330
- * @example
331
- * `resolverClient.default('list pets', 'function') // 'listPets'`
388
+ * resolverClient.default('list pets', 'function') // 'listPets'
389
+ * resolverClient.resolveClassName('pet') // 'Pet'
390
+ * resolverClient.resolveUrlName(operationNode) // 'getShowPetByIdUrl'
391
+ * ```
332
392
  */
333
393
  declare const resolverClient: ResolverClient;
334
394
  //#endregion