Browse Source

Optimize file import logic / 优化文件导入逻辑

star7th 4 years ago
parent
commit
99a1e5c2bd

+ 10 - 5
server/Application/Api/Controller/ExportController.class.php

@@ -66,7 +66,8 @@ class ExportController extends BaseController {
                     $data .= "<h1>{$value['page_title']}</h1>";
                 }
                 $data .= '<div style="margin-left:20px;">';
-                $value['page_content'] = D("Export")->runapiToMd($value['page_content']);
+                $tmp_content = D("Page")->runapiToMd($value['page_content']) ;
+                $value['page_content'] = $tmp_content ? $tmp_content : $value['page_content'] ;
                 $data .= htmlspecialchars_decode($Parsedown->text($value['page_content']));
                 $data .= '</div>';
                 $parent ++;
@@ -82,7 +83,8 @@ class ExportController extends BaseController {
                         foreach ($value['pages'] as $page) {
                             $data .= "<h2>{$parent}.{$child}、{$page['page_title']}</h2>";
                             $data .= '<div style="margin-left:0px;">';
-                            $page['page_content'] = D("Export")->runapiToMd($page['page_content']);
+                            $tmp_content = D("Page")->runapiToMd($page['page_content']) ;
+                            $page['page_content'] = $tmp_content ? $tmp_content : $page['page_content'] ;
                             $data .= htmlspecialchars_decode($Parsedown->text($page['page_content']));
                             $data .= '</div>';
                             $child ++;
@@ -98,7 +100,8 @@ class ExportController extends BaseController {
                                     foreach ($value3['pages'] as $page3) {
                                         $data .= "<h3>{$parent}.{$parent2}.{$child2}、{$page3['page_title']}</h3>";
                                         $data .= '<div style="margin-left:0px;">';
-                                        $page3['page_content'] = D("Export")->runapiToMd($page3['page_content']);
+                                        $tmp_content = D("Page")->runapiToMd($page3['page_content']) ;
+                                        $page3['page_content'] = $tmp_content ? $tmp_content : $page3['page_content'] ;
                                         $data .= htmlspecialchars_decode($Parsedown->text($page3['page_content']));
                                         $data .= '</div>';
                                         $child2 ++;
@@ -115,7 +118,8 @@ class ExportController extends BaseController {
                                                 foreach ($value4['pages'] as $page4) {
                                                     $data .= "<h3>{$parent}.{$parent2}.{$parent3}.{$child3}、{$page4['page_title']}</h3>";
                                                     $data .= '<div style="margin-left:30px;">';
-                                                    $page4['page_content'] = D("Export")->runapiToMd($page4['page_content']);
+                                                    $tmp_content = D("Page")->runapiToMd($page4['page_content']) ;
+                                                    $page4['page_content'] = $tmp_content ? $tmp_content : $page4['page_content'] ;
                                                     $data .= htmlspecialchars_decode($Parsedown->text($page4['page_content']));
                                                     $data .= '</div>';
                                                     $child3 ++;
@@ -131,7 +135,8 @@ class ExportController extends BaseController {
                                                             foreach ($value4['pages'] as $page5) {
                                                                 $data .= "<h3>{$parent}.{$parent2}.{$parent3}.{$parent4}.{$child4}、{$page5['page_title']}</h3>";
                                                                 $data .= '<div style="margin-left:30px;">';
-                                                                $page5['page_content'] = D("Export")->runapiToMd($page5['page_content']);
+                                                                $tmp_content = D("Page")->runapiToMd($page5['page_content']) ;
+                                                                $page5['page_content'] = $tmp_content ? $tmp_content : $page5['page_content'] ;
                                                                 $data .= htmlspecialchars_decode($Parsedown->text($page5['page_content']));
                                                                 $data .= '</div>';
                                                                 $child3 ++;

+ 14 - 136
server/Application/Api/Controller/ImportPostmanController.class.php

@@ -122,75 +122,13 @@ class ImportPostmanController extends BaseController {
 
     private function _requestToDoc($request){
         $from = I("from") ? I("from") : '' ;
+        $res = $this->_requestToApi($request);
         if($from == 'runapi'){
-            return $this->_requestToApi($request);
-            //如果是来自runapi的导入请求,则已经return不再执行下面
+            return $res ;
+        }else{
+            $res['page_content'] = D("Page")->runapiToMd($res['page_content']); 
+            return $res ;
         }
-        $return = array() ;
-        $return['page_title'] = $request['name'] ;
-        $return['id'] = $request['id'] ;
-        $return['s_number'] = 99 ;
-        $return['page_comments'] = '' ;
-        //若$return['page_title'] 为很长的url,则做一些特殊处理
-        $tmp_title_array = explode("/", $return['page_title']);
-        if ($tmp_title_array) {
-            $tmp_title_array = array_slice($tmp_title_array, -2);// 倒数2个
-            if($tmp_title_array[1])$return['page_title'] = $tmp_title_array[0]."/".$tmp_title_array[1] ;
-        }
-        
-        $content = '  
-**简要描述:** 
-
-- '.$request['description'].'
-
-**请求URL:** 
-- ` '.$request['url'].' `
-  
-**请求方式:**
-- '.$request['method'].' ';
-
-if ($request['headerData']) {
-$content .='
-
-**Header:** 
-
-|Header名|是否必选|类型|说明|
-|:----    |:---|:----- |-----   |'."\n";
-    foreach ($request['headerData'] as $key => $value) {
-         $content .= '|'.$value["key"].' |  | text | '.$value["value"].' |'."\n";
-    }
-}
-
-if ($request['rawModeData']) {
-$content .= '
-
-
- **请求参数示例**
-
-``` 
-'.$request['rawModeData'].'
-```
-
-';
-
-}
-
-if ($request['data']) {
-$content .='
-
-**参数:** 
-
-|参数名|是否必选|类型|说明|
-|:----    |:---|:----- |-----   |'."\n";
-    foreach ($request['data'] as $key => $value) {
-         $content .= '|'.$value["key"].' |   |'.$value["type"].' | 无 |'."\n";
-    }
-}
-
-
-        $return['page_content'] = $content ;
-        return $return ;
-
     }
 
     //转成runapi所需要的api格式
@@ -331,77 +269,13 @@ $content .='
 
     private function _requestToDocV2($name , $request){
         $from = I("from") ? I("from") : '' ;
+        $res = $this->_requestToApiV2($name , $request);
         if($from == 'runapi'){
-            return $this->_requestToApiV2($name , $request);
-            //如果是来自runapi的导入请求,则已经return不再执行下面
+            return $res ;
+        }else{
+            $res['page_content'] = D("Page")->runapiToMd($res['page_content']); 
+            return $res ;
         }
-        $return = array() ;
-        $return['page_title'] = $name ;
-        $return['s_number'] = 99 ;
-        $return['page_comments'] = '' ;
-        //若$return['page_title'] 为很长的url,则做一些特殊处理
-        $tmp_title_array = explode("/", $return['page_title']);
-        if ($tmp_title_array) {
-            $tmp_title_array = array_slice($tmp_title_array, -2);// 倒数2个
-            if($tmp_title_array[1])$return['page_title'] = $tmp_title_array[0]."/".$tmp_title_array[1] ;
-        }
-
-        $url = is_array($request['url']) ? $request['url']['raw'] : $request['url'] ;
-        $rawModeData = $request['body']['mode'] == 'raw' ? $request['body']['raw']  : $request['rawModeData'] ;
-
-        $content = '  
-**简要描述:** 
-
-- '.$request['description'].'
-
-**请求URL:** 
-- ` '.$url.' `
-  
-**请求方式:**
-- '.$request['method'].' ';
-
-if ($request['header']) {
-$content .='
-
-**Header:** 
-
-|Header名|是否必选|类型|说明|
-|:----    |:---|:----- |-----   |'."\n";
-    foreach ($request['header'] as $key => $value) {
-         $content .= '|'.$value["key"].' |  |  | '.$value["value"].' |'."\n";
-    }
-}
-
-if ($rawModeData) {
-$content .= '
-
-
- **请求参数示例**
-
-``` 
-'.$rawModeData.'
-```
-
-';
-
-}
-
-if ($request['body']['formdata']) {
-$content .='
-
-**参数:** 
-
-|参数名|是否必选|类型|说明|
-|:----    |:---|:----- |-----   |'."\n";
-    foreach ($request['body']['formdata'] as $key => $value) {
-         $content .= '|'.$value["key"].' |   |'.$value["type"].' | 无 |'."\n";
-    }
-}
-
-
-        $return['page_content'] = $content ;
-        return $return ;
-
     }
 
     //转成runapi所需要的api格式
@@ -468,6 +342,10 @@ $content .='
                     );
             }
         }
+        else if($rawModeData && json_decode($rawModeData)){
+            $content_array['request']['params']['mode'] = 'json';
+            $content_array['request']['params']['json'] = $rawModeData;
+        }
 
         $return['page_content'] = json_encode($content_array) ;
 

+ 76 - 154
server/Application/Api/Controller/ImportSwaggerController.class.php

@@ -3,6 +3,8 @@ namespace Api\Controller;
 use Think\Controller;
 class ImportSwaggerController extends BaseController {
 
+    public $json_array = array();
+    public $url_pre =  '';
 
     public function import(){
         $login_user = $this->checkLogin();
@@ -13,6 +15,8 @@ class ImportSwaggerController extends BaseController {
         $json_array = json_decode($json ,1 );
         unset($json);
         if ($json_array['info']) {
+            $this->json_array = $json_array ;
+            $this->url_pre = $json_array['schemes'][0]."://".$json_array['host'].$json_array['basePath'] ;
             $this->_fromSwaggerV2($json_array);
             return ;
         }
@@ -100,107 +104,13 @@ class ImportSwaggerController extends BaseController {
 
     private function _requestToDoc($method , $url , $request , $json_array){
         $from = I("from") ? I("from") : '' ;
+        $res = $this->_requestToApi($method , $url , $request , $json_array);
         if($from == 'runapi'){
-            return $this->_requestToApi($method , $url , $request , $json_array);
-            //如果是来自runapi的导入请求,则已经return不再执行下面
+            return $res ;
+        }else{
+            $res['page_content'] = D("Page")->runapiToMd($res['page_content']); 
+            return $res ;
         }
-        $return = array() ;
-        $return['page_title'] =  $request['summary'] ? $request['summary']: $request['operationId'] ;
-        $return['s_number'] = 99 ;
-        $return['page_comments'] = '' ;
-        
-        $content = '  
-**简要描述:** 
-
-- '.$request['description'].' 
-
-**请求URL:** 
-- ` '.$url.' `
-  
-**请求方式:**
-- '.$method.' ';
-
-if ($request['header']) {
-$content .='
-
-**Header:** 
-
-|Header名|是否必选|类型|说明|
-|:----    |:---|:----- |-----   |'."\n";
-    foreach ($request['headerData'] as $key => $value) {
-         $content .= '|'.$value["key"].' |  | text | '.$value["value"].' |'."\n";
-    }
-}
-
-if ($request['rawModeData']) {
-$content .= '
-
-
- **请求参数示例**
-
-``` 
-'.$request['rawModeData'].'
-```
-
-';
-
-}
-
-if ($request['parameters']) {
-$content .='
-
-**参数:** 
-
-|参数名|是否必选|类型|说明|
-|:----    |:---|:----- |-----   |'."\n";
-    foreach ($request['parameters'] as $key => $value) {
-         $content .= '|'.$value["name"].' | '.($value["required"] ? '是' : '否' ).'  |'.$value["type"].' | '.$value["description"].' |'."\n";
-    }
-}
-
-if ($request['responses']['200']) {
-
-$responses = $request['responses']['200'] ;
-//如果返回信息是引用对象
-if ($request['responses']['200']['schema'] && $request['responses']['200']['schema']['$ref'] ) {
-    $str_array = explode("/", $request['responses']['200']['schema']['$ref']) ;
-    if ($str_array[1] && $str_array[2]) {
-        $responses = $json_array[$str_array[1]][$str_array[2]] ;
-$content .='
-
-**返回参数说明:** 
-
-|参数名|类型|说明|
-|:----    |:---|:----- |-----   |'."\n";
-    foreach ($responses['properties'] as $key => $value) {
-         $content .= '|'.$key.'|'.$value["type"].' | '.$value["description"].' |'."\n";
-    }
-    
-    }
-    
-}else{
-    //如果返回的是普通json
-$content .= '
-
-
- **返回示例**
-
-``` 
-
-'.$this->_indent_json(json_encode($responses)).'
-
-```
-
-';
-}
-
-
-
-}
-
-        $return['page_content'] = $content ;
-        return $return ;
-
     }
 
     private function _requestToApi($method , $url , $request , $json_array){
@@ -216,13 +126,14 @@ $content .= '
                     "title" =>  $request['summary'] ? $request['summary']: $request['operationId']   ,
                     "description" =>  $request['description']  ,
                     "method" =>  strtolower($method)  ,
-                    "url" =>  $url  ,
+                    "url" =>  $this->url_pre . $url   ,
                     "remark" =>  '' ,
                 ),
                 "request" =>array(
                     "params"=> array(
                         'mode' => "formdata",
                         'json' => "",
+                        'jsonDesc' => array(),
                         'urlencoded' => array(),
                         'formdata' => array(),
                     ),
@@ -250,78 +161,89 @@ $content .= '
         if ($request['parameters']) {
 
             foreach ($request['parameters'] as $key => $value) {
-                 $content_array['request']['params']['formdata'][] = array(
+                // 如果in字段是body的话,应该就是参数为json的情况了
+                if($value["in"] == 'body'){
+                    $ref_str = $value['schema']['$ref'] ;
+                    //如果含有引用标识,则获取引用
+                    if($ref_str){
+                        $ref_array = $this->_getDefinition($ref_str);
+                    }else{
+                        $ref_array = $value['schema'] ;
+                    }
+                    $json_array = $this->_definitionToJsonArray($ref_array);
+                    $json_str = $this->_jsonArrayToStr($json_array);
+                    $content_array['request']['params']['mode'] = 'json';
+                    $content_array['request']['params']['json'] = $json_str;
+                    $content_array['request']['params']['jsonDesc'] = $json_array;
+                }else{
+                    $content_array['request']['params']['formdata'][] = array(
                         "name" =>$value["name"],
                         "type" =>'string',
                         "value" =>$value["value"],
                         "require" =>'1',
                         "remark" =>$value["description"],
                     );
+                }
+
             }
         }
 
+        //处理返回结果情况
+        if($request['responses'] && $request['responses']['200']){
+            $ref_str = $request['responses']['200']['schema']['$ref'] ;
+            //如果含有引用标识,则获取引用
+            if($ref_str){
+                $ref_array = $this->_getDefinition($ref_str);
+            }else{
+                $ref_array = $request['responses']['200']['schema'] ;
+            }
+            $json_array = $this->_definitionToJsonArray($ref_array);
+            $json_str = $this->_jsonArrayToStr($json_array);
+            $content_array['response']['responseExample'] = $json_str;
+            $content_array['response']['responseParamsDesc'] = $json_array;
+        }
+
         $return['page_content'] = json_encode($content_array);
         return $return ;
 
     }
 
+    // 获取引用,返回数组。
+    //$ref_str 是swagger里引用的字符串,比如"#/definitions/Petoo"
+    private function _getDefinition($ref_str){
+        $json_array = $this->json_array ;
+        $str_array = explode('#/definitions/',$ref_str);
+        $path = $str_array1[1];
+        $target_array = $json_array['definitions'][$str_array[1]] ;
+        if($target_array){
+            return $target_array ;
+        }
+        return false;
+    }
 
-    /**
-     * Indents a flat JSON string to make it more human-readable.
-     *
-     * @param string $json The original JSON string to process.
-     *
-     * @return string Indented version of the original JSON string.
-     */
-    private function _indent_json($json) {
-
-        $result      = '';
-        $pos         = 0;
-        $strLen      = strlen($json);
-        $indentStr   = '  ';
-        $newLine     = "\n";
-        $prevChar    = '';
-        $outOfQuotes = true;
-
-        for ($i=0; $i<=$strLen; $i++) {
-
-            // Grab the next character in the string.
-            $char = substr($json, $i, 1);
-
-            // Are we inside a quoted string?
-            if ($char == '"' && $prevChar != '\\') {
-                $outOfQuotes = !$outOfQuotes;
-
-            // If this character is the end of an element,
-            // output a new line and indent the next line.
-            } else if(($char == '}' || $char == ']') && $outOfQuotes) {
-                $result .= $newLine;
-                $pos --;
-                for ($j=0; $j<$pos; $j++) {
-                    $result .= $indentStr;
-                }
-            }
-
-            // Add the character to the result string.
-            $result .= $char;
-
-            // If the last character was the beginning of an element,
-            // output a new line and indent the next line.
-            if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
-                $result .= $newLine;
-                if ($char == '{' || $char == '[') {
-                    $pos ++;
-                }
+    //把引用类型的数组转换成纯json数组
+    private function _definitionToJsonArray($ref_array){
+        $res = array() ;
+        foreach ($ref_array['properties'] as $key => $value) {
+            $res[] = array(
+                "name" =>$key,
+                "type" =>'string',
+                "value" =>'',
+                "require" =>'1',
+                "remark" =>$value["title"],
+            );
+        }
+        return $res ;
 
-                for ($j = 0; $j < $pos; $j++) {
-                    $result .= $indentStr;
-                }
-            }
+    }
 
-            $prevChar = $char;
+    // 把json数组转成纯json字符串
+    private function _jsonArrayToStr($json_array){
+        $res_array = array() ;
+        foreach ($json_array as $key => $value) {
+            $res_array[$value['name']] = '' ;
         }
-
-        return $result;
+        return json_encode($res_array) ;  
     }
 
 }

+ 0 - 113
server/Application/Api/Model/ExportModel.class.php

@@ -9,118 +9,5 @@ class ExportModel  {
 
     Protected $autoCheckFields = false;  //一定要关闭字段缓存,不然会报找不到表的错误
 
-    //把runapi的格式内容转换为markdown格式。如果不是runapi格式,则会返回原数据
-    public function runapiToMd($content_json){
-        $content_json = htmlspecialchars_decode($content_json) ;
-        $content = json_decode($content_json , true) ;
-        if(!$content || !$content['info'] || !$content['info']['url'] ){
-            return $content_json ;
-        }
-        $new_content = "
-##### 简要描述
-
- - ".($content['info']['description'] ? $content['info']['description'] :'无') ."
-
-##### 请求URL
-
- - `{$content['info']['url']}`
-
-##### 请求方式
-
- - {$content['info']['method']}
-";
-
-    if($content['request']['headers'] && $content['request']['headers'][0] && $content['request']['headers'][0]['name']){
-        $new_content .= " 
-##### Header 
-
-|header|必选|类型|说明|
-|:-----  |:-----|-----|
-";
-        foreach ($content['request']['headers'] as $key => $value) {
-            $value['require'] = $value['require'] > 0 ? "是" : "否" ;
-            $value['remark'] = $value['remark'] ? $value['remark'] : 无 ;
-            $new_content .= "|{$value['name']}|  {$value['require']} |  {$value['type']} |  {$value['remark']} | \n";
-        } 
-    }
-
-    $params = $content['request']['params'][$content['request']['params']['mode']];
-    if ($params && is_array($params) && $params[0] && $params[0]['name']){
-        $new_content .= " 
-##### 请求参数
-
-|参数名|必选|类型|说明|
-|:-----  |:-----|-----|
-";
-
-    foreach ($params as $key => $value) {
-        $value['require'] = $value['require'] > 0 ? "是" : "否" ;
-        $value['remark'] = $value['remark'] ? $value['remark'] : 无 ;
-        $new_content .= "|{$value['name']}|  {$value['require']} |  {$value['type']} |  {$value['remark']} | \n";
-    }
-    }
-    //如果参数类型为json
-    if($content['request']['params']['mode'] == 'json' && $params){
-        $new_content .= " 
-##### 请求参数示例  
-```
-{$params}
-
-``` 
-"; 
-    }
-        // json字段说明
-        $jsonDesc = $content['request']['params']['jsonDesc'] ;
-        if ($content['request']['params']['mode'] == 'json' && $jsonDesc && $jsonDesc[0] && $jsonDesc[0]['name']){
-            $new_content .= " 
-##### json字段说明
-
-|字段名|必选|类型|说明|
-|:-----  |:-----|-----|
-";
-    
-        foreach ($jsonDesc as $key => $value) {
-            $value['require'] = $value['require'] > 0 ? "是" : "否" ;
-            $value['remark'] = $value['remark'] ? $value['remark'] : 无 ;
-            $new_content .= "|{$value['name']}|  {$value['require']} |  {$value['type']} |  {$value['remark']} | \n";
-        }
-        }
-
-        //返回示例
-        if($content['response']['responseExample']){
-            $new_content .= " 
-##### 返回示例  
-```
-{$content['response']['responseExample']}
-
-``` 
-"; 
-        }
-
-        //返回示例说明
-        if($content['response']['responseParamsDesc'] && $content['response']['responseParamsDesc'][0] && $content['response']['responseParamsDesc'][0]['name']){
-            $new_content .= " 
-##### 返回参数说明 
-
-|参数名|类型|说明|
-|:-----  |:-----|-----|
-";
-            foreach ($content['response']['responseParamsDesc'] as $key => $value) {
-                $value['remark'] = $value['remark'] ? $value['remark'] : 无 ;
-                $new_content .= "|{$value['name']}| {$value['type']} |  {$value['remark']} | \n";
-            }
-        }
-
-        $new_content .= " 
-##### 备注
-
- {$content['info']['remark']}
-";
-
-    
-
-        return $new_content ;
-
-    }
 
 }

+ 178 - 0
server/Application/Api/Model/PageModel.class.php

@@ -169,4 +169,182 @@ class PageModel extends BaseModel {
         return D("Attachment")->deleteFile($file_id) ;
     }
 
+    //把runapi的格式内容转换为markdown格式。如果不是runapi格式,则会返回false
+    //参数content为json字符串或者数组
+    public function runapiToMd($content){
+        if(!is_array($content) ){
+          $content_json = htmlspecialchars_decode($content) ;
+          $content = json_decode($content_json , true) ;
+        }
+        if(!$content || !$content['info'] || !$content['info']['url'] ){
+            return false ;
+        }
+        $new_content = "
+##### 简要描述
+  
+- ".($content['info']['description'] ? $content['info']['description'] :'无') ."
+  
+##### 请求URL
+  
+- `{$content['info']['url']}`
+  
+##### 请求方式
+  
+- {$content['info']['method']}
+  ";
+  
+    if($content['request']['headers'] && $content['request']['headers'][0] && $content['request']['headers'][0]['name']){
+        $new_content .= " 
+##### Header 
+  
+|header|必选|类型|说明|
+|:-----  |:-----|-----|
+  ";
+        foreach ($content['request']['headers'] as $key => $value) {
+            $value['require'] = $value['require'] > 0 ? "是" : "否" ;
+            $value['remark'] = $value['remark'] ? $value['remark'] : '无' ;
+            $new_content .= "|{$value['name']}|  {$value['require']} |  {$value['type']} |  {$value['remark']} | \n";
+        } 
+    }
+  
+    $params = $content['request']['params'][$content['request']['params']['mode']];
+    if ($params && is_array($params) && $params[0] && $params[0]['name']){
+        $new_content .= " 
+##### 请求参数
+  
+|参数名|必选|类型|说明|
+|:-----  |:-----|-----|
+  ";
+  
+    foreach ($params as $key => $value) {
+        $value['require'] = $value['require'] > 0 ? "是" : "否" ;
+        $value['remark'] = $value['remark'] ? $value['remark'] : '无' ;
+        $new_content .= "|{$value['name']}|  {$value['require']} |  {$value['type']} |  {$value['remark']} | \n";
+    }
+    }
+    //如果参数类型为json
+    if($content['request']['params']['mode'] == 'json' && $params){
+        $params = $this->_indent_json($params);
+        $new_content .= " 
+##### 请求参数示例  
+```
+{$params}
+  
+``` 
+  "; 
+    }
+        // json字段说明
+        $jsonDesc = $content['request']['params']['jsonDesc'] ;
+        if ($content['request']['params']['mode'] == 'json' && $jsonDesc && $jsonDesc[0] && $jsonDesc[0]['name']){
+            $new_content .= " 
+##### json字段说明
+  
+|字段名|必选|类型|说明|
+|:-----  |:-----|-----|
+  ";
+    
+        foreach ($jsonDesc as $key => $value) {
+            $value['require'] = $value['require'] > 0 ? "是" : "否" ;
+            $value['remark'] = $value['remark'] ? $value['remark'] : '无' ;
+            $new_content .= "|{$value['name']}|  {$value['require']} |  {$value['type']} |  {$value['remark']} | \n";
+        }
+        }
+  
+        //返回示例
+        if($content['response']['responseExample']){
+          $responseExample = $this->_indent_json($content['response']['responseExample']);
+          $responseExample = $responseExample ? $responseExample : $content['response']['responseExample'] ;
+            $new_content .= " 
+##### 返回示例  
+```
+{$responseExample}
+  
+``` 
+  "; 
+        }
+  
+        //返回示例说明
+        if($content['response']['responseParamsDesc'] && $content['response']['responseParamsDesc'][0] && $content['response']['responseParamsDesc'][0]['name']){
+            $new_content .= " 
+##### 返回参数说明 
+  
+|参数名|类型|说明|
+|:-----  |:-----|-----|
+  ";
+            foreach ($content['response']['responseParamsDesc'] as $key => $value) {
+                $value['remark'] = $value['remark'] ? $value['remark'] : '无' ;
+                $new_content .= "|{$value['name']}| {$value['type']} |  {$value['remark']} | \n";
+            }
+        }
+  
+        $new_content .= " 
+##### 备注
+  
+{$content['info']['remark']}
+  ";
+  
+    
+  
+        return $new_content ;
+  
+    }
+  
+      /**
+       * Indents a flat JSON string to make it more human-readable.
+       *
+       * @param string $json The original JSON string to process.
+       *
+       * @return string Indented version of the original JSON string.
+       */
+      private function _indent_json($json) {
+  
+        $result      = '';
+        $pos         = 0;
+        $strLen      = strlen($json);
+        $indentStr   = '  ';
+        $newLine     = "\n";
+        $prevChar    = '';
+        $outOfQuotes = true;
+  
+        for ($i=0; $i<=$strLen; $i++) {
+  
+            // Grab the next character in the string.
+            $char = substr($json, $i, 1);
+  
+            // Are we inside a quoted string?
+            if ($char == '"' && $prevChar != '\\') {
+                $outOfQuotes = !$outOfQuotes;
+  
+            // If this character is the end of an element,
+            // output a new line and indent the next line.
+            } else if(($char == '}' || $char == ']') && $outOfQuotes) {
+                $result .= $newLine;
+                $pos --;
+                for ($j=0; $j<$pos; $j++) {
+                    $result .= $indentStr;
+                }
+            }
+  
+            // Add the character to the result string.
+            $result .= $char;
+  
+            // If the last character was the beginning of an element,
+            // output a new line and indent the next line.
+            if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
+                $result .= $newLine;
+                if ($char == '{' || $char == '[') {
+                    $pos ++;
+                }
+  
+                for ($j = 0; $j < $pos; $j++) {
+                    $result .= $indentStr;
+                }
+            }
+  
+            $prevChar = $char;
+        }
+  
+        return $result;
+    }
+
 }