Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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进行求值。符号表为请求所传入的参数。
* 模板语法天然支持深层次嵌套使用,但暂不支持数组嵌套的数据。