Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dxy-f2e/mocker-dsl-core
the lib of api-mocker to build response by schema and request params
https://github.com/dxy-f2e/mocker-dsl-core
Last synced: about 2 months ago
JSON representation
the lib of api-mocker to build response by schema and request params
- Host: GitHub
- URL: https://github.com/dxy-f2e/mocker-dsl-core
- Owner: DXY-F2E
- License: mit
- Created: 2017-09-13T02:08:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-12T09:34:59.000Z (almost 6 years ago)
- Last Synced: 2024-01-23T11:04:50.097Z (12 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 2
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MOCKER-DSL-CORE
通过api-mocker的schema与请求的参数,生成对应的返回结果
## How to use
```javascript
npm install mocker-dsl-core --save
```## API
* `buildExampleFromSchema`: 通过[mock.js](http://mockjs.com/)将schema生成mock数据
* `renderer`: 通过请求参数,生成对应返回结果若希望只引用单个api文件,请引用lib目录,如:
```javascript
var buildExample = require('mocker-dsl-core/lib/buildExampleFromSchema')
```## `renderer` 模板语法
所有的value中包含有 ${...} 的 value,其括号内内容都会识别为模板语言进行编译。例如:
```javascript
// example of schema
{
test: "${name} render success"
}// GET {url}?name=dxy
// response
{
test: "dxy render success"
}
```* 目前模板语言所支持的变量类型为: string, 例如上例中的name会被当成string进行求值。符号表为请求所传入的参数。
* 模板语法天然支持深层次嵌套使用,但暂不支持数组嵌套的数据。