mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-15 05:10:47 +08:00
fix: 修改文档
This commit is contained in:
parent
a93e379875
commit
6a8d2e842a
@ -30,7 +30,7 @@
|
||||
|
||||
<span id = "mock"></span>
|
||||
### 2.1 Mock语法规范
|
||||
>参考自:[Mock.js 官网](http://mockjs.com/)
|
||||
>了解更多Mock详情:[Mock.js 官方文档](https://github.com/nuysoft/Mock/wiki/Syntax-Specification)
|
||||
|
||||
Mock.js 的语法规范包括两部分:
|
||||
|
||||
@ -61,14 +61,17 @@ Mock.js 的语法规范包括两部分:
|
||||
'name|+step': value
|
||||
```
|
||||
|
||||
生成规则示例:
|
||||
下面提供了6种生成规则以及示例包括 String、Number、Boolean、Object、Array、RegExp:
|
||||
|
||||
#### 1. 属性值是字符串 String
|
||||
|
||||
```
|
||||
1. 'name|min-max': string
|
||||
|
||||
通过重复 string 生成一个字符串,重复次数大于等于 min,小于等于 max。
|
||||
|
||||
2. 'name|count': string
|
||||
|
||||
通过重复 string 生成一个字符串,重复次数等于 count。
|
||||
```
|
||||
#### 2. 属性值是数字 Number
|
||||
@ -139,24 +142,18 @@ Mock.mock({
|
||||
|
||||
通过重复属性值 array 生成一个新数组,重复次数为 count。
|
||||
```
|
||||
#### 6. 属性值是函数 Function
|
||||
```
|
||||
1. 'name': function
|
||||
|
||||
执行函数 function,取其返回值作为最终的属性值,函数的上下文为属性 'name' 所在的对象。
|
||||
```
|
||||
#### 7.属性值是正则表达式 RegExp
|
||||
#### 6.属性值是正则表达式 RegExp
|
||||
```
|
||||
1. 'name': regexp
|
||||
|
||||
根据正则表达式 regexp 反向生成可以匹配它的字符串。用于生成自定义格式的字符串。
|
||||
根据正则表达式 regexp 反向生成可以匹配它的字符串,用于生成自定义格式的字符串。
|
||||
|
||||
例如:
|
||||
Mock.mock({
|
||||
{
|
||||
'regexp1': /[a-z][A-Z][0-9]/,
|
||||
'regexp2': /\w\W\s\S\d\D/,
|
||||
'regexp3': /\d{5,10}/
|
||||
})
|
||||
}
|
||||
// =>
|
||||
{
|
||||
"regexp1": "pJ7",
|
||||
@ -166,38 +163,29 @@ Mock.mock({
|
||||
```
|
||||
<span id = "DPD"></span>
|
||||
### 数据占位符定义规范(Data Placeholder Definition,DPD)
|
||||
|
||||
```
|
||||
占位符 只是在属性值字符串中占个位置,并不出现在最终的属性值中。
|
||||
|
||||
占位符 的格式为:
|
||||
```
|
||||
|
||||
@占位符
|
||||
@占位符(参数 [, 参数])
|
||||
|
||||
说明:
|
||||
1. 用 @ 来标识其后的字符串是 占位符。
|
||||
2. 占位符 引用的是 Mock.Random 中的方法。
|
||||
3. 通过 Mock.Random.extend() 来扩展自定义占位符。
|
||||
4. 占位符 也可以引用 数据模板 中的属性。
|
||||
5. 占位符 会优先引用 数据模板 中的属性。
|
||||
6. 占位符 支持 相对路径 和 绝对路径。
|
||||
1. 用 @ 来标识其后的字符串是 占位符,在YApi提供的Mock输入框在输入“@”后会自动提示占位符。
|
||||
|
||||
Mock.mock({
|
||||
name: {
|
||||
first: '@FIRST',
|
||||
middle: '@FIRST',
|
||||
last: '@LAST',
|
||||
full: '@first @middle @last'
|
||||
}
|
||||
})
|
||||
例如:
|
||||
name: {
|
||||
first: '@FIRST',
|
||||
middle: '@FIRST',
|
||||
last: '@LAST',
|
||||
full: '@first @middle @last'
|
||||
}
|
||||
// 上面的示例可以得到如下结果:
|
||||
{
|
||||
"name": {
|
||||
"first": "Charles",
|
||||
"middle": "Brenda",
|
||||
"last": "Lopez",
|
||||
"full": "Charles Brenda Lopez"
|
||||
}
|
||||
"name": {
|
||||
"first": "Charles",
|
||||
"middle": "Brenda",
|
||||
"last": "Lopez",
|
||||
"full": "Charles Brenda Lopez"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -670,7 +670,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#62" target="_blank">./server/controllers/user.js:62</a>
|
||||
<a href="./static/server/controllers/user.js.html#63" target="_blank">./server/controllers/user.js:63</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -703,7 +703,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#159" target="_blank">./server/controllers/user.js:159</a>
|
||||
<a href="./static/server/controllers/user.js.html#160" target="_blank">./server/controllers/user.js:160</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -799,7 +799,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#228" target="_blank">./server/controllers/user.js:228</a>
|
||||
<a href="./static/server/controllers/user.js.html#229" target="_blank">./server/controllers/user.js:229</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -896,7 +896,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#300" target="_blank">./server/controllers/user.js:300</a>
|
||||
<a href="./static/server/controllers/user.js.html#301" target="_blank">./server/controllers/user.js:301</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -966,7 +966,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#328" target="_blank">./server/controllers/user.js:328</a>
|
||||
<a href="./static/server/controllers/user.js.html#329" target="_blank">./server/controllers/user.js:329</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1028,7 +1028,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#366" target="_blank">./server/controllers/user.js:366</a>
|
||||
<a href="./static/server/controllers/user.js.html#367" target="_blank">./server/controllers/user.js:367</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1090,7 +1090,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#397" target="_blank">./server/controllers/user.js:397</a>
|
||||
<a href="./static/server/controllers/user.js.html#398" target="_blank">./server/controllers/user.js:398</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1182,7 +1182,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#456" target="_blank">./server/controllers/user.js:456</a>
|
||||
<a href="./static/server/controllers/user.js.html#457" target="_blank">./server/controllers/user.js:457</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -1260,7 +1260,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/user.js.html#502" target="_blank">./server/controllers/user.js:502</a>
|
||||
<a href="./static/server/controllers/user.js.html#503" target="_blank">./server/controllers/user.js:503</a>
|
||||
</p>
|
||||
|
||||
|
||||
@ -2300,7 +2300,7 @@
|
||||
|
||||
<p>
|
||||
<small class="text-muted">源码位置:</small>
|
||||
<a href="./static/server/controllers/project.js.html#403" target="_blank">./server/controllers/project.js:403</a>
|
||||
<a href="./static/server/controllers/project.js.html#404" target="_blank">./server/controllers/project.js:404</a>
|
||||
</p>
|
||||
|
||||
|
||||
|
@ -85,7 +85,7 @@
|
||||
<p><img src="http://note.youdao.com/yws/api/personal/file/WEB1d1f7dc7b83a8cd6f576953cf45e9719?method=download&shareKey=99b4af9baac527b969543dd0a909d2a1" width = "800" style="margin:0px auto;display:block;" alt="图片名称" align=center /></p>
|
||||
<p><span id = "mock"></span></p>
|
||||
<h3 class="subject" id="2.1_Mock语法规范">2.1 Mock语法规范 <a class="hashlink" href="#2.1_Mock语法规范">#</a></h3><blockquote>
|
||||
<p>参考自:<a href="http://mockjs.com/">Mock.js 官网</a></p>
|
||||
<p>了解更多Mock详情:<a href="https://github.com/nuysoft/Mock/wiki/Syntax-Specification">Mock.js 官方文档</a></p>
|
||||
</blockquote>
|
||||
<p>Mock.js 的语法规范包括两部分:</p>
|
||||
<p><a href="#DTD">1. 数据模板定义规范(Data Template Definition,DTD)</a></p>
|
||||
@ -106,11 +106,13 @@
|
||||
'name|count.dmin-dmax'<span class="token operator">:</span> value
|
||||
'name|count.dcount'<span class="token operator">:</span> value
|
||||
'name|+step'<span class="token operator">:</span> value
|
||||
</code></pre><p>生成规则示例:</p>
|
||||
</code></pre><p>下面提供了6种生成规则以及示例包括 String、Number、Boolean、Object、Array、RegExp:</p>
|
||||
<h4 class="subject" id="1._属性值是字符串_String">1. 属性值是字符串 String <a class="hashlink" href="#1._属性值是字符串_String">#</a></h4><pre><code><span class="token number">1</span>. 'name|min-max'<span class="token operator">:</span> string
|
||||
|
||||
通过重复 string 生成一个字符串,重复次数大于等于 min,小于等于 max。
|
||||
|
||||
<span class="token number">2</span>. 'name|count'<span class="token operator">:</span> string
|
||||
|
||||
通过重复 string 生成一个字符串,重复次数等于 count。
|
||||
</code></pre><h4 class="subject" id="2._属性值是数字_Number">2. 属性值是数字 Number <a class="hashlink" href="#2._属性值是数字_Number">#</a></h4><pre><code><span class="token number">1</span>. 'name|+<span class="token number">1</span>'<span class="token operator">:</span> number
|
||||
|
||||
@ -167,19 +169,16 @@ Mock.mock(<span class="token punctuation">{</span>
|
||||
<span class="token number">4</span>. 'name|count'<span class="token operator">:</span> array
|
||||
|
||||
通过重复属性值 array 生成一个新数组,重复次数为 count。
|
||||
</code></pre><h4 class="subject" id="6._属性值是函数_Function">6. 属性值是函数 Function <a class="hashlink" href="#6._属性值是函数_Function">#</a></h4><pre><code><span class="token number">1</span>. 'name'<span class="token operator">:</span> function
|
||||
</code></pre><h4 class="subject" id="6.属性值是正则表达式_RegExp">6.属性值是正则表达式 RegExp <a class="hashlink" href="#6.属性值是正则表达式_RegExp">#</a></h4><pre><code><span class="token number">1</span>. 'name'<span class="token operator">:</span> regexp
|
||||
|
||||
执行函数 function,取其返回值作为最终的属性值,函数的上下文为属性 'name' 所在的对象。
|
||||
</code></pre><h4 class="subject" id="7.属性值是正则表达式_RegExp">7.属性值是正则表达式 RegExp <a class="hashlink" href="#7.属性值是正则表达式_RegExp">#</a></h4><pre><code><span class="token number">1</span>. 'name'<span class="token operator">:</span> regexp
|
||||
|
||||
根据正则表达式 regexp 反向生成可以匹配它的字符串。用于生成自定义格式的字符串。
|
||||
根据正则表达式 regexp 反向生成可以匹配它的字符串,用于生成自定义格式的字符串。
|
||||
|
||||
例如:
|
||||
Mock.mock(<span class="token punctuation">{</span>
|
||||
<span class="token punctuation">{</span>
|
||||
'regexp1'<span class="token operator">:</span> /<span class="token punctuation">[</span>a-z<span class="token punctuation">]</span><span class="token punctuation">[</span>A-Z<span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">0</span>-<span class="token number">9</span><span class="token punctuation">]</span>/<span class="token punctuation">,</span>
|
||||
'regexp2'<span class="token operator">:</span> /\w\W\s\S\d\D/<span class="token punctuation">,</span>
|
||||
'regexp3'<span class="token operator">:</span> /\d<span class="token punctuation">{</span><span class="token number">5</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">}</span>/
|
||||
<span class="token punctuation">}</span><span class="token punctuation">)</span>
|
||||
<span class="token punctuation">}</span>
|
||||
// =>
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token property">"regexp1"</span><span class="token operator">:</span> <span class="token string">"pJ7"</span><span class="token punctuation">,</span>
|
||||
@ -187,35 +186,28 @@ Mock.mock(<span class="token punctuation">{</span>
|
||||
<span class="token property">"regexp3"</span><span class="token operator">:</span> <span class="token string">"561659409"</span>
|
||||
<span class="token punctuation">}</span>
|
||||
</code></pre><p><span id = "DPD"></span></p>
|
||||
<h3 class="subject" id="数据占位符定义规范(Data_Placeholder_Definition,DPD)">数据占位符定义规范(Data Placeholder Definition,DPD) <a class="hashlink" href="#数据占位符定义规范(Data_Placeholder_Definition,DPD)">#</a></h3><p>占位符 只是在属性值字符串中占个位置,并不出现在最终的属性值中。</p>
|
||||
<p>占位符 的格式为:</p>
|
||||
<pre><code>@占位符
|
||||
@占位符(参数 <span class="token punctuation">[</span><span class="token punctuation">,</span> 参数<span class="token punctuation">]</span><span class="token punctuation">)</span>
|
||||
<h3 class="subject" id="数据占位符定义规范(Data_Placeholder_Definition,DPD)">数据占位符定义规范(Data Placeholder Definition,DPD) <a class="hashlink" href="#数据占位符定义规范(Data_Placeholder_Definition,DPD)">#</a></h3><pre><code>占位符 只是在属性值字符串中占个位置,并不出现在最终的属性值中。
|
||||
|
||||
占位符 的格式为:
|
||||
|
||||
@占位符
|
||||
|
||||
说明:
|
||||
<span class="token number">1</span>. 用 @ 来标识其后的字符串是 占位符。
|
||||
<span class="token number">2</span>. 占位符 引用的是 Mock.Random 中的方法。
|
||||
<span class="token number">3</span>. 通过 Mock.Random.extend(<span class="token punctuation">)</span> 来扩展自定义占位符。
|
||||
<span class="token number">4</span>. 占位符 也可以引用 数据模板 中的属性。
|
||||
<span class="token number">5</span>. 占位符 会优先引用 数据模板 中的属性。
|
||||
<span class="token number">6</span>. 占位符 支持 相对路径 和 绝对路径。
|
||||
<span class="token number">1</span>. 用 @ 来标识其后的字符串是 占位符,在YApi提供的Mock输入框在输入“@”后会自动提示占位符。
|
||||
|
||||
Mock.mock(<span class="token punctuation">{</span>
|
||||
name<span class="token operator">:</span> <span class="token punctuation">{</span>
|
||||
first<span class="token operator">:</span> '@FIRST'<span class="token punctuation">,</span>
|
||||
middle<span class="token operator">:</span> '@FIRST'<span class="token punctuation">,</span>
|
||||
last<span class="token operator">:</span> '@LAST'<span class="token punctuation">,</span>
|
||||
full<span class="token operator">:</span> '@first @middle @last'
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token punctuation">}</span><span class="token punctuation">)</span>
|
||||
例如:
|
||||
name<span class="token operator">:</span> <span class="token punctuation">{</span>
|
||||
first<span class="token operator">:</span> '@FIRST'<span class="token punctuation">,</span>
|
||||
middle<span class="token operator">:</span> '@FIRST'<span class="token punctuation">,</span>
|
||||
last<span class="token operator">:</span> '@LAST'<span class="token punctuation">,</span>
|
||||
full<span class="token operator">:</span> '@first @middle @last'
|
||||
<span class="token punctuation">}</span>
|
||||
// 上面的示例可以得到如下结果:
|
||||
<span class="token punctuation">{</span>
|
||||
<span class="token property">"name"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token property">"first"</span><span class="token operator">:</span> <span class="token string">"Charles"</span><span class="token punctuation">,</span>
|
||||
<span class="token property">"middle"</span><span class="token operator">:</span> <span class="token string">"Brenda"</span><span class="token punctuation">,</span>
|
||||
<span class="token property">"last"</span><span class="token operator">:</span> <span class="token string">"Lopez"</span><span class="token punctuation">,</span>
|
||||
<span class="token property">"full"</span><span class="token operator">:</span> <span class="token string">"Charles Brenda Lopez"</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token property">"name"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
|
||||
<span class="token property">"first"</span><span class="token operator">:</span> <span class="token string">"Charles"</span><span class="token punctuation">,</span>
|
||||
<span class="token property">"middle"</span><span class="token operator">:</span> <span class="token string">"Brenda"</span><span class="token punctuation">,</span>
|
||||
<span class="token property">"last"</span><span class="token operator">:</span> <span class="token string">"Lopez"</span><span class="token punctuation">,</span>
|
||||
<span class="token property">"full"</span><span class="token operator">:</span> <span class="token string">"Charles Brenda Lopez"</span>
|
||||
<span class="token punctuation">}</span>
|
||||
</code></pre><h2 class="subject" id="未来计划推出功能">未来计划推出功能 <a class="hashlink" href="#未来计划推出功能">#</a></h2><ol>
|
||||
<li>可视化JSON编辑器,可定义JSON_Schema和mockjs</li><li>支持HTTP和RPC协议</li><li>自动化测试</li><li>多人协作</li></ol>
|
||||
|
@ -87,7 +87,7 @@ class baseController {
|
||||
|
||||
async getLoginStatus(ctx) {
|
||||
if (await this.checkLogin(ctx) === true) {
|
||||
let result = yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time']);
|
||||
let result = yapi.commons.fieldSelect(this.$user, ['_id', 'username', 'email', 'up_time', 'add_time','role']);
|
||||
result.server_ip = yapi.WEBCONFIG.server_ip;
|
||||
return ctx.body = yapi.commons.resReturn(result);
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
handleBasepath(basepath) {
|
||||
if (!basepath) return false;
|
||||
if (basepath === '/') return basepath;
|
||||
if (!basepath) return "";
|
||||
if (basepath === '/') return "";
|
||||
if (basepath[0] !== '/') basepath = '/' + basepath;
|
||||
if (basepath[basepath.length - 1] === '/') basepath = basepath.substr(0, basepath.length - 1);
|
||||
if (!yapi.commons.verifyPath(basepath)) {
|
||||
@ -99,13 +99,13 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在的项目名');
|
||||
}
|
||||
|
||||
if (!params.basepath) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目basepath不能为空');
|
||||
}
|
||||
|
||||
if (!params.prd_host) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
|
||||
}
|
||||
|
||||
params.basepath = params.basepath || '';
|
||||
|
||||
if ((params.basepath = this.handleBasepath(params.basepath)) === false) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误');
|
||||
}
|
||||
@ -359,6 +359,7 @@ class projectController extends baseController {
|
||||
try {
|
||||
let id = ctx.request.body.id;
|
||||
let params = ctx.request.body;
|
||||
params.basepath = params.basepath || '';
|
||||
params = yapi.commons.handleParams(params, {
|
||||
name: 'string',
|
||||
basepath: 'string',
|
||||
|
@ -75,6 +75,7 @@ class userController extends baseController {
|
||||
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
username: result.username,
|
||||
role: result.role,
|
||||
uid: result._id,
|
||||
email: result.email,
|
||||
add_time: result.add_time,
|
||||
|
Loading…
Reference in New Issue
Block a user