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

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