Skip to content

Run Kubb with Astro

kubb/astro runs Kubb as an Astro integration. It hooks into Astro's Vite layer and generates during a build. Pass your Kubb config to the config option.

Install

Install kubb as a dev dependency.

shell
bun add -d kubb
shell
pnpm add -D kubb
shell
npm install --save-dev kubb
shell
yarn add -D kubb

Configure

Add the integration to your astro.config.mjs:

astro.config.mjs
typescript
import { defineConfig } from 'astro/config'
import kubb from 'kubb/astro'
import { pluginTs } from '@kubb/plugin-ts'

const config = {
  root: '.',
  input: './petStore.yaml',
  output: { path: './src/gen', clean: true },
  plugins: [pluginTs({ output: { path: 'models' } })],
}

export default defineConfig({
  integrations: [kubb({ config })],
})

NOTE

The Astro integration runs through Vite with apply: 'build', so generation runs during astro build only. Run kubb generate before you start the dev server.