Skip to content
Officialv5.0.7MITkubb >=5.0.0node >=22

@kubb/plugin-msw

Generates MSW request handlers from your OpenAPI spec so you can mock the API in tests and during local development.

mswmock-service-workerapi-mockingmockstestingcodegenopenapi
Stijn Van Hulle

Stijn Van Hulle

@stijnvanhulle

Downloads
247.1K/ mo
Stars
8
Bundle size
170.2 kB
Updated
1d ago

@kubb/plugin-msw generates typed MSW handlers from OpenAPI operations. Supply response data in tests or generate it with Faker.

Installation

bun add -d @kubb/plugin-msw

Dependencies

Add pluginTs. Add pluginFaker when parser: 'faker'. The default parser: 'data' does not need it. Generated handlers require MSW v2 or higher.

Example

kubb.config.ts
import { defineConfig } from 'kubb'
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 }),
  ],
})

Documentation

See also