Beta You're reading the docs for Kubb v5, which is currently in beta. View the stable v4 docs
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.

See it work

Here is the whole loop, start to finish. Install Kubb together with one plugin:

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

Create a kubb.config.ts next to your spec. It points at the spec, sets an output directory, and lists the plugins you want. This one generates TypeScript types with @kubb/plugin-ts:

kubb.config.ts
typescript
import {  } from 'kubb'
import {  } from '@kubb/plugin-ts'

export default ({
  : { : './petStore.yaml' },
  : { : './src/gen', : true },
  : [({ : { : 'models' } })],
})

Run the generator:

Terminal
shell
kubb generate

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

typescript
import type {  } from './gen/models/Pet'

const :  = { : 1, : 'Cat' }

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

Features

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

Community

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