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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +26 -7
  3. package/dist/components-1cEftHJm.cjs +1276 -0
  4. package/dist/components-1cEftHJm.cjs.map +1 -0
  5. package/dist/components-DTSvTMEo.js +1162 -0
  6. package/dist/components-DTSvTMEo.js.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +66 -121
  9. package/dist/components.js +1 -1
  10. package/dist/generators-BEiWCS-U.cjs +698 -0
  11. package/dist/generators-BEiWCS-U.cjs.map +1 -0
  12. package/dist/generators-F6_EduRU.js +681 -0
  13. package/dist/generators-F6_EduRU.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +5 -501
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +150 -121
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +146 -121
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-Bkm7bWT3.d.ts +243 -0
  23. package/extension.yaml +749 -0
  24. package/package.json +60 -65
  25. package/src/components/InfiniteQuery.tsx +71 -159
  26. package/src/components/InfiniteQueryOptions.tsx +120 -163
  27. package/src/components/Mutation.tsx +97 -134
  28. package/src/components/Query.tsx +68 -157
  29. package/src/components/QueryKey.tsx +23 -66
  30. package/src/components/QueryOptions.tsx +97 -143
  31. package/src/generators/infiniteQueryGenerator.tsx +152 -171
  32. package/src/generators/mutationGenerator.tsx +102 -125
  33. package/src/generators/queryGenerator.tsx +125 -137
  34. package/src/index.ts +1 -1
  35. package/src/plugin.ts +126 -177
  36. package/src/resolvers/resolverVueQuery.ts +65 -0
  37. package/src/types.ts +121 -52
  38. package/src/utils.ts +49 -0
  39. package/dist/components-Yjoe78Y7.cjs +0 -1119
  40. package/dist/components-Yjoe78Y7.cjs.map +0 -1
  41. package/dist/components-_AMBl0g-.js +0 -1029
  42. package/dist/components-_AMBl0g-.js.map +0 -1
  43. package/dist/generators-CR34GjVu.js +0 -661
  44. package/dist/generators-CR34GjVu.js.map +0 -1
  45. package/dist/generators-DH8VkK1q.cjs +0 -678
  46. package/dist/generators-DH8VkK1q.cjs.map +0 -1
  47. package/dist/types-CgDFUvfZ.d.ts +0 -211
package/extension.yaml ADDED
@@ -0,0 +1,749 @@
1
+ $schema: https://kubb.dev/schemas/extension.json
2
+ kind: plugin
3
+ id: plugin-vue-query
4
+ name: Vue Query
5
+ description: Generate Vue Query composables from OpenAPI specifications.
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 type-safe Vue Query composables from your OpenAPI schema for data fetching, caching, and synchronization.
41
+ options:
42
+ - name: output
43
+ type: Output
44
+ required: false
45
+ default: "{ path: 'hooks', barrel: { type: 'named' } }"
46
+ description: Specify the export location for the files and define the behavior of the output.
47
+ properties:
48
+ - name: path
49
+ type: string
50
+ required: true
51
+ description: Output directory or file for the generated code, relative to the global `output.path`.
52
+ tip: |
53
+ if `output.path` is a file, `group` cannot be used.
54
+ default: "'hooks'"
55
+ - name: barrel
56
+ type: "{ type: 'named' | 'all', nested?: boolean } | false"
57
+ required: false
58
+ default: "{ type: 'named' }"
59
+ description: 'Configure barrel file export strategy. Use `type` to control named vs. wildcard exports; set `nested: true` to generate hierarchical barrels in subdirectories.'
60
+ examples:
61
+ - name: all
62
+ files:
63
+ - lang: typescript
64
+ code: |
65
+ export * from './gen/petService.ts'
66
+ twoslash: false
67
+ - name: named
68
+ files:
69
+ - lang: typescript
70
+ code: |
71
+ export { PetService } from './gen/petService.ts'
72
+ twoslash: false
73
+ - name: nested
74
+ files:
75
+ - name: kubb.config.ts
76
+ lang: typescript
77
+ code: |
78
+ output: {
79
+ path: './gen',
80
+ barrel: { type: 'named', nested: true },
81
+ }
82
+ twoslash: false
83
+ - name: 'false'
84
+ files:
85
+ - lang: typescript
86
+ code: ''
87
+ twoslash: false
88
+ - name: banner
89
+ type: 'string | ((node: RootNode) => string)'
90
+ required: false
91
+ description: Add a banner comment at the top of every generated file. Accepts a static string or a function that receives the `RootNode` and returns a string.
92
+ - name: footer
93
+ type: 'string | ((node: RootNode) => string)'
94
+ required: false
95
+ description: Add a footer comment at the end of every generated file. Accepts a static string or a function that receives the `RootNode` and returns a string.
96
+ - name: override
97
+ type: boolean
98
+ required: false
99
+ default: 'false'
100
+ description: Whether Kubb overrides existing external files that can be generated if they already exist.
101
+ - name: contentType
102
+ type: "'application/json' | (string & {})"
103
+ required: false
104
+ description: |
105
+ Define which content type to use.
106
+
107
+ By default, Kubb uses the first JSON-valid media type.
108
+ - name: group
109
+ type: Group
110
+ required: false
111
+ description: |
112
+ Grouping combines files in a folder based on a specific `type`.
113
+ examples:
114
+ - name: kubb.config.ts
115
+ files:
116
+ - lang: typescript
117
+ code: |
118
+ group: {
119
+ type: 'tag',
120
+ name({ group }) {
121
+ return `${group}Controller`
122
+ }
123
+ }
124
+ twoslash: false
125
+ body: |
126
+ With the configuration above, the generator emits:
127
+
128
+ ```text
129
+ .
130
+ ├── src/
131
+ │ └── petController/
132
+ │ │ ├── addPet.ts
133
+ │ │ └── getPet.ts
134
+ │ └── storeController/
135
+ │ ├── createStore.ts
136
+ │ └── getStoreById.ts
137
+ ├── petStore.yaml
138
+ ├── kubb.config.ts
139
+ └── package.json
140
+ ```
141
+ properties:
142
+ - name: type
143
+ type: "'tag'"
144
+ required: true
145
+ description: Specify the property to group files by. Required when `group` is defined.
146
+ note: |
147
+ `Required: true*` means this is required only when the `group` option is used. The `group` option itself is optional.
148
+ body: |
149
+ - `'tag'`: Uses the first tag from `operation.getTags().at(0)?.name`
150
+ - name: name
151
+ type: '(context: GroupContext) => string'
152
+ required: false
153
+ default: (ctx) => `${ctx.group}Controller`
154
+ description: Return the name of a group based on the group name. This is used for file and identifier generation.
155
+ - name: client
156
+ type: ClientImportPath & { clientType?, dataReturnType?, baseURL?, bundle?, paramsCasing? }
157
+ required: false
158
+ description: Client configuration for HTTP request generation.
159
+ properties:
160
+ - name: importPath
161
+ type: string
162
+ required: false
163
+ description: Path to the client used for API calls. Supports both relative and absolute paths.
164
+ details:
165
+ - title: When to use `importPath`
166
+ body: |
167
+ Use `importPath` when you want to:
168
+
169
+ - **Customize the HTTP client**: Provide your own client implementation with custom configurations (e.g., baseURL, headers, interceptors)
170
+ - **Add authentication**: Include authentication tokens or other security mechanisms in your client
171
+ - **Override default behavior**: Replace the default Kubb client with your own implementation
172
+ - title: Default behavior
173
+ body: |
174
+ When `importPath` is not specified:
175
+
176
+ - If `bundle: false` (default): Uses `@kubb/plugin-client/clients/${client}` where client is either `axios` or `fetch`.
177
+ - If `bundle: true`: Bundles the client into `.kubb/fetch.ts`.
178
+ - title: Import structure
179
+ body: 'Generated code imports the client as a default import and the runtime types as named type imports:'
180
+ codeBlock:
181
+ lang: typescript
182
+ code: |-
183
+ /**
184
+ * Generated by Kubb (https://kubb.dev/).
185
+ * Do not edit manually.
186
+ */
187
+ import client from '${client.importPath}'
188
+ import type { RequestConfig, ResponseErrorConfig } from '${client.importPath}'
189
+ // ... rest of generated file
190
+ important: |
191
+ When using `importPath` with query plugins such as `@kubb/plugin-react-query` or `@kubb/plugin-vue-query`, the generated hooks also import a `Client` type alongside `RequestConfig` and `ResponseErrorConfig` from the custom module. Your custom client module **must** export all three types — if any is missing, TypeScript will report an unresolvable import error.
192
+ codeBlock:
193
+ lang: typescript
194
+ title: client.ts
195
+ code: |
196
+ export type RequestConfig<TData = unknown> = {
197
+ url?: string
198
+ method: 'GET' | 'PUT' | 'PATCH' | 'POST' | 'DELETE'
199
+ params?: object
200
+ data?: TData | FormData
201
+ responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream'
202
+ signal?: AbortSignal
203
+ headers?: HeadersInit
204
+ }
205
+
206
+ export type ResponseConfig<TData = unknown> = {
207
+ data: TData
208
+ status: number
209
+ statusText: string
210
+ }
211
+
212
+ export type ResponseErrorConfig<TError = unknown> = TError
213
+
214
+ // The Client type alias is required when using query plugins
215
+ export type Client = <TData, _TError = unknown, TVariables = unknown>(
216
+ config: RequestConfig<TVariables>
217
+ ) => Promise<ResponseConfig<TData>>
218
+
219
+ export const client: Client = async (config) => { /* ... */ }
220
+ export default client
221
+ examples:
222
+ - name: kubb.config.ts
223
+ files:
224
+ - lang: typescript
225
+ code: |
226
+ import { defineConfig } from 'kubb'
227
+ import { pluginClient } from '@kubb/plugin-client'
228
+
229
+ export default defineConfig({
230
+ // ...
231
+ plugins: [
232
+ pluginClient({
233
+ importPath: './src/client.ts', // Path to your custom client
234
+ }),
235
+ ],
236
+ })
237
+ twoslash: false
238
+ tip: |
239
+ Learn more about defining a custom client [here](https://kubb.dev/plugins/plugin-client#importpath).
240
+ - name: dataReturnType
241
+ type: "'data' | 'full'"
242
+ required: false
243
+ default: "'data'"
244
+ description: |
245
+ Return type used when calling the client.
246
+
247
+ - `'data'` returns `ResponseConfig['data']`.
248
+ - `'full'` returns the full `ResponseConfig`.
249
+ examples:
250
+ - name: data
251
+ files:
252
+ - lang: typescript
253
+ code: |
254
+ export async function getPetById<TData>(
255
+ petId: GetPetByIdPathParams,
256
+ ): Promise<ResponseConfig<TData>['data']> {
257
+ ...
258
+ }
259
+ twoslash: false
260
+ - name: full
261
+ files:
262
+ - lang: typescript
263
+ code: |
264
+ export async function getPetById<TData>(
265
+ petId: GetPetByIdPathParams,
266
+ ): Promise<ResponseConfig<TData>> {
267
+ ...
268
+ }
269
+ twoslash: false
270
+ - name: baseURL
271
+ type: string
272
+ required: false
273
+ description: Sets a custom base URL for all generated calls. When not set, the base URL is automatically taken from the OAS spec via the adapter (e.g. the `servers[0].url` field).
274
+ - name: clientType
275
+ type: "'function' | 'class'"
276
+ required: false
277
+ default: "'function'"
278
+ description: Specify whether to use function-based or class-based clients.
279
+ warning: |
280
+ This plugin is only compatible with `clientType: 'function'` (the default). If `clientType: 'class'` is detected, the plugin will automatically generate its own inline function-based client instead of importing from `@kubb/plugin-client`.
281
+ - name: bundle
282
+ type: boolean
283
+ required: false
284
+ default: 'false'
285
+ description: Controls whether the HTTP client runtime is copied into the generated `.kubb` directory.
286
+ body: |
287
+ - `true` adds a `.kubb/fetch.ts` file containing the selected client template (fetch or axios). Generated clients remain self-contained.
288
+ - `false` keeps generated clients slim by importing the shared runtime from `@kubb/plugin-client/clients/{client}`.
289
+ - Override this behavior by providing a custom `client.importPath`.
290
+ - name: paramsType
291
+ type: "'object' | 'inline'"
292
+ required: false
293
+ default: "'inline'"
294
+ description: Defines how parameters are passed to generated functions. Switch between object-style parameters and inline parameters.
295
+ tip: |
296
+ When `paramsType` is set to `'object'`, `pathParams` will also be set to `'object'`.
297
+ body: |
298
+ - `'object'` returns params and pathParams as an object.
299
+ - `'inline'` returns params as comma-separated params.
300
+ examples:
301
+ - name: object
302
+ files:
303
+ - lang: typescript
304
+ code: |
305
+ export async function deletePet(
306
+ {
307
+ petId,
308
+ headers,
309
+ }: {
310
+ petId: DeletePetPathParams['petId']
311
+ headers?: DeletePetHeaderParams
312
+ },
313
+ config: Partial<RequestConfig> = {},
314
+ ) {
315
+ ...
316
+ }
317
+ twoslash: false
318
+ - name: inline
319
+ files:
320
+ - lang: typescript
321
+ code: |
322
+ export async function deletePet(
323
+ petId: DeletePetPathParams['petId'],
324
+ headers?: DeletePetHeaderParams,
325
+ config: Partial<RequestConfig> = {}
326
+ ){
327
+ ...
328
+ }
329
+ twoslash: false
330
+ - name: paramsCasing
331
+ type: "'camelcase'"
332
+ required: false
333
+ description: Transform parameter names to a specific casing format for path, query, and header parameters in generated client code.
334
+ important: |
335
+ When using `paramsCasing`, ensure that `@kubb/plugin-ts` also has the same `paramsCasing` setting. This option automatically maps transformed parameter names back to their original API names in HTTP requests.
336
+ body: |
337
+ - `'camelcase'` transforms parameter names to camelCase.
338
+ examples:
339
+ - name: With paramsCasing camelcase
340
+ files:
341
+ - lang: typescript
342
+ code: |
343
+ // Function parameters use camelCase
344
+ export async function deletePet(
345
+ petId: DeletePetPathParams['petId'], // ✓ camelCase
346
+ headers?: DeletePetHeaderParams,
347
+ config: Partial<RequestConfig> = {}
348
+ ) {
349
+ // Automatically maps back to original name for the API
350
+ const pet_id = petId
351
+
352
+ return fetch({
353
+ method: 'DELETE',
354
+ url: `/pet/${pet_id}`, // Uses original API parameter name
355
+ ...
356
+ })
357
+ }
358
+ twoslash: false
359
+ - name: Without paramsCasing
360
+ files:
361
+ - lang: typescript
362
+ code: |
363
+ // Parameters use original API naming
364
+ export async function deletePet(
365
+ pet_id: DeletePetPathParams['pet_id'], // Original naming
366
+ headers?: DeletePetHeaderParams,
367
+ config: Partial<RequestConfig> = {}
368
+ ) {
369
+ return fetch({
370
+ method: 'DELETE',
371
+ url: `/pet/${pet_id}`,
372
+ ...
373
+ })
374
+ }
375
+ twoslash: false
376
+ tip: |
377
+ The client automatically generates mapping code to convert camelCase parameter names back to the original API format. You write code with developer-friendly camelCase names, but HTTP requests use the exact parameter names from your OpenAPI specification.
378
+ - name: pathParamsType
379
+ type: "'object' | 'inline'"
380
+ required: false
381
+ default: "'inline'"
382
+ description: Defines how pathParams are passed to generated functions.
383
+ body: |
384
+ - `'object'` returns pathParams as an object.
385
+ - `'inline'` returns pathParams as comma-separated params.
386
+ examples:
387
+ - name: object
388
+ files:
389
+ - lang: typescript
390
+ code: |
391
+ export async function getPetById(
392
+ { petId }: GetPetByIdPathParams,
393
+ ) {
394
+ ...
395
+ }
396
+ twoslash: false
397
+ - name: inline
398
+ files:
399
+ - lang: typescript
400
+ code: |
401
+ export async function getPetById(
402
+ petId: GetPetByIdPathParams,
403
+ ) {
404
+ ...
405
+ }
406
+ twoslash: false
407
+ - name: parser
408
+ type: "'client' | 'zod'"
409
+ required: false
410
+ default: "'client'"
411
+ description: Parser used before returning data.
412
+ body: |
413
+ - `'zod'` uses `@kubb/plugin-zod` to parse data.
414
+ - `'client'` returns data without parsing.
415
+ - name: infinite
416
+ type: Infinite | false
417
+ required: false
418
+ default: 'false'
419
+ description: |
420
+ Generate an `infiniteQuery` composable for paginated queries. Pass `false` to disable.
421
+ typeDefinition: |
422
+ type Infinite = {
423
+ /**
424
+ * Specify the params key used for `pageParam`.
425
+ * @default `'id'`
426
+ */
427
+ queryParam: string
428
+ /**
429
+ * Which field of the data will be used, set it to undefined when no cursor is known.
430
+ * @deprecated Use `nextParam` and `previousParam` instead for more flexible pagination handling.
431
+ */
432
+ cursorParam?: string | undefined
433
+ /**
434
+ * Which field of the data will be used to get the cursor for the next page.
435
+ * Supports dot notation (e.g. 'pagination.next.id') or array path (e.g. ['pagination', 'next', 'id']) to access nested fields.
436
+ */
437
+ nextParam?: string | string[] | undefined
438
+ /**
439
+ * Which field of the data will be used to get the cursor for the previous page.
440
+ * Supports dot notation (e.g. 'pagination.prev.id') or array path (e.g. ['pagination', 'prev', 'id']) to access nested fields.
441
+ */
442
+ previousParam?: string | string[] | undefined
443
+ /**
444
+ * The initial value, the value of the first page.
445
+ * @default `0`
446
+ */
447
+ initialPageParam: unknown
448
+ } | false
449
+ properties:
450
+ - name: queryParam
451
+ type: string
452
+ required: false
453
+ default: "'id'"
454
+ description: Specify the params key used for `pageParam`.
455
+ - name: initialPageParam
456
+ type: unknown
457
+ required: false
458
+ default: '0'
459
+ description: Specify the initial page param value.
460
+ - name: cursorParam
461
+ type: string | undefined
462
+ required: false
463
+ deprecated:
464
+ note: '`cursorParam` is deprecated. Use `nextParam` and `previousParam` instead for more flexible pagination handling.'
465
+ description: Which field of the data will be used, set it to undefined when no cursor is known.
466
+ - name: nextParam
467
+ type: string | string[] | undefined
468
+ required: false
469
+ description: |
470
+ Which field of the data will be used to get the cursor for the next page.
471
+
472
+ Supports dot notation (e.g. `'pagination.next.id'`) or array path (e.g. `['pagination', 'next', 'id']`) to access nested fields.
473
+ - name: previousParam
474
+ type: string | string[] | undefined
475
+ required: false
476
+ description: |
477
+ Which field of the data will be used to get the cursor for the previous page.
478
+
479
+ Supports dot notation (e.g. `'pagination.prev.id'`) or array path (e.g. `['pagination', 'prev', 'id']`) to access nested fields.
480
+ - name: queryKey
481
+ type: '(props: { operation: Operation; schemas: OperationSchemas }) => unknown[]'
482
+ required: false
483
+ description: |
484
+ Customize the queryKey that will be used for the query.
485
+
486
+ The function receives an object with:
487
+ - `operation`: The OpenAPI operation object with methods like `getTags()`, `getOperationId()`, etc.
488
+ - `schemas`: An object containing operation schemas including `pathParams`, `queryParams`, `request`, `response`, etc.
489
+ warning: |
490
+ When using a string you need to use `JSON.stringify`.
491
+ details:
492
+ - title: Using tags and path parameters
493
+ body: |-
494
+ Generate a queryKey with operation tags and path parameters:
495
+
496
+ For a GET operation with tags `["user"]` and path parameter `username`, this generates:
497
+ codeBlock:
498
+ - lang: typescript
499
+ code: |-
500
+ import { defineConfig } from 'kubb'
501
+ import { pluginVueQuery } from '@kubb/plugin-vue-query'
502
+
503
+ export default defineConfig({
504
+ // ...
505
+ plugins: [
506
+ pluginVueQuery({
507
+ queryKey: ({ operation, schemas }) => {
508
+ const tags = operation.getTags().map(tag => JSON.stringify(tag.name))
509
+ const pathParams = schemas.pathParams?.keys || []
510
+ return [...tags, ...pathParams]
511
+ },
512
+ }),
513
+ ],
514
+ })
515
+ - lang: typescript
516
+ code: |-
517
+ export const getUserByNameQueryKey = ({ username }: { username: GetUserByNamePathParams["username"] }) =>
518
+ ['user', username] as const
519
+ - title: Using the default transformer
520
+ body: |-
521
+ You can extend the default queryKey transformer:
522
+
523
+ This prepends a version to the default queryKey:
524
+ codeBlock:
525
+ - lang: typescript
526
+ code: |-
527
+ import { defineConfig } from 'kubb'
528
+ import { pluginVueQuery } from '@kubb/plugin-vue-query'
529
+ import { QueryKey } from '@kubb/plugin-vue-query/components'
530
+
531
+ export default defineConfig({
532
+ // ...
533
+ plugins: [
534
+ pluginVueQuery({
535
+ queryKey: (props) => {
536
+ const defaultKeys = QueryKey.getTransformer(props)
537
+ return [JSON.stringify('v5'), ...defaultKeys]
538
+ },
539
+ }),
540
+ ],
541
+ })
542
+ - lang: typescript
543
+ code: |-
544
+ export const findPetsByTagsQueryKey = (params?: FindPetsByTagsQueryParams) =>
545
+ ['v5', { url: '/pet/findByTags' }, ...(params ? [params] : [])] as const
546
+ - title: Using operation ID
547
+ body: 'Create a simple queryKey using the operation ID:'
548
+ codeBlock:
549
+ lang: typescript
550
+ code: |-
551
+ import { defineConfig } from 'kubb'
552
+ import { pluginVueQuery } from '@kubb/plugin-vue-query'
553
+
554
+ export default defineConfig({
555
+ // ...
556
+ plugins: [
557
+ pluginVueQuery({
558
+ queryKey: ({ operation }) => {
559
+ return [JSON.stringify(operation.getOperationId())]
560
+ },
561
+ }),
562
+ ],
563
+ })
564
+ - title: Conditional keys based on parameters
565
+ body: 'Include query parameters when they exist:'
566
+ codeBlock:
567
+ lang: typescript
568
+ code: |-
569
+ import { defineConfig } from 'kubb'
570
+ import { pluginVueQuery } from '@kubb/plugin-vue-query'
571
+
572
+ export default defineConfig({
573
+ // ...
574
+ plugins: [
575
+ pluginVueQuery({
576
+ queryKey: ({ operation, schemas }) => {
577
+ const keys = [JSON.stringify(operation.getOperationId())]
578
+
579
+ // Add path parameter values (without quotes, so they reference the variables)
580
+ if (schemas.pathParams?.keys) {
581
+ keys.push(...schemas.pathParams.keys)
582
+ }
583
+
584
+ // Add query params conditionally (the string gets embedded as code)
585
+ if (schemas.queryParams?.name) {
586
+ keys.push('...(params ? [params] : [])')
587
+ }
588
+
589
+ return keys
590
+ },
591
+ }),
592
+ ],
593
+ })
594
+ - name: query
595
+ type: Query
596
+ required: false
597
+ description: |
598
+ Override some `useQuery` behaviors.
599
+
600
+ To disable the creation of hooks pass `false`, this will result in only creating `queryOptions`.
601
+ typeDefinition: |
602
+ type Query = {
603
+ methods: Array<HttpMethod>
604
+ importPath?: string
605
+ } | false
606
+ properties:
607
+ - name: methods
608
+ type: Array<HttpMethod>
609
+ required: false
610
+ default: "['get']"
611
+ description: Define which HttpMethods can be used for queries.
612
+ - name: importPath
613
+ type: string
614
+ required: false
615
+ default: "'@tanstack/vue-query'"
616
+ description: |
617
+ Path to the `useQuery` that will be used to do the `useQuery` functionality.
618
+
619
+ It will be used as `import { useQuery } from '${hook.importPath}'`. It allows both relative and absolute paths. The path will be applied as is, so relative paths should be based on the file being generated.
620
+ - name: mutation
621
+ type: Mutation
622
+ required: false
623
+ description: |
624
+ Override some `useMutation` behaviors.
625
+
626
+ To disable queries pass `false`.
627
+ typeDefinition: |
628
+ type Mutation = {
629
+ methods: Array<HttpMethod>
630
+ importPath?: string
631
+ } | false
632
+ properties:
633
+ - name: methods
634
+ type: Array<HttpMethod>
635
+ required: false
636
+ default: "['post', 'put', 'delete']"
637
+ description: Define which HttpMethods can be used for mutations.
638
+ - name: importPath
639
+ type: string
640
+ required: false
641
+ default: "'@tanstack/vue-query'"
642
+ description: |
643
+ Path to the `useMutation` that will be used to do the `useMutation` functionality.
644
+
645
+ It will be used as `import { useMutation } from '${hook.importPath}'`. It allows both relative and absolute paths. The path will be applied as is, so relative paths should be based on the file being generated.
646
+ - name: mutationKey
647
+ type: '(props: { operation: Operation; schemas: OperationSchemas }) => unknown[]'
648
+ required: false
649
+ description: Customize the mutationKey.
650
+ warning: |
651
+ When using a string you need to use `JSON.stringify`.
652
+ - name: include
653
+ type: Array<Include>
654
+ required: false
655
+ description: Array containing include parameters to include tags, operations, methods, paths, or content types.
656
+ codeBlock:
657
+ lang: typescript
658
+ title: Include
659
+ code: |
660
+ export type Include = {
661
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
662
+ pattern: string | RegExp
663
+ }
664
+ - name: exclude
665
+ type: Array<Exclude>
666
+ required: false
667
+ description: Array containing exclude parameters to exclude or skip tags, operations, methods, paths, or content types.
668
+ codeBlock:
669
+ lang: typescript
670
+ title: Exclude
671
+ code: |
672
+ export type Exclude = {
673
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
674
+ pattern: string | RegExp
675
+ }
676
+ - name: override
677
+ type: Array<Override>
678
+ required: false
679
+ description: Array containing override parameters to override `options` based on tags, operations, methods, paths, or content types.
680
+ codeBlock:
681
+ lang: typescript
682
+ title: Override
683
+ code: |
684
+ export type Override = {
685
+ type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType'
686
+ pattern: string | RegExp
687
+ options: PluginOptions
688
+ }
689
+ - name: generators
690
+ type: Array<Generator<PluginVueQuery>>
691
+ required: false
692
+ experimental: true
693
+ description: |
694
+ Define additional generators next to the built-in generators.
695
+
696
+ See [Generators](https://kubb.dev/docs/5.x/guides/creating-plugins) for more information on how to use generators.
697
+ - name: resolver
698
+ type: Partial<ResolverVueQuery>
699
+ required: false
700
+ description: Override individual resolver methods to customize naming conventions.
701
+ - name: transformer
702
+ type: ast.Visitor
703
+ required: false
704
+ description: Single AST visitor applied to each node before printing.
705
+ examples:
706
+ - name: kubb.config.ts
707
+ files:
708
+ - lang: typescript
709
+ code: |
710
+ import { defineConfig } from 'kubb'
711
+ import { pluginTs } from '@kubb/plugin-ts'
712
+ import { pluginVueQuery } from '@kubb/plugin-vue-query'
713
+
714
+ export default defineConfig({
715
+ input: {
716
+ path: './petStore.yaml',
717
+ },
718
+ output: {
719
+ path: './src/gen',
720
+ },
721
+ plugins: [
722
+ pluginTs(),
723
+ pluginVueQuery({
724
+ output: {
725
+ path: './hooks',
726
+ },
727
+ group: {
728
+ type: 'tag',
729
+ name: ({ group }) => `${group}Hooks`,
730
+ },
731
+ client: {
732
+ dataReturnType: 'full',
733
+ },
734
+ mutation: {
735
+ methods: ['post', 'put', 'delete'],
736
+ },
737
+ infinite: {
738
+ queryParam: 'next_page',
739
+ initialPageParam: 0,
740
+ cursorParam: 'nextCursor',
741
+ },
742
+ query: {
743
+ methods: ['get'],
744
+ importPath: '@tanstack/vue-query',
745
+ },
746
+ }),
747
+ ],
748
+ })
749
+ twoslash: false