# openapi-mock-middleware

> ## Installation

Latest version **1.0.13** (published 2022-06-02) · 0 weekly downloads

## Install

```sh
npm install openapi-mock-middleware
pnpm add openapi-mock-middleware
yarn add openapi-mock-middleware
bun add openapi-mock-middleware
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.13 |
| Published | 2022-06-02 |
| First published | 2021-12-27 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 22 |
| Unpacked size | 628.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | maxx5 |

## Links

- npm: https://www.npmjs.com/package/openapi-mock-middleware
- npm.io page: https://npm.io/package/openapi-mock-middleware

## Dependencies (22)

- [ajv](https://npm.io/package/ajv.md) ^8.11.0
- [jade](https://npm.io/package/jade.md) ^1.11.0
- [user](https://npm.io/package/user.md) 0.0.0
- [debug](https://npm.io/package/debug.md) ^4.3.4
- [chance](https://npm.io/package/chance.md) ^1.1.8
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [morgan](https://npm.io/package/morgan.md) ^1.10.0
- [express](https://npm.io/package/express.md) ^4.17.3
- [chokidar](https://npm.io/package/chokidar.md) ^3.5.3
- [prettier](https://npm.io/package/prettier.md) ^2.6.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.19.2
- [http-errors](https://npm.io/package/http-errors.md) ^2.0.0
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.6
- [openapi-types](https://npm.io/package/openapi-types.md) ^10.0.0
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^6.2.0
- [@faker-js/faker](https://npm.io/package/@faker-js/faker.md) ^6.1.1
- [method-override](https://npm.io/package/method-override.md) ^3.0.0
- [json-schema-faker](https://npm.io/package/json-schema-faker.md) ^0.5.0-rcv.42
- [eslint-config-prettier](https://npm.io/package/eslint-config-prettier.md) ^8.5.0
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) ^4.0.0
- [@apidevtools/swagger-parser](https://npm.io/package/@apidevtools/swagger-parser.md) ^10.0.3
- [@apidevtools/swagger-express-middleware](https://npm.io/package/@apidevtools/swagger-express-middleware.md) ^4.0.2

## Recent versions

- 1.0.13 (latest) — 2022-06-02
- 1.0.12 — 2022-06-02
- 1.0.11 — 2022-06-02
- 1.0.10 — 2022-05-06
- 1.0.7 — 2022-04-02
- 1.0.6 — 2022-01-09
- 1.0.5 — 2022-01-09
- 1.0.4 — 2022-01-09
- 1.0.3 — 2022-01-08
- 1.0.2 — 2022-01-08
- 1.0.1 — 2021-12-27
- 1.0.0 — 2021-12-27

## README

# openapi-mock-middleware

## Installation

Generating mock data using open API file

## Usage

npm i openapi-mock-middleware

```js
const express = require('express');
const createMockMiddleware = require('openapi-mock-middleware');

const app = express();

app.use(
  '/api',
  createMockMiddleware({
    request: {
      spec: ['./example'], // apiSpec。支持file, dir,  array。
      ignore: [/\.js$/], // 扫描目录时忽略的文件 string, RegExp or array
      ext: ['.yml', '.json'], // API文件后缀格式：string or array
      isValidate: true, // 是否开启校验: 开启之后将校验请求的 header、path、query、body。
    },
    response: {
      locale: 'zh', // json-schema-faker locale, default to 'en'
      options: {
        // json-schema-faker options
        /**
         * alwaysFakeOptionals-当启用时，它会设置optionalsProbability: 1.0和 fixedProbabilities: true（默认值：false）
         * optionalsProbability— 一个值 from 0.0to1.0以一致的方式生成值，例如0.5将生成 from 0%to 50%of 的值。使用数组这意味着项目，在对象上他们的属性等。（默认值：false）
         * fixedProbabilities-如果启用，那么optionalsProbability: 0.5总是会生成值的一半（默认值：false）
         */
        alwaysFakeOptionals: true,
        useExamplesValue: true, //如果启用，它会返回一个随机值从examples它们是否存在
        // useDefaultValue-如果启用，它将返回default值，如果存在（默认：false）
      },
      callback: (jsf, faker) => {
        // function where you can extend json-schema-faker
        // ...
      },
    },
  })
);

app.listen(8090, () =>
  console.log('Server listening on http://localhost:8090')
);
```

参考：【[openapi-mock-express-middleware](https://github.com/aleksandryackovlev/openapi-mock-express-middleware)】

---
_Source: https://npm.io/package/openapi-mock-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
