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
278.2K/ mo
Stars
8
Bundle size
170.2 kB
Updated
3d ago

Generate typed MSW handlers from OpenAPI.

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

Installation

bun add -d @kubb/plugin-msw

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'
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

Options

Mock API responses

See also