@principlestudios/openapi-codegen-typescript-msw
TypeScript icon, indicating that this package has built-in type declarations

0.7.0 • Public • Published

OpenAPI Codegen for TypeScript-friendly MSW testing

Provides an adapter layer method for @principlestudios/openapi-codegen-typescript to integrate with msw.

npm i -D @principlestudios/openapi-codegen-typescript-msw

You must also have dotnet 8.0 runtime installed on your machine.

This will provide a corresponding bin to generate the typescript files.

openapi-codegen-typescript api.yaml api-generated/ -c

You can then create a mock MSW service to handle specific requests:

import { setupServer } from 'msw/node';
import { toMswHandler } from '@principlestudios/openapi-codegen-typescript-msw';
import operations from './api-generated/operations';

const baseDomain = 'http://localhost/';
const findPets = toMswHandler(operations.findPets, { baseDomain });
const server = setupServer(
    findPets(
        { params: { tags: ['dog','cat'], limit: 10 } },
        { statusCode: 200, data: [{ name: 'Fido', tag: 'dog', id: 1234 }], mimeType: 'application/json' }
    )
);

This API will use the type safety from OpenAPI along with msw.

/@principlestudios/openapi-codegen-typescript-msw/

    Package Sidebar

    Install

    npm i @principlestudios/openapi-codegen-typescript-msw

    Weekly Downloads

    1

    Version

    0.7.0

    License

    BSD-2-Clause

    Unpacked Size

    9.71 kB

    Total Files

    5

    Last publish

    Collaborators

    • tonymishler
    • jordanrhode
    • chelfers-sp
    • mdekrey