Plugin
plugins: [pluginMsw()]Officialv5.0.12kubb >=5.8.3node >=22
MSW
@kubb/plugin-msw
Generates MSW request handlers from your OpenAPI spec so you can mock the API in tests and during local development.
kubb add plugin-msw
mswmock-service-workerapi-mockingmockstestingcodegenopenapi
- Downloads286.8K/ monthnpm, last 30 days
- GitHub stars8kubb-labs/plugins
- Unpacked size183.6kBv5.0.12 on npm
- Latest release9h agov5.0.12 · Oct 13, 2026
The MSW plugin generates a typed MSW request handler for each operation in your OpenAPI spec.
Each handler returns the data you pass to it. With parser: 'faker', a handler called without data returns mock data from @kubb/plugin-faker. Only operations with a success response schema get mock data.
Installation
bun add -d @kubb/plugin-mswpnpm add -D @kubb/plugin-mswnpm install --save-dev @kubb/plugin-mswyarn add -D @kubb/plugin-mswOr run kubb add plugin-msw to install the version the Kubb registry pins and add pluginMsw() to kubb.config.ts.
Setup
- Add
@kubb/plugin-tsfor the request and response types. - Add
@kubb/plugin-fakerwhen you setparser: 'faker', and install@faker-js/fakerv10. The defaultdataparser does not need it. - Install
mswv2 in the app that uses the generated code.
Options worth knowing
parsersets where the response body comes from:data(default) orfaker.handlerswrites ahandlers.tsfile that exports every handler, ready to spread intosetupServerorsetupWorker.baseURLis prepended to the path each handler matches.
See Options for every option and its default.
Example
The config below generates one handler per operation and a handlers.ts file that exports them all.
kubb.config.ts
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginMsw } from '@kubb/plugin-msw'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
plugins: [
pluginTs(),
pluginMsw({ output: { path: 'handlers', mode: 'directory' }, handlers: true }),
],
})Dependencies
Extensions that must be in the same config as MSW.