fix: swagger import data 导入时出现的 id 未定义bug

This commit is contained in:
suxiaoxin 2017-10-30 17:15:21 +08:00
parent 2bdd6547c8
commit 85023e9b8a
2 changed files with 10 additions and 6 deletions

View File

@ -122,10 +122,9 @@ class ProjectData extends Component {
if (this.props.basePath) {
data.path = data.path.indexOf(this.props.basePath) === 0 ? data.path.substr(this.props.basePath.length) : data.path;
}
if (data.catname && cats[data.catname].id) {
if (data.catname && cats[data.catname] && typeof cats[data.catname] === 'object' && cats[data.catname].id) {
data.catid = cats[data.catname].id;
}
let result = await axios.post('/api/interface/add', data);
count++;
if (result.data.errcode) {

View File

@ -51,7 +51,7 @@ function improtData(importDataModule){
let api = {};
//处理基本信息
api.method = data.method.toUpperCase();
api.title = data.summary;
api.title = data.summary || data.path;
api.desc = data.description;
api.catname = data.tags && Array.isArray(data.tags)? data.tags[0] : null;
api.path = handlePath(data.path);
@ -122,11 +122,16 @@ function improtData(importDataModule){
_.each(api, (res, code)=>{
if(code == 200){
if(res && typeof res === 'object'){
res_body = handleSchema(res.schema);
if(res.schema){
res_body = handleSchema(res.schema);
}else if(res.description){
res_body = res.description;
}
}else if(typeof res === 'string'){
res_body = res;
}else{
res_body = '';
}
}
}
})
return res_body;