diff --git a/server/controllers/interface.js b/server/controllers/interface.js index 5c910d72..95b11ceb 100755 --- a/server/controllers/interface.js +++ b/server/controllers/interface.js @@ -995,9 +995,9 @@ class interfaceController extends baseController { async schema2json(ctx){ let schema = ctx.request.body.schema; let required = ctx.request.body.required; - + let res = yapi.commons.schemaToJson(schema, { - alwaysFakeOptionals: required ? true : false + alwaysFakeOptionals: _.isUndefined(required) ? true : require }) // console.log('res',res) return ctx.body = res; diff --git a/server/middleware/mockServer.js b/server/middleware/mockServer.js index 12d128be..a3a571a5 100755 --- a/server/middleware/mockServer.js +++ b/server/middleware/mockServer.js @@ -218,7 +218,9 @@ module.exports = async (ctx, next) => { if (interfaceData.res_body_is_json_schema === true) { //json-schema const schema = yapi.commons.json_parse(interfaceData.res_body); - res = yapi.commons.schemaToJson(schema); + res = yapi.commons.schemaToJson(schema, { + alwaysFakeOptionals: true + }); } else { // console.log('header', ctx.request.header['content-type'].indexOf('multipart/form-data')) // 处理 format-data diff --git a/server/utils/commons.js b/server/utils/commons.js index 1bf3e1c9..8e23b7f7 100755 --- a/server/utils/commons.js +++ b/server/utils/commons.js @@ -35,6 +35,7 @@ formats.forEach(item => { exports.schemaToJson = function(schema, options = {}) { Object.assign(options, defaultOptions); + jsf.option(options); let result; try { @@ -274,7 +275,7 @@ exports.sandbox = (sandbox, script) => { script.runInContext(context, { timeout: 3000 }); - + return sandbox; }; @@ -525,13 +526,13 @@ exports.runCaseScript = async function runCaseScript(params) { let result = {}; try { result = yapi.commons.sandbox(context, script); - + result.logs = logs; return yapi.commons.resReturn(result); } catch (err) { logs.push(convertString(err)); result.logs = logs; - + return yapi.commons.resReturn(result, 400, err.name + ': ' + err.message); } }; @@ -552,38 +553,36 @@ exports.getUserdata = async function getUserdata(uid, role) { }; exports.sendNotice = async function sendNotice(projectId, data) { - const followInst = yapi.getInst(followModel); - const userInst = yapi.getInst(userModel); - const projectInst = yapi.getInst(projectModel); - const list = await followInst.listByProjectId(projectId); - const starUsers = list.map(item => item.uid); + const followInst = yapi.getInst(followModel); + const userInst = yapi.getInst(userModel); + const projectInst = yapi.getInst(projectModel); + const list = await followInst.listByProjectId(projectId); + const starUsers = list.map(item => item.uid); - const projectList = await projectInst.get(projectId); - const projectMenbers = projectList.members.filter(item => item.email_notice).map(item => item.uid); + const projectList = await projectInst.get(projectId); + const projectMenbers = projectList.members + .filter(item => item.email_notice) + .map(item => item.uid); + const users = arrUnique(projectMenbers, starUsers); + const usersInfo = await userInst.findByUids(users); + const emails = usersInfo.map(item => item.email).join(','); - const users = arrUnique(projectMenbers, starUsers); - const usersInfo = await userInst.findByUids(users); - const emails = usersInfo.map(item => item.email).join(','); - - try { - yapi.commons.sendMail({ - to: emails, - contents: data.content, - subject: data.title - }); - } catch (e) { - yapi.commons.log('邮件发送失败:' + e, 'error'); - } + try { + yapi.commons.sendMail({ + to: emails, + contents: data.content, + subject: data.title + }); + } catch (e) { + yapi.commons.log('邮件发送失败:' + e, 'error'); + } }; function arrUnique(arr1, arr2) { - let arr = arr1.concat(arr2); - let res = arr.filter(function (item, index, arr) { + let res = arr.filter(function(item, index, arr) { return arr.indexOf(item) === index; }); return res; - } -