# Mock Service Worker

# Type-safe Handlers

The experimental_openapiMSWPlugin plugin allows you to define MSW handlers in a type-safe way.

To use this client, you need to install the openapi-msw package:

pnpm add openapi-msw
npm install openapi-msw
yarn add openapi-msw

Example usage:

create-schemas.config.ts
import { defineConfig } from "@workleap/create-schemas";
import { experimental_openapiMSWPlugin } from "@workleap/create-schemas/plugins";

export default defineConfig({
    plugins: [experimental_openapiMSWPlugin()]
    input: "v1.yaml",
    outdir: "codegen",
});
import { http } from "./codegen/openapi-msw.ts";

export const handlers = [
    http.get("/good-vibes-points/{userId}", ({ response }) => {
        return response(200).json({ pointx: 50 });
                                 // ^^^^^^ Property "pointx" does not exist on type { points: number }
    }),
];

# Auto-generated handlers

Soon...

See https://source.mswjs.io/