mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
fix: mockExtra bug
This commit is contained in:
parent
7d28a7b6c1
commit
8ce95a3e7a
@ -22,17 +22,17 @@ function mock(mockJSON, context) {
|
|||||||
} else {
|
} else {
|
||||||
p[i] = handleStr(p[i]);
|
p[i] = handleStr(p[i]);
|
||||||
var filters = i.split(mockSplit), newFilters = [].concat(filters);
|
var filters = i.split(mockSplit), newFilters = [].concat(filters);
|
||||||
|
c[i] = p[i];
|
||||||
if (filters.length > 1) {
|
if (filters.length > 1) {
|
||||||
for (var f = 1, l = filters.length, index; f < l; f++) {
|
for (var f = 1, l = filters.length, index; f < l; f++) {
|
||||||
if (filters[f] in filtersMap) {
|
if (filters[f] in filtersMap) {
|
||||||
if ((index = newFilters.indexOf(filters[f])) !== -1) {
|
if ((index = newFilters.indexOf(filters[f])) !== -1) {
|
||||||
newFilters.splice(index, 1);
|
newFilters.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
delete c[i];
|
||||||
c[newFilters.join(mockSplit)] = filtersMap[filters[f]].call(p, p[i]);
|
c[newFilters.join(mockSplit)] = filtersMap[filters[f]].call(p, p[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c[i] = p[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,8 @@ module.exports = async (ctx, next) => {
|
|||||||
body: ctx.request.body
|
body: ctx.request.body
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
console.log(interfaceData.res_body);
|
||||||
|
console.log(res)
|
||||||
return ctx.body = Mock.mock(res);
|
return ctx.body = Mock.mock(res);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
yapi.commons.log(e, 'error')
|
yapi.commons.log(e, 'error')
|
||||||
|
@ -51,7 +51,7 @@ function matchApi(apiPath, apiRule) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx, next) {
|
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(ctx, next) {
|
||||||
var hostname, config, path, paths, projectId, projectInst, project, interfaceData, newData, newpath, interfaceInst, _newData, findInterface, res;
|
var hostname, config, path, paths, projectId, projectInst, project, interfaceData, newData, newpath, interfaceInst, _newData, findInterface, res;
|
||||||
|
|
||||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||||
@ -184,7 +184,7 @@ module.exports = function () {
|
|||||||
ctx.set("Access-Control-Allow-Origin", "*");
|
ctx.set("Access-Control-Allow-Origin", "*");
|
||||||
|
|
||||||
if (!(interfaceData.res_body_type === 'json')) {
|
if (!(interfaceData.res_body_type === 'json')) {
|
||||||
_context.next = 64;
|
_context.next = 66;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,10 +193,13 @@ module.exports = function () {
|
|||||||
query: ctx.request.query,
|
query: ctx.request.query,
|
||||||
body: ctx.request.body
|
body: ctx.request.body
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(interfaceData.res_body);
|
||||||
|
console.log(res);
|
||||||
return _context.abrupt('return', ctx.body = _mockjs2.default.mock(res));
|
return _context.abrupt('return', ctx.body = _mockjs2.default.mock(res));
|
||||||
|
|
||||||
case 60:
|
case 62:
|
||||||
_context.prev = 60;
|
_context.prev = 62;
|
||||||
_context.t2 = _context['catch'](55);
|
_context.t2 = _context['catch'](55);
|
||||||
|
|
||||||
_yapi2.default.commons.log(_context.t2, 'error');
|
_yapi2.default.commons.log(_context.t2, 'error');
|
||||||
@ -206,22 +209,22 @@ module.exports = function () {
|
|||||||
data: interfaceData.res_body
|
data: interfaceData.res_body
|
||||||
});
|
});
|
||||||
|
|
||||||
case 64:
|
case 66:
|
||||||
return _context.abrupt('return', ctx.body = interfaceData.res_body);
|
return _context.abrupt('return', ctx.body = interfaceData.res_body);
|
||||||
|
|
||||||
case 67:
|
case 69:
|
||||||
_context.prev = 67;
|
_context.prev = 69;
|
||||||
_context.t3 = _context['catch'](30);
|
_context.t3 = _context['catch'](30);
|
||||||
|
|
||||||
console.error(_context.t3);
|
console.error(_context.t3);
|
||||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 409, _context.t3.message));
|
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 409, _context.t3.message));
|
||||||
|
|
||||||
case 71:
|
case 73:
|
||||||
case 'end':
|
case 'end':
|
||||||
return _context.stop();
|
return _context.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, _callee, undefined, [[17, 23], [30, 67], [55, 60]]);
|
}, _callee, undefined, [[17, 23], [30, 69], [55, 62]]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return function (_x, _x2) {
|
return function (_x, _x2) {
|
||||||
|
Loading…
Reference in New Issue
Block a user