@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/clients/fetch.cjs.map +1 -1
- package/dist/clients/fetch.d.ts +1 -1
- package/dist/clients/fetch.js.map +1 -1
- package/dist/index.cjs +135 -88
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +125 -65
- package/dist/index.js +135 -88
- package/dist/index.js.map +1 -1
- package/dist/templates/clients/fetch.source.cjs +1 -1
- package/dist/templates/clients/fetch.source.js +1 -1
- package/extension.yaml +774 -260
- package/package.json +6 -6
- package/src/clients/fetch.ts +1 -1
- package/src/components/ClassClient.tsx +3 -3
- package/src/components/Client.tsx +17 -17
- package/src/components/StaticClassClient.tsx +3 -3
- package/src/components/Url.tsx +1 -1
- package/src/functionParams.ts +8 -8
- package/src/generators/classClientGenerator.tsx +16 -11
- package/src/generators/clientGenerator.tsx +16 -8
- package/src/generators/groupedClientGenerator.tsx +9 -3
- package/src/generators/operationsGenerator.tsx +7 -1
- package/src/generators/staticClassClientGenerator.tsx +16 -10
- package/src/plugin.ts +24 -11
- package/src/resolvers/resolverClient.ts +10 -4
- package/src/types.ts +66 -53
- package/src/utils.ts +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -50,9 +50,10 @@ type ResolverClient = Resolver & {
|
|
|
50
50
|
*/
|
|
51
51
|
type ClientImportPath = {
|
|
52
52
|
/**
|
|
53
|
-
*
|
|
54
|
-
* - 'axios'
|
|
55
|
-
* - 'fetch'
|
|
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
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
105
|
-
* - 'object' groups
|
|
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
|
-
*
|
|
114
|
-
*
|
|
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
|
-
*
|
|
122
|
+
* Split generated files into subfolders based on the operation's tag.
|
|
119
123
|
*/
|
|
120
124
|
group?: Group;
|
|
121
125
|
/**
|
|
122
|
-
*
|
|
126
|
+
* Skip operations matching at least one entry in the list.
|
|
123
127
|
*/
|
|
124
128
|
exclude?: Array<Exclude>;
|
|
125
129
|
/**
|
|
126
|
-
*
|
|
130
|
+
* Restrict generation to operations matching at least one entry in the list.
|
|
127
131
|
*/
|
|
128
132
|
include?: Array<Include>;
|
|
129
133
|
/**
|
|
130
|
-
*
|
|
134
|
+
* Apply a different options object to operations matching a pattern.
|
|
131
135
|
*/
|
|
132
136
|
override?: Array<Override<ResolvedOptions>>;
|
|
133
137
|
/**
|
|
134
|
-
*
|
|
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
|
-
*
|
|
140
|
-
* - 'export'
|
|
141
|
-
* - false
|
|
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
|
-
*
|
|
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
|
-
*
|
|
152
|
-
* - 'data'
|
|
153
|
-
* - 'full'
|
|
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
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
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
|
-
*
|
|
165
|
-
* - 'client'
|
|
166
|
-
* - 'zod'
|
|
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
|
-
*
|
|
172
|
-
* - 'function'
|
|
173
|
-
* - 'class'
|
|
174
|
-
* - 'staticClass'
|
|
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
|
-
*
|
|
180
|
-
* When
|
|
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
|
|
187
|
-
*
|
|
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
|
|
209
|
-
*
|
|
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
|
-
*
|
|
214
|
-
* Return `null` or `undefined`
|
|
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
|
-
*
|
|
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 |
|
|
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
|
|
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
|
|
311
|
-
*
|
|
312
|
-
*
|
|
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
|
|
357
|
+
* @example
|
|
315
358
|
* ```ts
|
|
316
|
-
* import
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
384
|
+
* @example Resolve client function and class names
|
|
385
|
+
* ```ts
|
|
386
|
+
* import { resolverClient } from '@kubb/plugin-client'
|
|
329
387
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
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
|