@kubb/plugin-vue-query
@kubb/plugin-vue-query turns each OpenAPI operation into a TanStack Query composable for Vue. Read operations become useFoo, with an optional useFooInfinite variant. Write operations become useFoo mutations. Every composable is typed: query keys, input variables, response data, and error shape all come from the spec.
The composables call an HTTP client, so a client plugin must be registered. Add @kubb/plugin-ts for the types and either @kubb/plugin-axios or @kubb/plugin-fetch for the client. Generation errors out when no client plugin is present.
Each composable takes its parameters as a single grouped options object shaped as { body, path, query, headers }, with camelCase property names. The request still sends the original parameter names from the spec, and Kubb writes that mapping for you.
Installation
bun add -d @kubb/plugin-vue-query@betapnpm add -D @kubb/plugin-vue-query@betanpm install --save-dev @kubb/plugin-vue-query@betayarn add -D @kubb/plugin-vue-query@betaDependencies
This plugin needs these plugins in your config:
@kubb/plugin-tsfor the types.- A client plugin,
@kubb/plugin-axiosor@kubb/plugin-fetch, for the HTTP layer. The composables call its functions, so generation errors out when no client plugin is registered.
For runtime validation, set validator on the client plugin. The generated operations carry the validation, so the composables get it for free.
Example
import { } from 'kubb'
import { } from '@kubb/plugin-ts'
import { } from '@kubb/plugin-axios'
import { } from '@kubb/plugin-vue-query'
export default ({
: { : './petStore.yaml' },
: { : './src/gen' },
: [
(),
(),
({
: { : './hooks' },
: {
: 'tag',
: ({ }) => `${}Hooks`,
},
: 'axios',
: { : ['POST', 'PUT', 'DELETE'] },
: {
: 'next_page',
: 0,
: 'pagination.next.cursor',
},
: {
: ['GET'],
: '@tanstack/vue-query',
},
}),
],
})