fix: json schema 默认全部解析

This commit is contained in:
gaoxiaolin.gao 2018-07-10 16:03:45 +08:00
parent 14fdde4b6d
commit d77e51e07c
3 changed files with 31 additions and 30 deletions

View File

@ -997,7 +997,7 @@ class interfaceController extends baseController {
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;

View File

@ -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

View File

@ -35,6 +35,7 @@ formats.forEach(item => {
exports.schemaToJson = function(schema, options = {}) {
Object.assign(options, defaultOptions);
jsf.option(options);
let result;
try {
@ -559,8 +560,9 @@ exports.sendNotice = async function sendNotice(projectId, data) {
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 projectMenbers = projectList.members
.filter(item => item.email_notice)
.map(item => item.uid);
const users = arrUnique(projectMenbers, starUsers);
const usersInfo = await userInst.findByUids(users);
@ -578,12 +580,9 @@ exports.sendNotice = async function sendNotice(projectId, data) {
};
function arrUnique(arr1, arr2) {
let arr = arr1.concat(arr2);
let res = arr.filter(function(item, index, arr) {
return arr.indexOf(item) === index;
});
return res;
}