mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-01 14:05:44 +08:00
Merge branch 'dev-1.3.0' of gitlab.corp.qunar.com:mfe/yapi into dev-1.3.0
This commit is contained in:
commit
9c23c49a91
@ -231,12 +231,16 @@ export default class Run extends Component {
|
||||
return null
|
||||
}
|
||||
|
||||
let tempJson;
|
||||
if ((tempJson = isJson(result.body))) {
|
||||
let tempJson = result.body;
|
||||
if(tempJson && typeof tempJson === 'object'){
|
||||
result.body = JSON.stringify(tempJson, null, ' ')
|
||||
this.setState({
|
||||
res_body_type: 'json'
|
||||
})
|
||||
}else if (isJson(result.body)) {
|
||||
this.setState({
|
||||
res_body_type: 'json'
|
||||
})
|
||||
}
|
||||
|
||||
this.setState({
|
||||
@ -482,7 +486,7 @@ export default class Run extends Component {
|
||||
</div>
|
||||
}
|
||||
key="3"
|
||||
className={HTTP_METHOD[method].request_body ? 'POST' : 'hidden'}
|
||||
className={HTTP_METHOD[method].request_body && (req_body_type === 'form' && req_body_form.length > 0 || req_body_type !== 'form') ? 'POST' : 'hidden'}
|
||||
>
|
||||
|
||||
<div style={{ display: checkRequestBodyIsRaw(method, req_body_type) ? 'block' : 'none' }}>
|
||||
|
@ -74,15 +74,8 @@ function sandbox(context = {}, script) {
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
// function HandleAfterScript(body, script){
|
||||
// return body;
|
||||
// }
|
||||
|
||||
function crossRequest(options, preScript, afterScript) {
|
||||
// preScript = `query.ttt="hello"; requestBody.aaaa= filter("3333 | md5 | substr:1, 5")`
|
||||
// afterScript = `console.log(responseData); context.responseData='hello'`
|
||||
options = Object.assign({}, options);
|
||||
function crossRequest(defaultOptions, preScript, afterScript) {
|
||||
let options = Object.assign({}, defaultOptions);
|
||||
let urlObj = URL.parse(options.url, true), query = {};
|
||||
query = Object.assign(query, urlObj.query);
|
||||
let context = {
|
||||
@ -103,21 +96,20 @@ function crossRequest(options, preScript, afterScript) {
|
||||
}
|
||||
};
|
||||
|
||||
if (preScript || afterScript) {
|
||||
|
||||
if(preScript){
|
||||
context = sandbox(context, preScript);
|
||||
options.url = URL.format({
|
||||
protocol: urlObj.protocol,
|
||||
host: urlObj.host,
|
||||
query: context.query,
|
||||
pathname: context.pathname
|
||||
})
|
||||
options.headers = context.requestHeader;
|
||||
options.data = context.requestBody;
|
||||
}
|
||||
if (preScript) {
|
||||
context = sandbox(context, preScript);
|
||||
defaultOptions.url = options.url = URL.format({
|
||||
protocol: urlObj.protocol,
|
||||
host: urlObj.host,
|
||||
query: context.query,
|
||||
pathname: context.pathname
|
||||
})
|
||||
defaultOptions.headers = options.headers = context.requestHeader;
|
||||
defaultOptions.data = options.data = context.requestBody;
|
||||
|
||||
}
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
options.error = options.success = function (res, header, data) {
|
||||
let message = '请求异常,请检查 chrome network 错误信息...';
|
||||
@ -129,15 +121,12 @@ function crossRequest(options, preScript, afterScript) {
|
||||
})
|
||||
}
|
||||
|
||||
if(afterScript){
|
||||
|
||||
if (afterScript) {
|
||||
context.responseData = json_parse(data.res.body);
|
||||
context.responseHeader = data.res.header;
|
||||
context.responseStatus = data.res.status;
|
||||
context.runTime = data.runTime;
|
||||
|
||||
context = sandbox(context, afterScript);
|
||||
|
||||
data.res.body = context.responseData;
|
||||
data.res.header = context.responseHeader;
|
||||
}
|
||||
|
@ -128,7 +128,6 @@ export default class InterfaceCaseContent extends Component {
|
||||
enable_script,
|
||||
test_res_body,
|
||||
test_res_header
|
||||
|
||||
};
|
||||
|
||||
const res = await axios.post('/api/col/up_case', params);
|
||||
|
@ -8,7 +8,7 @@ import { Tooltip, Icon, Button, Spin, Modal, message, Select, Switch } from 'ant
|
||||
import { fetchInterfaceColList, fetchCaseList, setColData } from '../../../../reducer/modules/interfaceCol'
|
||||
import HTML5Backend from 'react-dnd-html5-backend';
|
||||
import { DragDropContext } from 'react-dnd';
|
||||
import { isJson, handleParamsValue } from '../../../../common.js'
|
||||
import { json_parse, handleParamsValue } from '../../../../common.js'
|
||||
import AceEditor from 'client/components/AceEditor/AceEditor';
|
||||
import * as Table from 'reactabular-table';
|
||||
import * as dnd from 'reactabular-dnd';
|
||||
@ -183,21 +183,27 @@ class InterfaceColContent extends Component {
|
||||
|
||||
let result = { code: 400,
|
||||
msg: '数据异常',
|
||||
validRes: [],
|
||||
...options
|
||||
validRes: []
|
||||
};
|
||||
|
||||
|
||||
try {
|
||||
let data = await crossRequest(options, interfaceData.pre_script, interfaceData.after_script)
|
||||
let res = data.res.body = isJson(data.res.body);
|
||||
|
||||
let res = data.res.body = json_parse(data.res.body);
|
||||
result = {
|
||||
...options,
|
||||
...result,
|
||||
res_header: data.res.header,
|
||||
res_body: res
|
||||
}
|
||||
|
||||
if(options.data && typeof options.data === 'object'){
|
||||
requestParams = {
|
||||
...requestParams,
|
||||
...options.data
|
||||
}
|
||||
}
|
||||
|
||||
let validRes = [];
|
||||
// 弃用 mock 字段验证功能
|
||||
// if (res && typeof res === 'object') {
|
||||
@ -227,6 +233,7 @@ class InterfaceColContent extends Component {
|
||||
|
||||
} catch (data) {
|
||||
result = {
|
||||
...options,
|
||||
...result,
|
||||
res_header: data.header,
|
||||
res_body: data.body || data.message,
|
||||
|
@ -59,7 +59,7 @@ class projectController extends baseController {
|
||||
},
|
||||
addMember: {
|
||||
"*id": id,
|
||||
"*member_uid": member_uid,
|
||||
"*member_uids": member_uid,
|
||||
"role": role
|
||||
},
|
||||
delMember: {
|
||||
|
Loading…
Reference in New Issue
Block a user