yapi
yapi copied to clipboard
接口数据编辑保存失败
版本号
1.5.0
什么问题
编辑并保存带有tag的接口报错 接口的up方法没有传project_id,代码逻辑中的autoAddTag需要用到project_id
如何复现此问题
接口有tag然后编辑之后不能正常保存
什么浏览器
Chrome
什么系统(Linux, Windows, macOS)
Linux
前端代码和后端代码的字段没匹配上, v1.10.2 仍然有这个问题 https://github.com/YMFE/yapi/blob/59bade3a8a43e7db077d38a4b0c7c584f30ddf8c/server/controllers/interface.js#L396C17-L396C17
async autoAddTag(params) {
//检查是否提交了目前不存在的tag
let tags = params.tag;
if (tags && Array.isArray(tags) && tags.length > 0) {
let projectData = await this.projectModel.get(params.project_id);// 前端传的是params.id,后端读的是params.project_id
let tagsInProject = projectData.tag;
let needUpdate = false;
if (tagsInProject && Array.isArray(tagsInProject) && tagsInProject.length > 0) {
tags.forEach(tag => {
if (!_.find(tagsInProject, item => {
return item.name === tag;
})) {//tag不存在
needUpdate = true;
tagsInProject.push({
name: tag,
desc: tag
});
}
});
} else {
needUpdate = true
tagsInProject = []
tags.forEach(tag => {
tagsInProject.push({
name: tag,
desc: tag
});
});
}
if (needUpdate) {//需要更新tag
let data = {
tag: tagsInProject,
up_time: yapi.commons.time()
};
await this.projectModel.up(params.project_id, data);// 前端传的是params.id,后端读的是params.project_id
}
}
}
有人改了,但作者没合并:https://github.com/YMFE/yapi/pull/2374/commits/c8e7b1f2e3b5a0bcea50ad2cd4795efb3a552f06 或者用社区的方案,自己改代码:https://github.com/YMFE/yapi/pull/2374#issuecomment-1208022757