Skip to content

Migration: @kubb/plugin-msw

Part of the v4 → v5 migration guide. For the full option reference, see @kubb/plugin-msw.

resolver.resolveName takes over from transformers.name. The contentType option moved to adapterOas, covered in Migration: @kubb/adapter-oas. Every other option stays the same.

Generated output

Handlers are now typed against the request body and headers, and they take an HttpResponseResolver callback in place of an inline MSW handler signature.

typescript
export function createUserHandler(
  data?: string | number | boolean | null | object | ((info: Parameters<Parameters<typeof http.post>[1]>[0]) => Response | Promise<Response>),
) {
  return http.post('http://localhost:3000/user', function handler(info) {
    ...
  })
}
typescript
import type { HttpResponseResolver } from 'msw'
import type { CreateUserData } from '../../../models/CreateUser.ts'

export function createUserHandler(
  data?: string | number | boolean | null | object | HttpResponseResolver<Record<string, string>, CreateUserData, any>,
) {
  return http.post<Record<string, string>, CreateUserData, any>(`http://localhost:3000/user`, function handler(info) {
    ...
  })
}