Skip to content
Officialv5.0.10MITkubb >=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
286.8K/ mo
Stars
8
Bundle size
174.8 kB
Updated
36m ago

Generate typed MSW handlers from OpenAPI.

  • Supply response data in tests.
  • Generate mock responses with Faker.

Installation

bun add -d @kubb/plugin-msw

Or run kubb add plugin-msw to install the version the Kubb registry pins and add pluginMsw() to kubb.config.ts.

Dependencies

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

Example

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 }),
  ],
})

See also