mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-06 15:00:26 +08:00
fix: format-data 数据解析不成功
This commit is contained in:
parent
7e5ef96867
commit
854badbedc
@ -1,9 +1,12 @@
|
||||
### v1.3.16
|
||||
|
||||
* 支持自定义域名邮箱登录
|
||||
|
||||
|
||||
#### Bug Fixed
|
||||
|
||||
* postman headers 为 null 时报错
|
||||
* format-data 数据解析不成功
|
||||
|
||||
|
||||
### v1.3.15
|
||||
|
@ -40,11 +40,14 @@
|
||||
```
|
||||
{
|
||||
"name": "${query.name}", //请求的url是/path?name=xiaoming, 返回的name字段是xiaoming
|
||||
"type": "${body.type}" //请求的requestBody type=1,返回的type字段是1
|
||||
"type": "${body.type}", //请求的requestBody type=1,返回的type字段是1
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
3. 示例
|
||||
```
|
||||
/**
|
||||
|
@ -84,7 +84,7 @@ const StatusOverview = (props) => (
|
||||
<Col className="gutter-row" span={6}>
|
||||
<span>
|
||||
系统空闲内存总量 / 内存总量
|
||||
<Tooltip placement="rightTop" title="统计yapi所有项目中的所有测试接口总数">
|
||||
<Tooltip placement="rightTop" title="系统空闲内存总量 / 内存总量">
|
||||
<Icon className="m-help" type="question-circle" />
|
||||
</Tooltip>
|
||||
</span>
|
||||
|
77
package-lock.json
generated
77
package-lock.json
generated
@ -6560,6 +6560,11 @@
|
||||
"resolved": "http://registry.npm.taobao.org/format-util/download/format-util-1.0.3.tgz",
|
||||
"integrity": "sha1-Ay3KShFiYqEsQ/TD7IVmQWxbLZU="
|
||||
},
|
||||
"formidable": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "http://registry.npm.taobao.org/formidable/download/formidable-1.2.1.tgz",
|
||||
"integrity": "sha1-cPt8oCkO5v+WEJBBX0s989IIJlk="
|
||||
},
|
||||
"forwarded": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "http://registry.npm.taobao.org/forwarded/download/forwarded-0.1.2.tgz",
|
||||
@ -10731,6 +10736,73 @@
|
||||
"vary": "1.1.2"
|
||||
}
|
||||
},
|
||||
"koa-body": {
|
||||
"version": "2.5.0",
|
||||
"resolved": "http://registry.npm.taobao.org/koa-body/download/koa-body-2.5.0.tgz",
|
||||
"integrity": "sha1-hOj82NUimozBy5ipJuk5Bp5xaRU=",
|
||||
"requires": {
|
||||
"co-body": "5.2.0",
|
||||
"formidable": "1.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"bytes": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "http://registry.npm.taobao.org/bytes/download/bytes-3.0.0.tgz",
|
||||
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg="
|
||||
},
|
||||
"co-body": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "http://registry.npm.taobao.org/co-body/download/co-body-5.2.0.tgz",
|
||||
"integrity": "sha1-WgpljEYCkTHg46MG9nZHMC9xwSQ=",
|
||||
"requires": {
|
||||
"inflation": "2.0.0",
|
||||
"qs": "6.5.2",
|
||||
"raw-body": "2.3.3",
|
||||
"type-is": "1.6.16"
|
||||
}
|
||||
},
|
||||
"http-errors": {
|
||||
"version": "1.6.3",
|
||||
"resolved": "http://registry.npm.taobao.org/http-errors/download/http-errors-1.6.3.tgz",
|
||||
"integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=",
|
||||
"requires": {
|
||||
"depd": "1.1.2",
|
||||
"inherits": "2.0.3",
|
||||
"setprototypeof": "1.1.0",
|
||||
"statuses": "1.4.0"
|
||||
}
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.23",
|
||||
"resolved": "http://registry.npm.taobao.org/iconv-lite/download/iconv-lite-0.4.23.tgz",
|
||||
"integrity": "sha1-KXhx9jvlB63Pv8pxXQzQ7thOmmM=",
|
||||
"requires": {
|
||||
"safer-buffer": "2.1.2"
|
||||
}
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.5.2",
|
||||
"resolved": "http://registry.npm.taobao.org/qs/download/qs-6.5.2.tgz",
|
||||
"integrity": "sha1-yzroBuh0BERYTvFUzo7pjUA/PjY="
|
||||
},
|
||||
"raw-body": {
|
||||
"version": "2.3.3",
|
||||
"resolved": "http://registry.npm.taobao.org/raw-body/download/raw-body-2.3.3.tgz",
|
||||
"integrity": "sha1-GzJOzmtXBuFThVvBFIxlu39uoMM=",
|
||||
"requires": {
|
||||
"bytes": "3.0.0",
|
||||
"http-errors": "1.6.3",
|
||||
"iconv-lite": "0.4.23",
|
||||
"unpipe": "1.0.0"
|
||||
}
|
||||
},
|
||||
"setprototypeof": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "http://registry.npm.taobao.org/setprototypeof/download/setprototypeof-1.1.0.tgz",
|
||||
"integrity": "sha1-0L2FU2iHtv58DYGMuWLZ2RxU5lY="
|
||||
}
|
||||
}
|
||||
},
|
||||
"koa-bodyparser": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "http://registry.npm.taobao.org/koa-bodyparser/download/koa-bodyparser-3.2.0.tgz",
|
||||
@ -18726,6 +18798,11 @@
|
||||
"ret": "0.1.10"
|
||||
}
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "http://registry.npm.taobao.org/safer-buffer/download/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha1-RPoWGwGHuVSd2Eu5GAL5vYOFzWo="
|
||||
},
|
||||
"sane": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "http://registry.npm.taobao.org/sane/download/sane-1.6.0.tgz",
|
||||
|
@ -46,6 +46,7 @@
|
||||
"jsondiffpatch": "0.2.5",
|
||||
"jsonwebtoken": "7.4.1",
|
||||
"koa": "2.0.0",
|
||||
"koa-body": "^2.5.0",
|
||||
"koa-bodyparser": "3.2.0",
|
||||
"koa-multer": "1.0.2",
|
||||
"koa-mysql-session": "0.0.2",
|
||||
|
@ -13,7 +13,8 @@ const websocket = require('./websocket.js');
|
||||
|
||||
const Koa = require('koa');
|
||||
const koaStatic = require('koa-static');
|
||||
const bodyParser = require('koa-bodyparser');
|
||||
// const bodyParser = require('koa-bodyparser');
|
||||
const koaBody = require('koa-body')
|
||||
const router = require('./router.js');
|
||||
|
||||
let indexFile = process.argv[2] === 'dev' ? 'dev.html' : 'index.html';
|
||||
@ -23,7 +24,8 @@ const app = websockify(new Koa());
|
||||
app.proxy = true;
|
||||
yapi.app = app;
|
||||
|
||||
app.use(bodyParser({multipart: true}));
|
||||
// app.use(bodyParser({multipart: true}));
|
||||
app.use(koaBody({multipart: true}))
|
||||
app.use(mockServer);
|
||||
app.use(router.routes());
|
||||
app.use(router.allowedMethods());
|
||||
|
@ -220,16 +220,25 @@ module.exports = async (ctx, next) => {
|
||||
const schema = yapi.commons.json_parse(interfaceData.res_body);
|
||||
res = yapi.commons.schemaToJson(schema);
|
||||
} else {
|
||||
// console.log('header', ctx.request.header['content-type'].indexOf('multipart/form-data'))
|
||||
// 处理 format-data
|
||||
if(ctx.request.header['content-type'].indexOf('multipart/form-data') > -1) {
|
||||
ctx.request.body = ctx.request.body.fields;
|
||||
}
|
||||
// console.log('body', ctx.request.body)
|
||||
|
||||
res = mockExtra(yapi.commons.json_parse(interfaceData.res_body), {
|
||||
query: ctx.request.query,
|
||||
body: ctx.request.body,
|
||||
params: Object.assign({}, ctx.request.query, ctx.request.body)
|
||||
});
|
||||
// console.log('res',res)
|
||||
}
|
||||
|
||||
try {
|
||||
res = Mock.mock(res);
|
||||
} catch (e) {
|
||||
console.log('err', e.message)
|
||||
yapi.commons.log(e, "error");
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,20 @@
|
||||
<div class="icon"></div>
|
||||
<input type="text" class="input js-input" placeholder="搜索" />
|
||||
<div class="m-search-result js-search-result"></div>
|
||||
</div></div><nav class="m-header-nav js-nav"><ul class="m-header-items"><li class="item active"><a class="href" href="index.html">教程</a></li><li class="item "><a class="href" href="../devops/index.html">内网部署</a></li></ul></nav><div id="js-nav-btn" class="m-header-btn ui-font-ydoc"></div></header><div class="m-content" id="js-content"><div id="markdown-body" class="m-content-container markdown-body"><h3 id="v1.3.15">v1.3.15</h3>
|
||||
</div></div><nav class="m-header-nav js-nav"><ul class="m-header-items"><li class="item active"><a class="href" href="index.html">教程</a></li><li class="item "><a class="href" href="../devops/index.html">内网部署</a></li></ul></nav><div id="js-nav-btn" class="m-header-btn ui-font-ydoc"></div></header><div class="m-content" id="js-content"><div id="markdown-body" class="m-content-container markdown-body"><h3 id="v1.3.16">v1.3.16</h3>
|
||||
<ul>
|
||||
<li>支持自定义域名邮箱登录</li>
|
||||
</ul>
|
||||
<h4>Bug Fixed</h4>
|
||||
<ul>
|
||||
<li>postman headers 为 null 时报错</li>
|
||||
</ul>
|
||||
<h3 id="v1.3.15">v1.3.15</h3>
|
||||
<ul>
|
||||
<li>增强跨域请求安全性,只允许 YApi 网站进行跨域请求</li>
|
||||
<li>优化文档</li>
|
||||
<li>修复 schema 描述信息展示 bug</li>
|
||||
<li>增加禁止普通用户注册功能</li>
|
||||
</ul>
|
||||
<h3 id="v1.3.14">v1.3.14</h3>
|
||||
<ul>
|
||||
|
@ -37,7 +37,8 @@
|
||||
</ol>
|
||||
<pre><code>{
|
||||
"name": "${query.name}", //请求的url是/path?name=xiaoming, 返回的name字段是xiaoming
|
||||
"type": "${body.type}" //请求的requestBody type=1,返回的type字段是1
|
||||
"type": "${body.type}", //请求的requestBody type=1,返回的type字段是1
|
||||
"value": "${body.fields.value}" // 当header是Content-Type: multipart/form-data 时获取body中的值 (v1.3.16+支持)
|
||||
}
|
||||
|
||||
</code></pre>
|
||||
|
@ -418,7 +418,7 @@ window.ydoc_plugin_search_json = {
|
||||
{
|
||||
"title": "原理",
|
||||
"url": "/documents/mock.html#方式1.-mockjs-原理",
|
||||
"content": "原理基于 mockjs,跟 Mockjs 区别是 yapi 基于 json + 注释 定义 mock 数据,无法使用 mockjs 原有的函数功能。正则表达式需要基于 rule 书写,示例如下:\n{ \"name|regexp\": \"[a-z0-9_]+?\",\n \"type|regexp\": \"json|text|xml\"\n}\n\n支持替换请求的 query, body 参数\n{ \"name\": \"${query.name}\", //请求的url是/path?name=xiaoming, 返回的name字段是xiaoming\n \"type\": \"${body.type}\" //请求的requestBody type=1,返回的type字段是1\n}\n\n示例\n/** * 这是一个接口返回数据示例\n */\n\n{\n \"errcode\": 0,\n \"errmsg\": \"@word\",\n \"data\": {\n \"id\": \"@id\", //@id 随机生成 id\n \"name\": \"@name\" //@name 随机生成用户名\n }\n}\n\n详细使用文档请查看:Mockjs 官网"
|
||||
"content": "原理基于 mockjs,跟 Mockjs 区别是 yapi 基于 json + 注释 定义 mock 数据,无法使用 mockjs 原有的函数功能。正则表达式需要基于 rule 书写,示例如下:\n{ \"name|regexp\": \"[a-z0-9_]+?\",\n \"type|regexp\": \"json|text|xml\"\n}\n\n支持替换请求的 query, body 参数\n{ \"name\": \"${query.name}\", //请求的url是/path?name=xiaoming, 返回的name字段是xiaoming\n \"type\": \"${body.type}\", //请求的requestBody type=1,返回的type字段是1\n \"value\": \"${body.fields.value}\" // 当header是Content-Type: multipart/form-data 时获取body中的值 (v1.3.16+支持)\n}\n\n示例\n/** * 这是一个接口返回数据示例\n */\n\n{\n \"errcode\": 0,\n \"errmsg\": \"@word\",\n \"data\": {\n \"id\": \"@id\", //@id 随机生成 id\n \"name\": \"@name\" //@name 随机生成用户名\n }\n}\n\n详细使用文档请查看:Mockjs 官网"
|
||||
},
|
||||
{
|
||||
"title": "方式2. json-schema",
|
||||
@ -465,7 +465,7 @@ window.ydoc_plugin_search_json = {
|
||||
{
|
||||
"title": "原理",
|
||||
"url": "/documents/mock.html#方式1.-mockjs-原理",
|
||||
"content": "原理基于 mockjs,跟 Mockjs 区别是 yapi 基于 json + 注释 定义 mock 数据,无法使用 mockjs 原有的函数功能。正则表达式需要基于 rule 书写,示例如下:\n{ \"name|regexp\": \"[a-z0-9_]+?\",\n \"type|regexp\": \"json|text|xml\"\n}\n\n支持替换请求的 query, body 参数\n{ \"name\": \"${query.name}\", //请求的url是/path?name=xiaoming, 返回的name字段是xiaoming\n \"type\": \"${body.type}\" //请求的requestBody type=1,返回的type字段是1\n}\n\n示例\n/** * 这是一个接口返回数据示例\n */\n\n{\n \"errcode\": 0,\n \"errmsg\": \"@word\",\n \"data\": {\n \"id\": \"@id\", //@id 随机生成 id\n \"name\": \"@name\" //@name 随机生成用户名\n }\n}\n\n详细使用文档请查看:Mockjs 官网"
|
||||
"content": "原理基于 mockjs,跟 Mockjs 区别是 yapi 基于 json + 注释 定义 mock 数据,无法使用 mockjs 原有的函数功能。正则表达式需要基于 rule 书写,示例如下:\n{ \"name|regexp\": \"[a-z0-9_]+?\",\n \"type|regexp\": \"json|text|xml\"\n}\n\n支持替换请求的 query, body 参数\n{ \"name\": \"${query.name}\", //请求的url是/path?name=xiaoming, 返回的name字段是xiaoming\n \"type\": \"${body.type}\", //请求的requestBody type=1,返回的type字段是1\n \"value\": \"${body.fields.value}\" // 当header是Content-Type: multipart/form-data 时获取body中的值 (v1.3.16+支持)\n}\n\n示例\n/** * 这是一个接口返回数据示例\n */\n\n{\n \"errcode\": 0,\n \"errmsg\": \"@word\",\n \"data\": {\n \"id\": \"@id\", //@id 随机生成 id\n \"name\": \"@name\" //@name 随机生成用户名\n }\n}\n\n详细使用文档请查看:Mockjs 官网"
|
||||
},
|
||||
{
|
||||
"title": "方式2. json-schema",
|
||||
@ -1159,10 +1159,15 @@ window.ydoc_plugin_search_json = {
|
||||
"content": "",
|
||||
"url": "/documents/CHANGELOG.html",
|
||||
"children": [
|
||||
{
|
||||
"title": "v1.3.16",
|
||||
"url": "/documents/CHANGELOG.html#v1.3.16",
|
||||
"content": "v1.3.16支持自定义域名邮箱登录\nBug Fixedpostman headers 为 null 时报错\n"
|
||||
},
|
||||
{
|
||||
"title": "v1.3.15",
|
||||
"url": "/documents/CHANGELOG.html#v1.3.15",
|
||||
"content": "v1.3.15增强跨域请求安全性,只允许 YApi 网站进行跨域请求\n优化文档\n修复 schema 描述信息展示 bug\n"
|
||||
"content": "v1.3.15增强跨域请求安全性,只允许 YApi 网站进行跨域请求\n优化文档\n修复 schema 描述信息展示 bug\n增加禁止普通用户注册功能\n"
|
||||
},
|
||||
{
|
||||
"title": "v1.3.14",
|
||||
@ -1301,10 +1306,15 @@ window.ydoc_plugin_search_json = {
|
||||
"content": "",
|
||||
"url": "/documents/CHANGELOG.html",
|
||||
"children": [
|
||||
{
|
||||
"title": "v1.3.16",
|
||||
"url": "/documents/CHANGELOG.html#v1.3.16",
|
||||
"content": "v1.3.16支持自定义域名邮箱登录\nBug Fixedpostman headers 为 null 时报错\n"
|
||||
},
|
||||
{
|
||||
"title": "v1.3.15",
|
||||
"url": "/documents/CHANGELOG.html#v1.3.15",
|
||||
"content": "v1.3.15增强跨域请求安全性,只允许 YApi 网站进行跨域请求\n优化文档\n修复 schema 描述信息展示 bug\n"
|
||||
"content": "v1.3.15增强跨域请求安全性,只允许 YApi 网站进行跨域请求\n优化文档\n修复 schema 描述信息展示 bug\n增加禁止普通用户注册功能\n"
|
||||
},
|
||||
{
|
||||
"title": "v1.3.14",
|
||||
|
Loading…
x
Reference in New Issue
Block a user