mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-18 13:04:46 +08:00
fix: checkCase 获取 key 最多参数逻辑错误
This commit is contained in:
parent
ec8d65404d
commit
ff16f967e7
@ -61,7 +61,7 @@ module.exports = function(){
|
||||
})
|
||||
}
|
||||
if(matchList.length > 0){
|
||||
let maxItem = _.max(matchList, item=> item.params.length);
|
||||
let maxItem = _.max(matchList, item=> Object.keys(item.params).length);
|
||||
return maxItem;
|
||||
}
|
||||
return null;
|
||||
@ -151,7 +151,7 @@ module.exports = function(){
|
||||
this.bindHook('mock_after', async function(context){
|
||||
let interfaceId = context.interfaceData._id;
|
||||
let caseData = await checkCase(context.ctx, interfaceId);
|
||||
if(caseData !== null){
|
||||
if(caseData){
|
||||
let data = await handleByCase(caseData, context);
|
||||
context.mockJson = data.res_body;
|
||||
context.resHeader = arrToObj(data.headers);
|
||||
@ -183,12 +183,6 @@ module.exports = function(){
|
||||
});
|
||||
sandbox = yapi.commons.sandbox(sandbox, script);
|
||||
sandbox.delay = isNaN(sandbox.delay) ? 0 : +sandbox.delay;
|
||||
let handleMock = new Promise(resolve=>{
|
||||
setTimeout(()=>{
|
||||
resolve(true)
|
||||
}, sandbox.delay)
|
||||
})
|
||||
await handleMock;
|
||||
|
||||
context.mockJson = sandbox.mockJson;
|
||||
context.resHeader = sandbox.resHeader;
|
||||
|
@ -148,6 +148,18 @@ module.exports = async (ctx, next) => {
|
||||
delay: 0
|
||||
}
|
||||
await yapi.emitHook('mock_after', context);
|
||||
let handleMock = new Promise(resolve=>{
|
||||
setTimeout(()=>{
|
||||
resolve(true)
|
||||
}, context.delay)
|
||||
})
|
||||
await handleMock;
|
||||
if(context.resHeader && typeof context.resHeader === 'object'){
|
||||
for(let i in context.resHeader){
|
||||
ctx.set(i, context.resHeader[i]);
|
||||
}
|
||||
}
|
||||
ctx.statusCode = context.httpCode;
|
||||
return ctx.body = context.mockJson;
|
||||
} catch (e) {
|
||||
yapi.commons.log(e, 'error')
|
||||
|
Loading…
Reference in New Issue
Block a user