diff --git a/common/mock-extra.js b/common/mock-extra.js index 7eb62b28..c7c3b7e1 100644 --- a/common/mock-extra.js +++ b/common/mock-extra.js @@ -22,17 +22,17 @@ function mock(mockJSON, context) { } else { p[i] = handleStr(p[i]); var filters = i.split(mockSplit), newFilters = [].concat(filters); + c[i] = p[i]; if (filters.length > 1) { for (var f = 1, l = filters.length, index; f < l; f++) { if (filters[f] in filtersMap) { if ((index = newFilters.indexOf(filters[f])) !== -1) { newFilters.splice(index, 1); } + delete c[i]; c[newFilters.join(mockSplit)] = filtersMap[filters[f]].call(p, p[i]); } } - } else { - c[i] = p[i]; } } } diff --git a/server/middleware/mockServer.js b/server/middleware/mockServer.js index cbcb416c..bd332afc 100644 --- a/server/middleware/mockServer.js +++ b/server/middleware/mockServer.js @@ -97,6 +97,8 @@ module.exports = async (ctx, next) => { body: ctx.request.body } ); + console.log(interfaceData.res_body); + console.log(res) return ctx.body = Mock.mock(res); } catch (e) { yapi.commons.log(e, 'error') diff --git a/server_dist/middleware/mockServer.js b/server_dist/middleware/mockServer.js index 5c08692a..7b4c1a56 100644 --- a/server_dist/middleware/mockServer.js +++ b/server_dist/middleware/mockServer.js @@ -51,7 +51,7 @@ function matchApi(apiPath, apiRule) { } 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; return _regenerator2.default.wrap(function _callee$(_context) { @@ -184,7 +184,7 @@ module.exports = function () { ctx.set("Access-Control-Allow-Origin", "*"); if (!(interfaceData.res_body_type === 'json')) { - _context.next = 64; + _context.next = 66; break; } @@ -193,10 +193,13 @@ module.exports = function () { query: ctx.request.query, body: ctx.request.body }); + + console.log(interfaceData.res_body); + console.log(res); return _context.abrupt('return', ctx.body = _mockjs2.default.mock(res)); - case 60: - _context.prev = 60; + case 62: + _context.prev = 62; _context.t2 = _context['catch'](55); _yapi2.default.commons.log(_context.t2, 'error'); @@ -206,22 +209,22 @@ module.exports = function () { data: interfaceData.res_body }); - case 64: + case 66: return _context.abrupt('return', ctx.body = interfaceData.res_body); - case 67: - _context.prev = 67; + case 69: + _context.prev = 69; _context.t3 = _context['catch'](30); console.error(_context.t3); return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 409, _context.t3.message)); - case 71: + case 73: case 'end': return _context.stop(); } } - }, _callee, undefined, [[17, 23], [30, 67], [55, 60]]); + }, _callee, undefined, [[17, 23], [30, 69], [55, 62]]); })); return function (_x, _x2) {