From 85023e9b8a8ca0938f23715e2644bf6c83362053 Mon Sep 17 00:00:00 2001
From: suxiaoxin <hellosean1025@163.com>
Date: Mon, 30 Oct 2017 17:15:21 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20swagger=20import=20data=20=E5=AF=BC?=
 =?UTF-8?q?=E5=85=A5=E6=97=B6=E5=87=BA=E7=8E=B0=E7=9A=84=20id=20=E6=9C=AA?=
 =?UTF-8?q?=E5=AE=9A=E4=B9=89bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Project/Setting/ProjectData/ProjectData.js      |  3 +--
 exts/yapi-plugin-import-swagger/client.js           | 13 +++++++++----
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/client/containers/Project/Setting/ProjectData/ProjectData.js b/client/containers/Project/Setting/ProjectData/ProjectData.js
index c9d1a106..623067ca 100755
--- a/client/containers/Project/Setting/ProjectData/ProjectData.js
+++ b/client/containers/Project/Setting/ProjectData/ProjectData.js
@@ -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) {
diff --git a/exts/yapi-plugin-import-swagger/client.js b/exts/yapi-plugin-import-swagger/client.js
index 44cffbae..20613120 100644
--- a/exts/yapi-plugin-import-swagger/client.js
+++ b/exts/yapi-plugin-import-swagger/client.js
@@ -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;