mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-09 05:00:30 +08:00
feat: advMock support mockjs
This commit is contained in:
parent
1295aa6823
commit
d6c9ce97ce
@ -5,6 +5,7 @@
|
||||
1. Api 路径兼容 postman {varible}
|
||||
2. View Response Height 问题
|
||||
3. pathname 允许只有一个 /
|
||||
4. 高级 Mock 期望支持 mockjs
|
||||
|
||||
### v1.2.8
|
||||
|
||||
|
@ -5,7 +5,7 @@ import PropTypes from 'prop-types'
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import { Table, Button, message, Popconfirm, Tooltip, Icon } from 'antd';
|
||||
import { fetchMockCol } from 'client/reducer/modules/mockCol'
|
||||
import { formatTime, getMockText } from 'client/common.js';
|
||||
import { formatTime } from 'client/common.js';
|
||||
import constants from 'client/constants/variable.js'
|
||||
import CaseDesModal from './CaseDesModal';
|
||||
|
||||
@ -98,7 +98,7 @@ export default class MockCol extends Component {
|
||||
delay: 0,
|
||||
headers: [{name: '', value: ''}],
|
||||
params: {},
|
||||
res_body: currInterface.res_body && getMockText(currInterface.res_body)
|
||||
res_body: currInterface.res_body
|
||||
}
|
||||
|
||||
let ipFilters = [];
|
||||
|
@ -7,6 +7,7 @@ const _ = require('underscore');
|
||||
const path = require('path');
|
||||
const lib = require(path.resolve(yapi.WEBROOT, 'common/lib.js' ));
|
||||
const Mock = require('mockjs');
|
||||
const mockExtra = require(path.resolve(yapi.WEBROOT, 'common/mock-extra.js' ))
|
||||
|
||||
function arrToObj(arr){
|
||||
let obj = {'Set-Cookie': []};
|
||||
@ -74,7 +75,7 @@ module.exports = function(){
|
||||
|
||||
}
|
||||
|
||||
async function handleByCase(caseData, context){
|
||||
async function handleByCase(caseData){
|
||||
let caseInst = yapi.getInst(caseModel);
|
||||
let result = await caseInst.get({
|
||||
_id: caseData._id
|
||||
@ -156,8 +157,18 @@ module.exports = function(){
|
||||
let interfaceId = context.interfaceData._id;
|
||||
let caseData = await checkCase(context.ctx, interfaceId);
|
||||
if(caseData){
|
||||
let data = await handleByCase(caseData, context);
|
||||
let data = await handleByCase(caseData);
|
||||
context.mockJson = yapi.commons.json_parse(data.res_body);
|
||||
try{
|
||||
context.mockJson = Mock.mock(mockExtra(context.mockJson, {
|
||||
query: context.ctx.query,
|
||||
body: context.ctx.request.body,
|
||||
params: Object.assign({}, context.ctx.query, context.ctx.request.body)
|
||||
}));
|
||||
}catch(err){
|
||||
yapi.commons.log(err, 'error')
|
||||
}
|
||||
|
||||
context.resHeader = arrToObj(data.headers);
|
||||
context.httpCode = data.code;
|
||||
context.delay = data.delay;
|
||||
|
Loading…
Reference in New Issue
Block a user