Authored by 周奇琪

接口文档生成模拟提交

@@ -49,5 +49,8 @@ module.exports = { @@ -49,5 +49,8 @@ module.exports = {
49 }, 49 },
50 '/ajax/link/:name': function(req, res) { 50 '/ajax/link/:name': function(req, res) {
51 uploader.linkFile(req, res); 51 uploader.linkFile(req, res);
  52 + },
  53 + '/proxy':function (req,res) {
  54 + uploader.proxy(req,res);
52 } 55 }
53 } 56 }
@@ -233,4 +233,15 @@ exports.downFile = function(req, res) { @@ -233,4 +233,15 @@ exports.downFile = function(req, res) {
233 exports.getJSONFile=function(req,res){ 233 exports.getJSONFile=function(req,res){
234 console.log(searchDomain); 234 console.log(searchDomain);
235 request.get("http://192.168.10.64:8080/yohosearch/brand/list.json").pipe(res); 235 request.get("http://192.168.10.64:8080/yohosearch/brand/list.json").pipe(res);
  236 +}
  237 +
  238 +exports.proxy = function(req,res) {
  239 + var headers = getHeader(req, res);
  240 + headers['Content-Type'] = 'application/json';
  241 +
  242 + request({
  243 + headers:headers,
  244 + url:domain + req.query.url,
  245 + body:JSON.stringify(req.body)
  246 + }).pipe(res);
236 } 247 }
@@ -53,9 +53,8 @@ @@ -53,9 +53,8 @@
53 <tr> 53 <tr>
54 <th>属性名</th> 54 <th>属性名</th>
55 <th>属性类型</th> 55 <th>属性类型</th>
56 - <th>正则匹配</th>  
57 - <th>长度限制</th>  
58 <th>说明</th> 56 <th>说明</th>
  57 + <th>测试入参</th>
59 </tr> 58 </tr>
60 </thead> 59 </thead>
61 60
@@ -64,9 +63,8 @@ @@ -64,9 +63,8 @@
64 <tr> 63 <tr>
65 <td>{{name}}</td> 64 <td>{{name}}</td>
66 <td>{{type}}</td> 65 <td>{{type}}</td>
67 - <td>{{reg}}</td>  
68 - <td>{{minLength}}-{{maxLength}}</td>  
69 <td>{{message}}</td> 66 <td>{{message}}</td>
  67 + <td><input name="{{name}}" type="text" /></td>
70 </tr> 68 </tr>
71 {{/ params}} 69 {{/ params}}
72 </tbody> 70 </tbody>
@@ -75,7 +73,7 @@ @@ -75,7 +73,7 @@
75 <pre style="display:none"> 73 <pre style="display:none">
76 74
77 </pre> 75 </pre>
78 - <button class="btn btn-success getRes" method="{{method}}" url="{{url}}">点击获取</button> 76 + <button class="btn btn-success getRes" method="{{method}}" url="{{url}}" isjson="{{isJsonRaw}}">点击获取</button>
79 </div> 77 </div>
80 </div> 78 </div>
81 {{/ list}} 79 {{/ list}}
@@ -169,19 +167,31 @@ var formatJson = function(json, options) { @@ -169,19 +167,31 @@ var formatJson = function(json, options) {
169 return formatted; 167 return formatted;
170 }; 168 };
171 $(function(){ 169 $(function(){
172 - $(".panel-minimize").click();  
173 - $(".getRes").click(function(){ 170 + $('.panel-minimize').click();
  171 + $('.getRes').click(function(){
174 var panel = $(this).prev().show('fast'); 172 var panel = $(this).prev().show('fast');
175 - $.ajax({  
176 - url:$(this).attr("url"),  
177 - type:$(this).attr("method"),  
178 - dataType:'json'  
179 - }).done(function(data){ 173 + var isJson = $(this).attr('isjson');
  174 + var option = {
  175 + url:$(this).attr('url'),
  176 + type:$(this).attr('method'),
  177 + }
  178 + var data = {};
  179 + if(isJson) {
  180 + option.url = '/proxy?url=' + $(this).attr('url');
  181 + }
  182 +
  183 + $(this).parent().find('input').each(function(){
  184 + data[$(this).attr('name')] = $(this).val();
  185 + });
  186 +
  187 + option.data = data;
  188 +
  189 + $.ajax(option).done(function(data){
180 var json = formatJson(data); 190 var json = formatJson(data);
181 panel.html(json); 191 panel.html(json);
182 }); 192 });
183 }); 193 });
184 -}) 194 +});
185 </script> 195 </script>
186 </body> 196 </body>
187 </html> 197 </html>