Skip to content

Introduction

Kubb is a meta framework for code generation. It runs a plugin-based pipeline on top of any API specification. An adapter reads your spec. Parsers turn the AST into source files. Plugins generate the output. The pipeline writes, formats, and lints the result, all from a single config file.

The default adapter reads OpenAPI 2.0, 3.0, and 3.1. From there Kubb generates TypeScript types, React Query hooks, Zod validators, MSW mocks, or a custom output. You stop hand-maintaining generated code. The output is deterministic. The same spec always produces the same result.

Features

Ready for more? Read Installation and Basic Usage, then reach for Configuration, Recipes, and Integrations when you need them.

See it work

Watch the pipeline drain a spec like a work queue. Every schema and operation is its own unit of work: the adapter turns each one into an AST node, and every plugin turns that node into its own file. The run below uses this config:

Expand kubb.config.ts
kubb.config.ts
typescript
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
()],
})
kubb.config.ts 4 in queue
src/gen one file per plugin per node
Every schema and operation in the spec is its own unit of work.

The architecture guide covers each layer in depth.

Try the same loop yourself. Install Kubb together with the two plugins from that config:

Terminal
shell
npm install -D kubb@beta @kubb/plugin-ts@beta @kubb/plugin-zod@beta

Write the config above next to your spec and run the generator:

Terminal
shell
kubb generate

Kubb writes one file per schema per plugin into ./src/gen. Import a type and the editor knows your API:

typescript
import type { 
Pet
} from './gen/types/Pet'
const
pet
:
Pet
= {
id
: 1,
name
: 'Cat' }

That is the full cycle. Change the spec, run kubb generate again, and the types follow.

Community

Join the Discord server, file an issue on GitHub, or sponsor the project on GitHub Sponsors or Open Collective.