Skip to content

Options

Options for @kubb/plugin-vue-query, which generates TanStack Vue Query composables from an OpenAPI spec.

Option Type Default Description
output Output { path: 'hooks' } Where the generated composables are written and exported
group Group Split output into per-tag or per-path folders
client 'axios' | 'fetch' Which registered client plugin the composables call
infinite Partial<Infinite> | false false Add useInfiniteQuery composables for paginated reads
query Partial<Query> | false { methods: ['GET'], … } Configure or disable query composables
queryKey (props) => Array<unknown> built-in Build the queryKey for each query composable
mutation Partial<Mutation> | false { methods: ['POST', …], … } Configure or disable mutation composables
mutationKey (props) => Array<unknown> built-in Build the mutationKey for each mutation composable
hooks boolean false Emit use* composables on top of the factory helpers
include Array<Include> Keep only operations that match
exclude Array<Exclude> Skip operations that match
override Array<Override> Apply different options per pattern
resolver ResolverPatch<ResolverVueQuery> Customize generated names and file paths
macros Array<Macro> Rewrite AST nodes before printing

output

Where the generated composables are written and how they are exported. Defaults to { path: 'hooks', barrel: { type: 'named' } }.

output.path

Folder the plugin writes to, resolved against the global output.path and defaulting to 'hooks'. For a single file, set output.mode: 'file' and give path an extension such as 'hooks.ts'.

output.mode

How generated code is consolidated, 'file' or 'directory'. The default 'file' writes a single file, so output.path needs an extension. 'directory' writes one file per operation and pairs with group for subdirectories.

IMPORTANT

group requires mode: 'directory'. Pairing group with mode: 'file' (or leaving mode unset) stops the build with KUBB_INVALID_PLUGIN_OPTIONS.

output.barrel

Toggle the export style and depth to see the generated barrels.

  • src/gen/
  • models/
  • Pet.ts
  • User.ts
  • clients/
  • pet/
  • getPetById.ts
  • store/
  • getInventory.ts
src/gen/index.ts

Controls how the generated index.ts (barrel) re-exports the output. Accepts { type: 'named' } or { type: 'all' }, optionally with nested: true (for example { type: 'named', nested: true }) to write an index.ts in every subdirectory, or false to skip the barrel entirely. Each generator plugin defaults output.barrel to { type: 'named' }; the root output.barrel on defineConfig defaults to false.

output.banner

Text added to the top of every generated file, such as a license header or @ts-nocheck directive. Pass a string, or a function (meta: BannerMeta) => string that receives the document info (title, description, version, baseURL) and per-file context (filePath, baseName, isBarrel, isAggregation), so a directive can skip barrel files.

Text added to the bottom of every generated file (string or (meta: BannerMeta) => string), like banner but for closing comments. Pair banner: '/* eslint-disable */' with footer: '/* eslint-enable */' to scope a lint disable to the generated file.

group

Switch the mode to see where these operations land on disk.

clients/pet/
  • getPetById
  • addPet
clients/store/
  • getInventory
clients/order/
  • placeOrder
  • getOrderById
clients/user/
  • loginUser
group: { type: "tag" } splits the output by the operation tag, so placeOrder follows its order tag.

Splits generated files into subfolders by the operation's tag or URL path, each under {output.path}/{groupName}/. Without group, every file lands directly in output.path. It applies only to output.mode: 'directory'.

IMPORTANT

Combining group with output.mode: 'file' stops the build with a KUBB_INVALID_PLUGIN_OPTIONS error.

group.type

Property used to assign each operation to a group ('tag' | 'path'), required whenever group is set. An operation with no tag goes in the default group.

  • 'tag' uses the operation's first tag.
  • 'path' uses the first URL segment, such as pet for /pet/{petId}.

group.name

Function turning a group key into a folder or identifier name, typed (context: { group: string }) => string. Defaults to ({ group }) => camelCase(group) for tag groups, while path groups use the URL segment as-is.

client

Selects which registered client plugin the composables call: 'axios' for @kubb/plugin-axios or 'fetch' for @kubb/plugin-fetch. When omitted, the plugin auto-detects the single registered client plugin, so you only need this to disambiguate several. A client plugin must be registered.

infinite

Adds infinite-query output for cursor- or page-based pagination. Pass an object to configure how the cursor is read, or false (the default) to skip. Output is emitted for an operation only when it declares a query parameter matching infinite.queryParam (default 'id') and hooks is also true. Without hooks: true, infinite produces no file at all, not even the factory:

typescript
export function getPetsQueryOptions(/* ... */) {
  return queryOptions({ queryKey, queryFn })
}
typescript
export function getPetsInfiniteQueryOptions(/* ... */) {
  return infiniteQueryOptions({ queryKey, queryFn, initialPageParam, getNextPageParam })
}

export function useGetPetsInfiniteQuery(/* ... */) {
  return useInfiniteQuery(getPetsInfiniteQueryOptions(/* ... */))
}

infinite.queryParam

Name of the query parameter that holds the page cursor. Defaults to 'id'.

infinite.initialPageParam

Initial value for pageParam on the first fetch. Type unknown, default 0.

infinite.nextParam

Path to the next-page cursor on the response, as dot notation ('pagination.next.id') or array form. Type string | string[] | null, default null.

infinite.previousParam

Path to the previous-page cursor, same dot or array form. Type string | string[] | null, default null.

infinite.cursorParam

Deprecated path to the cursor field. Use nextParam and previousParam instead. Type string | null, default null.

query

Decides which operations are treated as queries. The plugin generates a queryOptions factory for each match by default. Pass false to skip, or set hooks to also emit useQuery.

query.methods

HTTP methods treated as queries, default ['GET']. Matching operations generate a queryOptions factory instead of a mutation. Type Array<string>.

query.importPath

Module specifier for the generated import { queryOptions } from '...'. Type string, default '@tanstack/vue-query'.

queryKey

Builds the queryKey for each query composable. The callback receives the operation node and active casing and returns the key array. String values are inlined verbatim, so wrap literals in JSON.stringify(...). Defaults to the built-in queryKeyTransformer.

typescript
queryKey: ({ node }) => [JSON.stringify(node.operationId)]
typescript
export const getUserByNameQueryKey = () => ['getUserByName'] as const

mutation

Decides which operations are treated as mutations. The plugin generates a mutationKey helper for each match by default. Pass false to skip, or set hooks to also emit useMutation.

mutation.methods

HTTP methods treated as mutations, default ['POST', 'PUT', 'PATCH', 'DELETE']. Matching operations generate mutation output instead of a query. Type Array<string>.

mutation.importPath

Module specifier for the generated import { useMutation } from '...', emitted when hooks is set. Type string, default '@tanstack/vue-query'.

mutationKey

Builds the mutationKey for each mutation composable, useful for batching invalidations. It takes the same { node, casing } props as queryKey, inlines strings the same way (wrap literals in JSON.stringify(...)), and defaults to the built-in mutationKeyTransformer.

hooks

Controls whether use* composables are emitted. The default false writes only the queryOptions, queryKey, and mutationKey factory helpers for plain queries and mutations. Set true to also generate useQuery, useInfiniteQuery, and useMutation.

infinite is gated on hooks too, writing nothing while hooks is false.

include

Generates only the operations and schemas that match at least one entry, and skips the rest. Each entry filters by tag, operationId, path, method, contentType, or schemaName, with a pattern that can be a string or a RegExp, both matched as a regular expression against the value. A string pattern is compiled with new RegExp(pattern), so it is not an exact match: pattern: 'pet' also matches 'petType' or 'superpet'.

Type definition
typescript
export type Include = {
  type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType' | 'schemaName'
  pattern: string | RegExp
}

exclude

Skips any operation or schema that matches at least one entry, the opposite of include. Entries use the same type and pattern fields as include, and when both options match an item, exclude wins.

override

Applies different plugin options to operations that match a pattern. Each entry takes the same type and pattern as include, plus an options object that accepts any plugin option except override, so rules cannot nest. The first matching entry merges onto the plugin defaults, and later entries do not stack.

Type definition
typescript
export type Override = {
  type: 'tag' | 'operationId' | 'path' | 'method' | 'contentType' | 'schemaName'
  pattern: string | RegExp
  options: Omit<Partial<Options>, 'override'>
}

resolver

Changes how the plugin names generated files and symbols. Pass a partial patch. Override only the members you want, and anything you omit keeps resolverVueQuery. See Override a resolver for the this context and how a patch layers over the default.

TIP

Inside a method this is the full resolver, so this.default.name(name) reuses the built-in casing.

Partial override
typescript
type ResolverVueQueryPatch = {
  name?(name: string): string
  file?: {
    baseName?(params: { name: string; extname: string }): string
    path?(params: { baseName: string; output: Output }): string
  }
  query?: {
    name?(node: OperationNode): string
    optionsName?(node: OperationNode): string
    keyName?(node: OperationNode): string
    keyTypeName?(node: OperationNode): string
    clientName?(node: OperationNode): string
  }
  infiniteQuery?: { /* same members as query */ }
  mutation?: {
    name?(node: OperationNode): string
    keyName?(node: OperationNode): string
    typeName?(node: OperationNode): string
  }
}

macros

Rewrites AST nodes before they are printed, without forking the generator. Each macro callback (such as schema or operation) receives the node and a context object, and returns a replacement or undefined to leave it as is. Omitted callbacks keep their defaults, and macros run in order, so a later one sees the output of an earlier one.