@kubb/plugin-vue-query 5.0.0-beta.42 → 5.0.0-beta.64

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 (43) hide show
  1. package/dist/{components-Bxe1EuWf.js → components-CAlEf7Oh.js} +273 -388
  2. package/dist/components-CAlEf7Oh.js.map +1 -0
  3. package/dist/{components-BwFPMwK7.cjs → components-CfU59l8V.cjs} +274 -389
  4. package/dist/components-CfU59l8V.cjs.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.ts +1 -1
  7. package/dist/components.js +1 -1
  8. package/dist/{generators-BSN6A0ED.cjs → generators-DpMLVmyi.cjs} +91 -137
  9. package/dist/generators-DpMLVmyi.cjs.map +1 -0
  10. package/dist/{generators-D9TUvYRN.js → generators-fWBjs0CN.js} +93 -139
  11. package/dist/generators-fWBjs0CN.js.map +1 -0
  12. package/dist/generators.cjs +1 -1
  13. package/dist/generators.d.ts +1 -1
  14. package/dist/generators.js +1 -1
  15. package/dist/index.cjs +41 -18
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +42 -19
  19. package/dist/index.js.map +1 -1
  20. package/dist/{types-HHnnlEhK.d.ts → types-C6a_58nb.d.ts} +12 -16
  21. package/package.json +10 -18
  22. package/dist/components-BwFPMwK7.cjs.map +0 -1
  23. package/dist/components-Bxe1EuWf.js.map +0 -1
  24. package/dist/generators-BSN6A0ED.cjs.map +0 -1
  25. package/dist/generators-D9TUvYRN.js.map +0 -1
  26. package/extension.yaml +0 -1248
  27. package/src/components/InfiniteQuery.tsx +0 -127
  28. package/src/components/InfiniteQueryOptions.tsx +0 -194
  29. package/src/components/Mutation.tsx +0 -150
  30. package/src/components/MutationKey.tsx +0 -1
  31. package/src/components/Query.tsx +0 -126
  32. package/src/components/QueryKey.tsx +0 -52
  33. package/src/components/QueryOptions.tsx +0 -137
  34. package/src/components/index.ts +0 -7
  35. package/src/generators/index.ts +0 -3
  36. package/src/generators/infiniteQueryGenerator.tsx +0 -200
  37. package/src/generators/mutationGenerator.tsx +0 -158
  38. package/src/generators/queryGenerator.tsx +0 -184
  39. package/src/index.ts +0 -2
  40. package/src/plugin.ts +0 -183
  41. package/src/resolvers/resolverVueQuery.ts +0 -76
  42. package/src/types.ts +0 -272
  43. package/src/utils.ts +0 -56
package/extension.yaml DELETED
@@ -1,1248 +0,0 @@
1
- $schema: https://kubb.dev/schemas/extension.json
2
- kind: plugin
3
- id: plugin-vue-query
4
- name: Vue Query
5
- description: Generate TanStack Query composables for Vue (useQuery, useMutation, useInfiniteQuery) from OpenAPI.
6
- category: framework
7
- type: official
8
- npmPackage: '@kubb/plugin-vue-query'
9
- docsPath: /plugins/plugin-vue-query
10
- repo: https://github.com/kubb-labs/plugins
11
- maintainers:
12
- - name: Stijn Van Hulle
13
- github: stijnvanhulle
14
- compatibility:
15
- kubb: '>=5.0.0'
16
- node: '>=22'
17
- tags:
18
- - vue-query
19
- - tanstack-query
20
- - vue
21
- - composables
22
- - data-fetching
23
- - codegen
24
- - openapi
25
- dependencies:
26
- - plugin-ts
27
- - plugin-client
28
- resources:
29
- documentation: https://kubb.dev/plugins/plugin-vue-query
30
- repository: https://github.com/kubb-labs/plugins
31
- issues: https://github.com/kubb-labs/plugins/issues
32
- changelog: https://github.com/kubb-labs/plugins/blob/main/packages/plugin-vue-query/CHANGELOG.md
33
- codesandbox: https://codesandbox.io/p/github/kubb-labs/plugins/main/examples/vue-query
34
- featured: false
35
- icon:
36
- light: https://kubb.dev/feature/tanstack.svg
37
- intro: |
38
- # @kubb/plugin-vue-query
39
-
40
- Generate one [TanStack Query](https://tanstack.com/query) composable per OpenAPI operation, ready to use inside Vue's Composition API. Queries become `useFooQuery` (and optionally `useFooInfiniteQuery`); mutations become `useFooMutation`. Each composable is fully typed end to end.
41
-
42
- Pairs with `@kubb/plugin-client` for the HTTP layer and `@kubb/plugin-ts` for types.
43
- options:
44
- - name: output
45
- type: Output
46
- required: false
47
- default: "{ path: 'hooks', barrel: { type: 'named' } }"
48
- description: Where the generated composables are written and how they are exported.
49
- properties:
50
- - name: path
51
- type: string
52
- required: true
53
- description: |
54
- Folder (or single file) where the plugin writes its generated code. The path is resolved against the global `output.path` set on `defineConfig`.
55
-
56
- Use a folder to keep each generator's output isolated (`'types'`, `'clients'`, `'hooks'`). Use a single file when you want everything in one place, for example `'api.ts'`.
57
- tip: |
58
- When `output.path` points to a single file, the `group` option cannot be used because every operation ends up in the same file.
59
- examples:
60
- - name: kubb.config.ts
61
- files:
62
- - lang: typescript
63
- twoslash: false
64
- code: |
65
- import { defineConfig } from 'kubb'
66
- import { pluginTs } from '@kubb/plugin-ts'
67
-
68
- export default defineConfig({
69
- input: { path: './petStore.yaml' },
70
- output: { path: './src/gen' },
71
- plugins: [
72
- pluginTs({
73
- output: { path: './types' },
74
- }),
75
- ],
76
- })
77
- - name: Resulting tree
78
- files:
79
- - lang: text
80
- twoslash: false
81
- code: |
82
- src/
83
- └── gen/
84
- └── types/
85
- ├── Pet.ts
86
- └── Store.ts
87
- default: "'hooks'"
88
- - name: barrel
89
- type: "{ type: 'named' | 'all', nested?: boolean } | false"
90
- required: false
91
- default: "{ type: 'named' }"
92
- description: |
93
- Controls how the generated `index.ts` (barrel) file re-exports the plugin's output.
94
-
95
- - `{ type: 'named' }` re-exports each symbol by name. Best for tree-shaking and explicit imports.
96
- - `{ type: 'all' }` uses `export *`. Smaller barrel file, but exports everything.
97
- - `{ nested: true }` creates a barrel in every subdirectory, so callers can import from any depth.
98
- - `false` skips the barrel entirely. The plugin's files are also excluded from the root `index.ts`.
99
- tip: |
100
- Pick `'named'` when consumers care about which symbols they import (better tree-shaking, friendlier auto-import). Pick `'all'` when the file count is small and you want a one-line barrel.
101
- examples:
102
- - name: "'named' (default)"
103
- files:
104
- - name: kubb.config.ts
105
- lang: typescript
106
- twoslash: false
107
- code: |
108
- import { defineConfig } from 'kubb'
109
- import { pluginTs } from '@kubb/plugin-ts'
110
-
111
- export default defineConfig({
112
- input: { path: './petStore.yaml' },
113
- output: { path: './src/gen' },
114
- plugins: [
115
- pluginTs({
116
- output: { barrel: { type: 'named' } },
117
- }),
118
- ],
119
- })
120
- - name: src/gen/types/index.ts
121
- lang: typescript
122
- twoslash: false
123
- code: |
124
- export { Pet, PetStatus } from './Pet'
125
- export { Store } from './Store'
126
- - name: "'all'"
127
- files:
128
- - name: kubb.config.ts
129
- lang: typescript
130
- twoslash: false
131
- code: |
132
- import { defineConfig } from 'kubb'
133
- import { pluginTs } from '@kubb/plugin-ts'
134
-
135
- export default defineConfig({
136
- input: { path: './petStore.yaml' },
137
- output: { path: './src/gen' },
138
- plugins: [
139
- pluginTs({
140
- output: { barrel: { type: 'all' } },
141
- }),
142
- ],
143
- })
144
- - name: src/gen/types/index.ts
145
- lang: typescript
146
- twoslash: false
147
- code: |
148
- export * from './Pet'
149
- export * from './Store'
150
- - name: nested
151
- files:
152
- - name: kubb.config.ts
153
- lang: typescript
154
- twoslash: false
155
- code: |
156
- import { defineConfig } from 'kubb'
157
- import { pluginTs } from '@kubb/plugin-ts'
158
-
159
- export default defineConfig({
160
- input: { path: './petStore.yaml' },
161
- output: { path: './src/gen' },
162
- plugins: [
163
- pluginTs({
164
- output: { barrel: { type: 'named', nested: true } },
165
- }),
166
- ],
167
- })
168
- - name: Generated tree
169
- lang: text
170
- twoslash: false
171
- code: |
172
- src/gen/types/
173
- ├── index.ts # re-exports ./petController and ./storeController
174
- ├── petController/
175
- │ ├── index.ts # re-exports Pet, Store, ...
176
- │ └── Pet.ts
177
- └── storeController/
178
- ├── index.ts
179
- └── Store.ts
180
- - name: 'false'
181
- files:
182
- - name: kubb.config.ts
183
- lang: typescript
184
- twoslash: false
185
- code: |
186
- import { defineConfig } from 'kubb'
187
- import { pluginTs } from '@kubb/plugin-ts'
188
-
189
- export default defineConfig({
190
- input: { path: './petStore.yaml' },
191
- output: { path: './src/gen' },
192
- plugins: [
193
- pluginTs({
194
- output: { barrel: false },
195
- }),
196
- ],
197
- })
198
- - name: Result
199
- lang: text
200
- twoslash: false
201
- code: |
202
- # No index.ts is generated for this plugin.
203
- # Its files are also excluded from the root index.ts.
204
- - name: banner
205
- type: 'string | ((node: RootNode) => string)'
206
- required: false
207
- description: |
208
- Text prepended to every generated file. Useful for license headers, lint disables, or `@ts-nocheck` directives.
209
-
210
- Pass a string for a static banner. Pass a function to compute the banner from each file's `RootNode` (the AST root containing path, schema, and operation context).
211
- examples:
212
- - name: Static banner
213
- files:
214
- - name: kubb.config.ts
215
- lang: typescript
216
- twoslash: false
217
- code: |
218
- import { defineConfig } from 'kubb'
219
- import { pluginTs } from '@kubb/plugin-ts'
220
-
221
- export default defineConfig({
222
- input: { path: './petStore.yaml' },
223
- output: { path: './src/gen' },
224
- plugins: [
225
- pluginTs({
226
- output: {
227
- banner: '/* eslint-disable */\n// @ts-nocheck',
228
- },
229
- }),
230
- ],
231
- })
232
- - name: Generated file
233
- lang: typescript
234
- twoslash: false
235
- code: |
236
- /* eslint-disable */
237
- // @ts-nocheck
238
- export type Pet = {
239
- id: number
240
- name: string
241
- }
242
- - name: Dynamic banner
243
- files:
244
- - name: kubb.config.ts
245
- lang: typescript
246
- twoslash: false
247
- code: |
248
- import { defineConfig } from 'kubb'
249
- import { pluginTs } from '@kubb/plugin-ts'
250
-
251
- export default defineConfig({
252
- input: { path: './petStore.yaml' },
253
- output: { path: './src/gen' },
254
- plugins: [
255
- pluginTs({
256
- output: {
257
- banner: (node) => `// Source: ${node.path}\n// Generated at ${new Date().toISOString()}`,
258
- },
259
- }),
260
- ],
261
- })
262
- - name: footer
263
- type: 'string | ((node: RootNode) => string)'
264
- required: false
265
- description: |
266
- Text appended at the end of every generated file. The mirror of `banner` — use it for closing comments, re-enabling lint rules, or marker lines.
267
-
268
- Pass a string for a static footer, or a function that receives the file's `RootNode` and returns the footer text.
269
- examples:
270
- - name: Re-enable lint after a banner disable
271
- files:
272
- - name: kubb.config.ts
273
- lang: typescript
274
- twoslash: false
275
- code: |
276
- import { defineConfig } from 'kubb'
277
- import { pluginTs } from '@kubb/plugin-ts'
278
-
279
- export default defineConfig({
280
- input: { path: './petStore.yaml' },
281
- output: { path: './src/gen' },
282
- plugins: [
283
- pluginTs({
284
- output: {
285
- banner: '/* eslint-disable */',
286
- footer: '/* eslint-enable */',
287
- },
288
- }),
289
- ],
290
- })
291
- - name: override
292
- type: boolean
293
- required: false
294
- default: 'false'
295
- description: |
296
- Allows the plugin to overwrite hand-written files that share a name with a generated file.
297
-
298
- - `false` (default): Kubb skips a file if it already exists and is not marked as generated. This protects manual edits.
299
- - `true`: Kubb overwrites any file at the target path, including hand-written ones.
300
- warning: |
301
- Enable this only when you are sure the target folder contains nothing you need to keep. Local edits are lost on the next generation.
302
- examples:
303
- - name: kubb.config.ts
304
- files:
305
- - lang: typescript
306
- twoslash: false
307
- code: |
308
- import { defineConfig } from 'kubb'
309
- import { pluginTs } from '@kubb/plugin-ts'
310
-
311
- export default defineConfig({
312
- input: { path: './petStore.yaml' },
313
- output: { path: './src/gen' },
314
- plugins: [
315
- pluginTs({
316
- output: { override: true },
317
- }),
318
- ],
319
- })
320
- - name: group
321
- type: Group
322
- required: false
323
- description: |
324
- Splits generated files into subfolders based on the operation's tag, so each tag in your OpenAPI spec gets its own directory.
325
-
326
- Without `group`, every file lands in the plugin's `output.path` folder. With `group`, files are bucketed under `{output.path}/{groupName}/`, where `groupName` is derived from the operation's first tag.
327
- tip: |
328
- Use `group` to mirror your API's domain structure (pet, store, user) in the generated code. Combine it with `output.barrel: { type: 'named', nested: true }` to get per-tag barrel files.
329
- examples:
330
- - name: kubb.config.ts
331
- files:
332
- - lang: typescript
333
- twoslash: false
334
- code: |
335
- import { defineConfig } from 'kubb'
336
- import { pluginTs } from '@kubb/plugin-ts'
337
-
338
- export default defineConfig({
339
- input: { path: './petStore.yaml' },
340
- output: { path: './src/gen' },
341
- plugins: [
342
- pluginTs({
343
- group: {
344
- type: 'tag',
345
- name: ({ group }) => `${group}Controller`,
346
- },
347
- }),
348
- ],
349
- })
350
- body: |
351
- With the configuration above, the generator emits:
352
-
353
- ```text
354
- src/gen/
355
- ├── petController/
356
- │ ├── AddPet.ts
357
- │ └── GetPet.ts
358
- └── storeController/
359
- ├── CreateStore.ts
360
- └── GetStoreById.ts
361
- ```
362
- properties:
363
- - name: type
364
- type: "'tag'"
365
- required: true
366
- description: |
367
- Property used to assign each operation to a group. Required whenever `group` is set.
368
-
369
- Today only `'tag'` is supported: Kubb reads the first tag on the operation (`operation.getTags().at(0)?.name`) and uses it as the group key. Operations without a tag are placed in a default group.
370
- note: |
371
- `Required: true*` is conditional — only required when the parent `group` option is used. `group` itself stays optional.
372
- - name: name
373
- type: '(context: GroupContext) => string'
374
- required: false
375
- default: (ctx) => `${ctx.group}Controller`
376
- description: Function that builds the folder/identifier name from a group key (the operation's first tag).
377
- - name: client
378
- type: ClientImportPath & { clientType?, dataReturnType?, baseURL?, bundle?, paramsCasing? }
379
- required: false
380
- description: |
381
- HTTP client used inside every generated composable. Each composable calls into this client to perform the request.
382
-
383
- Mirrors a subset of `pluginClient` options. Set these here when the Vue composables need different client behavior than the rest of your app.
384
- properties:
385
- - name: importPath
386
- type: string
387
- required: false
388
- description: |
389
- Path or module specifier of a custom client module. Generated code imports its HTTP runtime from here instead of `@kubb/plugin-client/clients/{client}`.
390
-
391
- Use this when you need to inject auth headers, add interceptors, change the base URL at runtime, or wrap a different HTTP library (ky, ofetch, ...). Both relative paths (`./src/client.ts`) and bare specifiers (`@my-org/api-client`) work.
392
- details:
393
- - title: When to use `importPath`
394
- body: |
395
- Reach for a custom client when you need to:
396
-
397
- - Add an auth token to every request.
398
- - Plug in interceptors, retries, or logging.
399
- - Configure `baseURL` and headers from environment variables.
400
- - Wrap a library other than `axios`/`fetch`.
401
- - title: Default behavior
402
- body: |
403
- Without `importPath`:
404
-
405
- - `bundle: false` (default) — generated code imports from `@kubb/plugin-client/clients/{axios|fetch}`.
406
- - `bundle: true` — Kubb writes `.kubb/client.ts` and generated code imports from there.
407
- - title: Required exports
408
- body: |
409
- The module pointed to by `importPath` must satisfy the same shape as the built-in client. At minimum:
410
-
411
- - A default export of the `client` function.
412
- - A `RequestConfig` type.
413
- - A `ResponseErrorConfig` type.
414
-
415
- When used together with a query plugin (`@kubb/plugin-react-query`, `@kubb/plugin-vue-query`), it must also export a `Client` type alias.
416
- - title: How generated files import it
417
- body: |
418
- Generated code imports the client as a default import (bound to the local name `client`) and the runtime types as named type imports:
419
- codeBlock:
420
- lang: typescript
421
- code: |
422
- import client from '${client.importPath}'
423
- import type { RequestConfig, ResponseErrorConfig } from '${client.importPath}'
424
- // ... rest of the generated file
425
- important: |
426
- When used with query plugins (`@kubb/plugin-react-query`, `@kubb/plugin-vue-query`), generated hooks also import a `Client` type alias. Your module **must** export `Client`, `RequestConfig`, and `ResponseErrorConfig` — TypeScript will fail the import otherwise.
427
- codeBlock:
428
- lang: typescript
429
- title: src/client.ts
430
- code: |
431
- import axios from 'axios'
432
-
433
- export type RequestConfig<TData = unknown> = {
434
- url?: string
435
- method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE'
436
- params?: object
437
- data?: TData | FormData
438
- responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
439
- signal?: AbortSignal
440
- headers?: HeadersInit
441
- }
442
-
443
- export type ResponseConfig<TData = unknown> = {
444
- data: TData
445
- status: number
446
- statusText: string
447
- }
448
-
449
- export type ResponseErrorConfig<TError = unknown> = TError
450
-
451
- // Required when used with @kubb/plugin-react-query or @kubb/plugin-vue-query
452
- export type Client = <TData, _TError = unknown, TVariables = unknown>(
453
- config: RequestConfig<TVariables>,
454
- ) => Promise<ResponseConfig<TData>>
455
-
456
- const client: Client = async (config) => {
457
- const response = await axios.request<TData>({
458
- ...config,
459
- headers: {
460
- Authorization: `Bearer ${process.env.API_TOKEN}`,
461
- ...config.headers,
462
- },
463
- })
464
-
465
- return response
466
- }
467
-
468
- export default client
469
- examples:
470
- - name: Wire up a custom client
471
- files:
472
- - name: kubb.config.ts
473
- lang: typescript
474
- twoslash: false
475
- code: |
476
- import { defineConfig } from 'kubb'
477
- import { pluginClient } from '@kubb/plugin-client'
478
-
479
- export default defineConfig({
480
- input: { path: './petStore.yaml' },
481
- output: { path: './src/gen' },
482
- plugins: [
483
- pluginClient({
484
- importPath: './src/client.ts',
485
- }),
486
- ],
487
- })
488
- tip: |
489
- See the [custom client guide](https://kubb.dev/plugins/plugin-client#importpath) for a worked example.
490
- - name: dataReturnType
491
- type: "'data' | 'full'"
492
- required: false
493
- default: "'data'"
494
- description: |
495
- Shape of the value returned from each generated client function.
496
-
497
- - `'data'` returns only the response body (`response.data`). Concise and matches what most apps need.
498
- - `'full'` returns the full response config — body, status code, headers, and the original request. Use this when callers need to inspect headers or status.
499
- examples:
500
- - name: "'data' (default)"
501
- files:
502
- - name: getPetById.ts
503
- lang: typescript
504
- twoslash: false
505
- code: |
506
- export async function getPetById<TData>(
507
- petId: GetPetByIdPathParams,
508
- ): Promise<ResponseConfig<TData>['data']> {
509
- // ...
510
- }
511
- - name: usage.ts
512
- lang: typescript
513
- twoslash: false
514
- code: |
515
- const pet = await getPetById(1)
516
- // ^? Pet
517
- - name: "'full'"
518
- files:
519
- - name: getPetById.ts
520
- lang: typescript
521
- twoslash: false
522
- code: |
523
- export async function getPetById<TData>(
524
- petId: GetPetByIdPathParams,
525
- ): Promise<ResponseConfig<TData>> {
526
- // ...
527
- }
528
- - name: usage.ts
529
- lang: typescript
530
- twoslash: false
531
- code: |
532
- const response = await getPetById(1)
533
- // ^? ResponseConfig<Pet>
534
- console.log(response.status, response.headers)
535
- const pet = response.data
536
- - name: baseURL
537
- type: string
538
- required: false
539
- description: |
540
- Base URL prepended to every request URL in the generated client. When omitted, the URL comes from the OpenAPI spec's `servers[0].url` (or whichever index the adapter is configured to read).
541
-
542
- Set this when the generated client should point at a different environment (staging, production) than the one written in the spec.
543
- examples:
544
- - name: Override the spec's server URL
545
- files:
546
- - lang: typescript
547
- twoslash: false
548
- code: |
549
- import { defineConfig } from 'kubb'
550
- import { pluginClient } from '@kubb/plugin-client'
551
-
552
- export default defineConfig({
553
- input: { path: './petStore.yaml' },
554
- output: { path: './src/gen' },
555
- plugins: [
556
- pluginClient({
557
- baseURL: 'https://petstore.swagger.io/v2',
558
- }),
559
- ],
560
- })
561
- - name: clientType
562
- type: "'function' | 'class'"
563
- required: false
564
- default: "'function'"
565
- description: |
566
- Style of the HTTP client that this plugin imports from `@kubb/plugin-client`.
567
-
568
- - `'function'` — imports the function client (`getPetById(...)`). Required for query plugins.
569
- - `'class'` — also generates a wrapper class on top, but only usable inside `@kubb/plugin-client`.
570
- warning: |
571
- Query plugins (`@kubb/plugin-react-query`, `@kubb/plugin-vue-query`, `@kubb/plugin-svelte-query`, `@kubb/plugin-solid-query`) work only with `clientType: 'function'`. If you set `clientType: 'class'` here, the plugin falls back to generating its own inline function-based client instead of importing from `@kubb/plugin-client`.
572
- - name: bundle
573
- type: boolean
574
- required: false
575
- default: 'false'
576
- description: |
577
- Copies the HTTP client runtime into the generated output, so the consuming app does not need `@kubb/plugin-client` installed at runtime.
578
-
579
- - `false` (default) — generated files import from `@kubb/plugin-client/clients/{client}`. Smaller diff, but the package must be a runtime dependency.
580
- - `true` — Kubb writes a `.kubb/client.ts` file with the client implementation. Generated code imports from that local file and the project no longer pulls `@kubb/plugin-client` at runtime.
581
- - Setting `client.importPath` overrides both behaviors and uses your custom client instead.
582
- examples:
583
- - name: Bundle the runtime
584
- files:
585
- - lang: typescript
586
- twoslash: false
587
- code: |
588
- import { defineConfig } from 'kubb'
589
- import { pluginClient } from '@kubb/plugin-client'
590
-
591
- export default defineConfig({
592
- input: { path: './petStore.yaml' },
593
- output: { path: './src/gen' },
594
- plugins: [
595
- pluginClient({
596
- client: 'fetch',
597
- bundle: true,
598
- }),
599
- ],
600
- })
601
- - name: paramsType
602
- type: "'object' | 'inline'"
603
- required: false
604
- default: "'inline'"
605
- description: |
606
- How operation parameters (path, query, headers) are exposed in the generated function signature.
607
-
608
- - `'inline'` (default) — each parameter is a separate positional argument. Compact for operations with one or two params.
609
- - `'object'` — every parameter is wrapped in a single object argument. Easier to read for operations with many params and named at the call site.
610
- tip: |
611
- Setting `paramsType: 'object'` implicitly sets `pathParamsType: 'object'` as well, so call sites are consistent.
612
- examples:
613
- - name: "'inline' (default)"
614
- files:
615
- - name: Generated client
616
- lang: typescript
617
- twoslash: false
618
- code: |
619
- export async function deletePet(
620
- petId: DeletePetPathParams['petId'],
621
- headers?: DeletePetHeaderParams,
622
- config: Partial<RequestConfig> = {},
623
- ) {
624
- // ...
625
- }
626
- - name: Caller
627
- lang: typescript
628
- twoslash: false
629
- code: |
630
- await deletePet(42)
631
- - name: "'object'"
632
- files:
633
- - name: Generated client
634
- lang: typescript
635
- twoslash: false
636
- code: |
637
- export async function deletePet(
638
- {
639
- petId,
640
- headers,
641
- }: {
642
- petId: DeletePetPathParams['petId']
643
- headers?: DeletePetHeaderParams
644
- },
645
- config: Partial<RequestConfig> = {},
646
- ) {
647
- // ...
648
- }
649
- - name: Caller
650
- lang: typescript
651
- twoslash: false
652
- code: |
653
- await deletePet({ petId: 42, headers: { 'X-Api-Key': 'secret' } })
654
- - name: paramsCasing
655
- type: "'camelcase'"
656
- required: false
657
- description: |
658
- Renames path, query, and header parameters in the generated client to the chosen casing. The HTTP request still uses the original names from the OpenAPI spec — Kubb writes the mapping for you.
659
-
660
- - `'camelcase'` — turn `pet_id` and `X-Api-Key` into `petId` and `xApiKey` in your TypeScript code. The runtime URL still uses `/pet/{pet_id}` and the header is still sent as `X-Api-Key`.
661
- important: |
662
- Set the same `paramsCasing` on every plugin that touches operation parameters (`@kubb/plugin-ts`, `@kubb/plugin-client`, `@kubb/plugin-react-query`, `@kubb/plugin-faker`, `@kubb/plugin-mcp`). Mismatched casing causes type errors between generated layers.
663
- examples:
664
- - name: "With paramsCasing: 'camelcase'"
665
- files:
666
- - name: Generated client
667
- lang: typescript
668
- twoslash: false
669
- code: |
670
- // Function takes camelCase parameters
671
- export async function deletePet(
672
- petId: DeletePetPathParams['petId'],
673
- headers?: DeletePetHeaderParams,
674
- config: Partial<RequestConfig> = {},
675
- ) {
676
- // ...mapped back to the original API name internally
677
- const pet_id = petId
678
-
679
- return client({
680
- method: 'DELETE',
681
- url: `/pet/${pet_id}`,
682
- ...config,
683
- })
684
- }
685
- - name: Caller
686
- lang: typescript
687
- twoslash: false
688
- code: |
689
- await deletePet(42)
690
- - name: Without paramsCasing
691
- files:
692
- - name: Generated client
693
- lang: typescript
694
- twoslash: false
695
- code: |
696
- // Function parameters mirror the OpenAPI spec
697
- export async function deletePet(
698
- pet_id: DeletePetPathParams['pet_id'],
699
- headers?: DeletePetHeaderParams,
700
- config: Partial<RequestConfig> = {},
701
- ) {
702
- return client({
703
- method: 'DELETE',
704
- url: `/pet/${pet_id}`,
705
- ...config,
706
- })
707
- }
708
- tip: |
709
- Callers write friendly camelCase names. The generated client maps them back to whatever the API expects (snake_case path params, kebab-case headers, ...).
710
- - name: pathParamsType
711
- type: "'object' | 'inline'"
712
- required: false
713
- default: "'inline'"
714
- description: |
715
- How URL path parameters appear in the generated function signature. Affects only path params; query/header params follow `paramsType`.
716
-
717
- - `'inline'` (default) — each path param is a positional argument: `getPetById(petId)`.
718
- - `'object'` — path params are wrapped in a single object: `getPetById({ petId })`.
719
- examples:
720
- - name: "'inline' (default)"
721
- files:
722
- - lang: typescript
723
- twoslash: false
724
- code: |
725
- export async function getPetById(
726
- petId: GetPetByIdPathParams,
727
- ) {
728
- // ...
729
- }
730
- - name: "'object'"
731
- files:
732
- - lang: typescript
733
- twoslash: false
734
- code: |
735
- export async function getPetById(
736
- { petId }: GetPetByIdPathParams,
737
- ) {
738
- // ...
739
- }
740
- - name: parser
741
- type: false | 'zod'
742
- required: false
743
- default: 'false'
744
- description: |
745
- Runtime validator applied to the response body before it is returned to the caller.
746
-
747
- - `false` (default) — no validation. The client has no runtime parser; the response is cast to the generated TypeScript type and returned as-is. Fastest path, trusts the API.
748
- - `'zod'` — pipes the response through the Zod schema produced by `@kubb/plugin-zod`. Catches mismatches between spec and API at runtime, at the cost of a parse on every call.
749
-
750
- Use `'zod'` when you want a defensive boundary against drift between your OpenAPI spec and the live API. Requires `@kubb/plugin-zod` in the plugins list.
751
- examples:
752
- - name: Validate responses with Zod
753
- files:
754
- - lang: typescript
755
- twoslash: false
756
- code: |
757
- import { defineConfig } from 'kubb'
758
- import { pluginClient } from '@kubb/plugin-client'
759
- import { pluginTs } from '@kubb/plugin-ts'
760
- import { pluginZod } from '@kubb/plugin-zod'
761
-
762
- export default defineConfig({
763
- input: { path: './petStore.yaml' },
764
- output: { path: './src/gen' },
765
- plugins: [
766
- pluginTs(),
767
- pluginZod(),
768
- pluginClient({
769
- parser: 'zod',
770
- }),
771
- ],
772
- })
773
- - name: infinite
774
- type: Infinite | false
775
- required: false
776
- default: 'false'
777
- description: |
778
- Enables `useInfiniteQuery` composables for cursor- or page-based pagination. Pass an object to configure how the cursor is read from the response; pass `false` (default) to skip.
779
- typeDefinition: |
780
- type Infinite = {
781
- /** Query-param key used as the page cursor. Defaults to `'id'`. */
782
- queryParam: string
783
- /** @deprecated Use `nextParam` / `previousParam` instead. */
784
- cursorParam?: string
785
- /** Path to the next-page cursor in the response. Dot or array form. */
786
- nextParam?: string | string[]
787
- /** Path to the previous-page cursor in the response. Dot or array form. */
788
- previousParam?: string | string[]
789
- /** Value of `pageParam` for the first page. Defaults to `0`. */
790
- initialPageParam: unknown
791
- } | false
792
- properties:
793
- - name: queryParam
794
- type: string
795
- required: false
796
- default: "'id'"
797
- description: Name of the query parameter that holds the page cursor.
798
- - name: initialPageParam
799
- type: unknown
800
- required: false
801
- default: '0'
802
- description: Initial value for `pageParam` on the first fetch.
803
- - name: cursorParam
804
- type: string | undefined
805
- required: false
806
- deprecated:
807
- note: '`cursorParam` is deprecated. Use `nextParam` and `previousParam` for richer pagination control.'
808
- description: Path to the cursor field on the response. Leave undefined when the cursor is not known.
809
- - name: nextParam
810
- type: string | string[] | undefined
811
- required: false
812
- description: |
813
- Path to the next-page cursor on the response. Supports dot notation (`'pagination.next.id'`) or array form (`['pagination', 'next', 'id']`).
814
- - name: previousParam
815
- type: string | string[] | undefined
816
- required: false
817
- description: |
818
- Path to the previous-page cursor on the response. Supports dot notation (`'pagination.prev.id'`) or array form.
819
- - name: queryKey
820
- type: '(props: { operation: Operation; schemas: OperationSchemas }) => unknown[]'
821
- required: false
822
- description: |
823
- Builds the `queryKey` for each generated composable. Use this to add a version namespace, swap to operation IDs, or shape keys to match an existing invalidation strategy.
824
-
825
- The callback receives the OpenAPI `operation` and a `schemas` object containing `pathParams`, `queryParams`, `request`, and `response`.
826
- warning: |
827
- String values are inlined verbatim into generated code. Wrap any literal string in `JSON.stringify(...)`.
828
- details:
829
- - title: Keys from tags and path parameters
830
- body: "Build a key from the operation's first tag plus its path parameters:"
831
- codeBlock:
832
- - lang: typescript
833
- code: |-
834
- import { defineConfig } from 'kubb'
835
- import { pluginVueQuery } from '@kubb/plugin-vue-query'
836
-
837
- export default defineConfig({
838
- input: { path: './petStore.yaml' },
839
- output: { path: './src/gen' },
840
- plugins: [
841
- pluginVueQuery({
842
- queryKey: ({ operation, schemas }) => {
843
- const tags = operation.getTags().map((tag) => JSON.stringify(tag.name))
844
- const pathParams = schemas.pathParams?.keys ?? []
845
- return [...tags, ...pathParams]
846
- },
847
- }),
848
- ],
849
- })
850
- - lang: typescript
851
- code: |-
852
- export const getUserByNameQueryKey = ({ username }: { username: GetUserByNamePathParams['username'] }) =>
853
- ['user', username] as const
854
- - title: Extend the default transformer
855
- body: 'Prepend a version prefix to the default query key:'
856
- codeBlock:
857
- - lang: typescript
858
- code: |-
859
- import { defineConfig } from 'kubb'
860
- import { pluginVueQuery } from '@kubb/plugin-vue-query'
861
- import { QueryKey } from '@kubb/plugin-vue-query/components'
862
-
863
- export default defineConfig({
864
- input: { path: './petStore.yaml' },
865
- output: { path: './src/gen' },
866
- plugins: [
867
- pluginVueQuery({
868
- queryKey: (props) => {
869
- const defaultKeys = QueryKey.getTransformer(props)
870
- return [JSON.stringify('v5'), ...defaultKeys]
871
- },
872
- }),
873
- ],
874
- })
875
- - lang: typescript
876
- code: |-
877
- export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) =>
878
- ['v5', { url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
879
- - title: Key from operationId
880
- codeBlock:
881
- lang: typescript
882
- code: |-
883
- import { defineConfig } from 'kubb'
884
- import { pluginVueQuery } from '@kubb/plugin-vue-query'
885
-
886
- export default defineConfig({
887
- input: { path: './petStore.yaml' },
888
- output: { path: './src/gen' },
889
- plugins: [
890
- pluginVueQuery({
891
- queryKey: ({ operation }) => [JSON.stringify(operation.getOperationId())],
892
- }),
893
- ],
894
- })
895
- - title: Conditional keys based on params
896
- codeBlock:
897
- lang: typescript
898
- code: |-
899
- import { defineConfig } from 'kubb'
900
- import { pluginVueQuery } from '@kubb/plugin-vue-query'
901
-
902
- export default defineConfig({
903
- input: { path: './petStore.yaml' },
904
- output: { path: './src/gen' },
905
- plugins: [
906
- pluginVueQuery({
907
- queryKey: ({ operation, schemas }) => {
908
- const keys: unknown[] = [JSON.stringify(operation.getOperationId())]
909
-
910
- if (schemas.pathParams?.keys) {
911
- keys.push(...schemas.pathParams.keys)
912
- }
913
-
914
- if (schemas.queryParams?.name) {
915
- keys.push('...(params ? [params] : [])')
916
- }
917
-
918
- return keys
919
- },
920
- }),
921
- ],
922
- })
923
- - name: query
924
- type: Query
925
- required: false
926
- description: |
927
- Configures the query composables. Pass `false` to skip composable generation and emit only `queryOptions(...)` helpers.
928
- typeDefinition: |
929
- type Query = {
930
- methods: Array<HttpMethod>
931
- importPath?: string
932
- } | false
933
- properties:
934
- - name: methods
935
- type: Array<HttpMethod>
936
- required: false
937
- default: "['get']"
938
- description: |
939
- HTTP methods treated as queries. Operations using one of these methods generate a `useQuery`-style hook (or `queryOptions` helper) instead of a mutation.
940
-
941
- Defaults to `['get']`. Add other methods (for example `'head'`) only when your API uses them for cache-friendly reads.
942
- examples:
943
- - name: Allow HEAD as a query method
944
- files:
945
- - lang: typescript
946
- twoslash: false
947
- code: |
948
- import { defineConfig } from 'kubb'
949
- import { pluginReactQuery } from '@kubb/plugin-react-query'
950
-
951
- export default defineConfig({
952
- input: { path: './petStore.yaml' },
953
- output: { path: './src/gen' },
954
- plugins: [
955
- pluginReactQuery({
956
- query: { methods: ['get', 'head'] },
957
- }),
958
- ],
959
- })
960
- - name: importPath
961
- type: string
962
- required: false
963
- default: "'@tanstack/vue-query'"
964
- description: |
965
- Module specifier used in the `import { useQuery } from '...'` statement at the top of every generated composable file. Useful for routing through your own wrapper.
966
- - name: mutation
967
- type: Mutation
968
- required: false
969
- description: |
970
- Configures mutation composables. Set to `false` to skip mutation generation.
971
- typeDefinition: |
972
- type Mutation = {
973
- methods: Array<HttpMethod>
974
- importPath?: string
975
- } | false
976
- properties:
977
- - name: methods
978
- type: Array<HttpMethod>
979
- required: false
980
- default: "['post', 'put', 'patch', 'delete']"
981
- description: |
982
- HTTP methods treated as mutations. Operations using one of these methods generate a `useMutation`-style hook instead of a query.
983
-
984
- Defaults to `['post', 'put', 'patch', 'delete']`. Narrow the list if your API uses one of these methods for reads.
985
- examples:
986
- - name: Treat only POST and PUT as mutations
987
- files:
988
- - lang: typescript
989
- twoslash: false
990
- code: |
991
- import { defineConfig } from 'kubb'
992
- import { pluginReactQuery } from '@kubb/plugin-react-query'
993
-
994
- export default defineConfig({
995
- input: { path: './petStore.yaml' },
996
- output: { path: './src/gen' },
997
- plugins: [
998
- pluginReactQuery({
999
- mutation: { methods: ['post', 'put'] },
1000
- }),
1001
- ],
1002
- })
1003
- - name: importPath
1004
- type: string
1005
- required: false
1006
- default: "'@tanstack/vue-query'"
1007
- description: |
1008
- Module specifier used in the `import { useMutation } from '...'` statement at the top of every generated composable file.
1009
- - name: mutationKey
1010
- type: '(props: { operation: Operation; schemas: OperationSchemas }) => unknown[]'
1011
- required: false
1012
- description: |
1013
- Builds the `mutationKey` for each mutation composable. Useful when you batch invalidations or read mutation state via `useMutationState`.
1014
- warning: |
1015
- String values are inlined verbatim into generated code. Wrap any literal string in `JSON.stringify(...)`.
1016
- - name: include
1017
- type: Array<Include>
1018
- required: false
1019
- description: |
1020
- Restricts generation to operations that match at least one entry in the list. Anything not matched is skipped.
1021
-
1022
- Each entry filters by one of:
1023
-
1024
- - `tag` — the operation's first tag in the OpenAPI spec.
1025
- - `operationId` — the operation's `operationId`.
1026
- - `path` — the URL pattern (`'/pet/{petId}'`).
1027
- - `method` — HTTP method (`'get'`, `'post'`, ...).
1028
- - `contentType` — the media type of the request body.
1029
-
1030
- `pattern` accepts either a string (exact match) or a `RegExp` for fuzzy matches.
1031
- codeBlock:
1032
- lang: typescript
1033
- title: Type definition
1034
- code: |
1035
- export type Include = {
1036
- type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
1037
- pattern: string | RegExp
1038
- }
1039
- examples:
1040
- - name: Only the pet tag
1041
- files:
1042
- - name: kubb.config.ts
1043
- lang: typescript
1044
- twoslash: false
1045
- code: |
1046
- import { defineConfig } from 'kubb'
1047
- import { pluginTs } from '@kubb/plugin-ts'
1048
-
1049
- export default defineConfig({
1050
- input: { path: './petStore.yaml' },
1051
- output: { path: './src/gen' },
1052
- plugins: [
1053
- pluginTs({
1054
- include: [
1055
- { type: 'tag', pattern: 'pet' },
1056
- ],
1057
- }),
1058
- ],
1059
- })
1060
- - name: Only GET operations under /pet
1061
- files:
1062
- - name: kubb.config.ts
1063
- lang: typescript
1064
- twoslash: false
1065
- code: |
1066
- import { defineConfig } from 'kubb'
1067
- import { pluginTs } from '@kubb/plugin-ts'
1068
-
1069
- export default defineConfig({
1070
- input: { path: './petStore.yaml' },
1071
- output: { path: './src/gen' },
1072
- plugins: [
1073
- pluginTs({
1074
- include: [
1075
- { type: 'method', pattern: 'get' },
1076
- { type: 'path', pattern: /^\/pet/ },
1077
- ],
1078
- }),
1079
- ],
1080
- })
1081
- - name: exclude
1082
- type: Array<Exclude>
1083
- required: false
1084
- description: |
1085
- Skips any operation that matches at least one entry in the list. The opposite of `include`.
1086
-
1087
- Each entry filters by one of:
1088
-
1089
- - `tag` — the operation's first tag.
1090
- - `operationId` — the operation's `operationId`.
1091
- - `path` — the URL pattern (`'/pet/{petId}'`).
1092
- - `method` — HTTP method (`'get'`, `'post'`, ...).
1093
- - `contentType` — the media type of the request body.
1094
-
1095
- `pattern` accepts a plain string or a `RegExp`. When both `include` and `exclude` are set, `exclude` wins.
1096
- codeBlock:
1097
- lang: typescript
1098
- title: Type definition
1099
- code: |
1100
- export type Exclude = {
1101
- type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
1102
- pattern: string | RegExp
1103
- }
1104
- examples:
1105
- - name: Skip everything under the store tag
1106
- files:
1107
- - name: kubb.config.ts
1108
- lang: typescript
1109
- twoslash: false
1110
- code: |
1111
- import { defineConfig } from 'kubb'
1112
- import { pluginTs } from '@kubb/plugin-ts'
1113
-
1114
- export default defineConfig({
1115
- input: { path: './petStore.yaml' },
1116
- output: { path: './src/gen' },
1117
- plugins: [
1118
- pluginTs({
1119
- exclude: [
1120
- { type: 'tag', pattern: 'store' },
1121
- ],
1122
- }),
1123
- ],
1124
- })
1125
- - name: Skip a specific operation and all delete methods
1126
- files:
1127
- - name: kubb.config.ts
1128
- lang: typescript
1129
- twoslash: false
1130
- code: |
1131
- import { defineConfig } from 'kubb'
1132
- import { pluginTs } from '@kubb/plugin-ts'
1133
-
1134
- export default defineConfig({
1135
- input: { path: './petStore.yaml' },
1136
- output: { path: './src/gen' },
1137
- plugins: [
1138
- pluginTs({
1139
- exclude: [
1140
- { type: 'operationId', pattern: 'deletePet' },
1141
- { type: 'method', pattern: 'delete' },
1142
- ],
1143
- }),
1144
- ],
1145
- })
1146
- - name: override
1147
- type: Array<Override>
1148
- required: false
1149
- description: |
1150
- Applies a different set of plugin options to operations that match a pattern. Use this when most of your API should follow the global config, but a handful of endpoints need different treatment.
1151
-
1152
- Each entry has the same `type` and `pattern` shape as `include`/`exclude`, plus an `options` object that overrides the plugin's options for matched operations.
1153
-
1154
- Entries are evaluated top to bottom. The first matching entry's `options` is merged onto the plugin defaults; later entries do not stack.
1155
- codeBlock:
1156
- lang: typescript
1157
- title: Type definition
1158
- code: |
1159
- export type Override = {
1160
- type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
1161
- pattern: string | RegExp
1162
- options: PluginOptions
1163
- }
1164
- examples:
1165
- - name: Use a different enum style for the user tag
1166
- files:
1167
- - name: kubb.config.ts
1168
- lang: typescript
1169
- twoslash: false
1170
- code: |
1171
- import { defineConfig } from 'kubb'
1172
- import { pluginTs } from '@kubb/plugin-ts'
1173
-
1174
- export default defineConfig({
1175
- input: { path: './petStore.yaml' },
1176
- output: { path: './src/gen' },
1177
- plugins: [
1178
- pluginTs({
1179
- enumType: 'asConst',
1180
- override: [
1181
- {
1182
- type: 'tag',
1183
- pattern: 'user',
1184
- options: { enumType: 'literal' },
1185
- },
1186
- ],
1187
- }),
1188
- ],
1189
- })
1190
- - name: generators
1191
- type: Array<Generator<PluginVueQuery>>
1192
- required: false
1193
- experimental: true
1194
- description: |
1195
- Adds custom generators that run alongside the plugin's built-in generators. Each generator can emit additional files or post-process existing ones using the plugin's AST and options.
1196
-
1197
- Use this when you need output the plugin does not produce out of the box (a custom client wrapper, an extra index, a metadata file). For end-to-end guidance, see [Creating plugins](https://kubb.dev/docs/5.x/guides/creating-plugins).
1198
- warning: |
1199
- Generators are an experimental, low-level API. The signature may change between minor releases.
1200
- - name: resolver
1201
- type: Partial<ResolverVueQuery>
1202
- required: false
1203
- description: |
1204
- Overrides naming and path resolution for the generated composables. Supply only the methods you want to change; everything else falls back to the default resolver.
1205
- - name: transformer
1206
- type: ast.Visitor
1207
- required: false
1208
- description: |
1209
- AST visitor applied to operation nodes before code is printed. Use this to rewrite operation IDs, tags, or descriptions across the entire output.
1210
- notes:
1211
- - type: tip
1212
- body: |
1213
- Reference: [TanStack Query for Vue](https://tanstack.com/query/latest/docs/framework/vue/overview) for cache, retries, and devtools.
1214
- examples:
1215
- - name: kubb.config.ts
1216
- files:
1217
- - lang: typescript
1218
- twoslash: false
1219
- code: |
1220
- import { defineConfig } from 'kubb'
1221
- import { pluginTs } from '@kubb/plugin-ts'
1222
- import { pluginVueQuery } from '@kubb/plugin-vue-query'
1223
-
1224
- export default defineConfig({
1225
- input: { path: './petStore.yaml' },
1226
- output: { path: './src/gen' },
1227
- plugins: [
1228
- pluginTs(),
1229
- pluginVueQuery({
1230
- output: { path: './hooks' },
1231
- group: {
1232
- type: 'tag',
1233
- name: ({ group }) => `${group}Hooks`,
1234
- },
1235
- client: { dataReturnType: 'full' },
1236
- mutation: { methods: ['post', 'put', 'delete'] },
1237
- infinite: {
1238
- queryParam: 'next_page',
1239
- initialPageParam: 0,
1240
- nextParam: 'pagination.next.cursor',
1241
- },
1242
- query: {
1243
- methods: ['get'],
1244
- importPath: '@tanstack/vue-query',
1245
- },
1246
- }),
1247
- ],
1248
- })