Skip to content

Introduction to Kubb: turn your API spec into code

Generate TypeScript types, Axios and Fetch clients, TanStack Query hooks, Zod schemas, and Faker and MSW mocks from an OpenAPI spec with Kubb.

Kubb turns an API spec into the code your app uses to call that API: types, clients, query hooks, validators, and mocks. You pick the outputs with plugins in one kubb.config.ts. When the spec changes, run Kubb again and the code follows.

Generate TypeScript types, Axios and Fetch clients, TanStack Query hooks, Zod schemas, and Faker and MSW mocks from an OpenAPI spec with Kubb.

What Kubb generates

OutputPlugins
TypeScript typesplugin-ts
HTTP clientsplugin-axios, plugin-fetch
Query hooksplugin-react-query, plugin-vue-query, plugin-swr
Validation schemasplugin-zod
Mock data, request handlers, and testsplugin-faker, plugin-msw, plugin-cypress
An MCP server for your APIplugin-mcp
API documentationplugin-redoc

The default OpenAPI adapter reads OpenAPI 2.0, 3.0, 3.1, and 3.2.

See it work

This config generates types and Zod schemas from petStore.yaml:

kubb.config.ts
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginZod } from '@kubb/plugin-zod'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [pluginTs(), pluginZod()],
})

The adapter turns the spec into AST nodes, and each plugin generates files from those nodes. How Kubb works explains each stage.

SPECpetStore.yamlADAPTER@kubb/adapter-oasPLUGINS · config orderpluginTs()KUBB COREpluginZod()PARSER.ts → parser-tsSTORAGEsrc/genfsStorage · skips unchangedPetkind: 'Schema'name: 'Pet'Pet.tsUserkind: 'Schema'name: 'User'User.tsGET /pet/{id}kind: 'Operation'operationId: 'getPet'getPet.tsPOST /petkind: 'Operation'operationId: 'addPet'addPet.ts
Every schema and operation in the spec is its own unit of work.

Start here

You want toRead
Learn by generating a client from a sample specGenerate your first client
Add Kubb to your projectInstallation
Set up a stack, such as React Query with ZodConfigure generation
Rename files or change generated codeResolvers, macros, and printers
Generate during a build or in CIBuild tools and CI
Use Kubb from a browser or an AI assistantStudio and AI assistants
Build a pluginCreate a plugin
Look up an option, command, or APIConfiguration, commands, and Kit API
Understand the pipelineHow Kubb works
Compare Kubb with other generatorsComparison
Upgrade from v4Migration guide

Community

Kubb is free and open source under the MIT license. Ask on Discord, report bugs on GitHub, or read the FAQ.