openapi-ts-mock-generator
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

openapi-ts-mock-generator

This project inpired from msw-auto-mock

  • Generate mock data from openapi.json: schema and paths with responses.
  • Custom mock data: use special fakers.

Usage

  • openapi.json with url
npx openapi-ts-mock-generator http://127.0.0.1/openapi.json
  • openapi.json with file
npx openapi-ts-mock-generator openapi.json

Options

  • -b, --base-dir: base directory for input and output files.
  • -c, --include-codes: include status codes in response.
  • -m, --array-min-length: minimum length of array.
  • -M, --array-max-length: maximum length of array.
  • --special-path: special path for custom mock data.
  • -l, --locales: locales for faker data. look at faker.js Localization use Locale value. ex) ko
  • -s, --static: generate static mock data.
  • --handler-url: handler url for msw.

Special Keys

Special Keys are used for custom mock data. Applied based on title and description. Key is target title or description, value can be value type or faker type.

value type

use value as mock data.

{
  "year": {
    "value": "2024"
  }
}

faker type

generate faker data.

{
  "age": {
    "module": "number",
    "type": "int",
    "options": {
      "min": 0,
      "max": 150
    }
  }
}

Package Sidebar

Install

npm i openapi-ts-mock-generator

Weekly Downloads

13

Version

1.0.11

License

MIT

Unpacked Size

921 kB

Total Files

45

Last publish

Collaborators

  • bill-park