npm.io
1.0.0 • Published 8 months agoCLI

@swarmica/msw-auto-mock

Licence
MIT
Version
1.0.0
Deps
7
Size
9.3 MB
Vulns
3
Weekly
0
Stars
1

@swarmica/msw-auto-mock

A cli tool to generate stable mock data from OpenAPI descriptions for msw.

Why

We already have all the type definitions from OpenAPI spec so hand-writing every response resolver is completely unnecessary.

Install:

npm i @swarmica/msw-auto-mock -D

Read from your OpenAPI descriptions and output generated code:

# can be http url or a file path on your machine, support both yaml and json.
npx msw-auto-mock http://your_openapi.json -o ./mock

For Node.js integration, you can import from your_output/node.js:

import { server } from './mock/node.js';

Options

  • -o, --output: specify output file path or output to stdout.
  • -t, --includes <keywords>: specify keywords to match if you want to generate mock data only for certain requests, multiple keywords can be seperated with comma.
  • -e, --excludes <keywords>: specify keywords to exclude, multiple keywords can be seperated with comma.
  • --base-url: output code with specified base url or fallback to server host specified in OpenAPI.
  • -c, --codes <keywords>: comma separated list of status codes to generate responses for
  • --typescript: Generate TypeScript files instead of JavaScript files.
  • -h, --help: show help info.

Keywords