Configure generation
Use these configurations in a project with Kubb installed and an OpenAPI specification. Replace ./petStore.yaml with your specification path, install the packages for your stack, then run npx kubb generate. Each plugin page shows its single-plugin configuration. The stacks below combine several plugins.
./src/gen. With clean: true, Kubb removes that directory before generation, so keep handwritten files elsewhere.Pick a stack
Types, an Axios client, and TanStack Query hooks for React.
npm install -D kubb typescript @kubb/plugin-ts @kubb/plugin-axios @kubb/plugin-react-query
npm install axios react @tanstack/react-queryimport { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginAxios } from '@kubb/plugin-axios'
import { pluginReactQuery } from '@kubb/plugin-react-query'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen', clean: true },
plugins: [pluginTs(), pluginAxios(), pluginReactQuery({ hooks: true })],
})Types, an Axios client, and TanStack Query composables for Vue.
npm install -D kubb typescript @kubb/plugin-ts @kubb/plugin-axios @kubb/plugin-vue-query
npm install axios vue @tanstack/vue-queryimport { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginAxios } from '@kubb/plugin-axios'
import { pluginVueQuery } from '@kubb/plugin-vue-query'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen', clean: true },
plugins: [pluginTs(), pluginAxios(), pluginVueQuery({ hooks: true })],
})Runtime validation with Zod, plus MSW request handlers backed by Faker.js mock data.
npm install -D kubb typescript @kubb/plugin-ts @kubb/plugin-zod @kubb/plugin-faker @kubb/plugin-msw
npm install zod msw @faker-js/fakerimport { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginZod } from '@kubb/plugin-zod'
import { pluginFaker } from '@kubb/plugin-faker'
import { pluginMsw } from '@kubb/plugin-msw'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen', clean: true },
plugins: [pluginTs(), pluginZod(), pluginFaker(), pluginMsw({ parser: 'faker', handlers: true })],
})To call the API with the global fetch instead of Axios, replace pluginAxios with pluginFetch from @kubb/plugin-fetch.
Format, lint, and run commands after generation
Set format and lint to a tool name, or to 'auto' to pick whichever tool is installed. output.postGenerate runs shell commands once the files are formatted and linted. Install the tools first, for example npm install -D @biomejs/biome oxlint.
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
export default defineConfig({
input: './petStore.yaml',
output: {
path: './src/gen',
clean: true,
format: 'biome',
lint: 'oxlint',
postGenerate: ['npm run typecheck'],
},
plugins: [pluginTs()],
})Read the spec from a git repository
Point input at a file in a git repository when the spec lives in another repo, such as the API's own. Write it as git+<repo>#<ref>:<path>, and pin <ref> to a tag or commit so every run generates from the same spec:
import { defineConfig } from 'kubb/config'
export default defineConfig({
input: 'git+https://github.com/org/api.git#v2.1.0:specs/openapi.yaml',
output: { path: './src/gen' },
})Kubb needs git on the PATH and uses your own git credentials, so a private repository works with the credential helper or SSH key you already use. In CI, give the job read access to that repository. See input for the full format.
Watch mode, several specifications, and scripts
- Run
kubb generate --watchto regenerate when the local spec file changes. A URL or git input is generated once, so rerun Kubb after the remote spec changes. Pass a function todefineConfigto readwatchand keepcleanoff during incremental runs. See Config formats. - Pass an array to
defineConfigto generate from several specifications in one run, each with its own plugins and output directory. Set anameper entry so the CLI output tells them apart. - Drive Kubb from a script with
createKubbwhen you orchestrate builds or inspect diagnostics. - Run
kubb validatebefore generation in CI to fail on an invalid specification.