Merge branch 'master' into registry-nacos

pull/1/head
tanghc 5 years ago
commit 306523511c
  1. 24
      sop-website/website-front/pages/doc/doc.html
  2. 2
      sop-website/website-front/pages/doc/docEvent.js
  3. 12
      sop-website/website-front/pages/sandbox/sandbox.html
  4. 17
      sop-website/website-front/pages/sandbox/sandbox.js
  5. 24
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocItem.java
  6. 16
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocParserContext.java
  7. 29
      sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java

@ -102,12 +102,17 @@
<blockquote class="layui-elem-quote layui-text sop-description">
</blockquote>
<div class="site-title">
<fieldset class="layui-elem-field layui-field-title site-title">
<legend>请求地址</legend>
</fieldset>
</div>
<div class="site-text">
<h3>请求地址</h3>
<table class="layui-table">
<thead>
<tr>
<th>环境</th>
<th style="width: 120px;">环境</th>
<th>请求地址</th>
</tr>
</thead>
@ -120,6 +125,16 @@
</table>
</div>
<div class="site-title">
<fieldset class="layui-elem-field layui-field-title site-title">
<legend>请求方法</legend>
</fieldset>
</div>
<div class="site-text">
<span id="httpMethodList"></span>
</div>
<div class="site-title">
<fieldset class="layui-elem-field layui-field-title site-title">
<legend>公共参数</legend>
@ -127,7 +142,6 @@
</div>
<div class="site-text">
<h3>公共请求参数</h3>
<table class="layui-table">
<thead>
<tr>
@ -244,7 +258,7 @@
<div class="site-title">
<fieldset class="layui-elem-field layui-field-title site-title">
<legend>请求参数</legend>
<legend>业务参数</legend>
</fieldset>
</div>
<div class="site-text">
@ -308,7 +322,7 @@
<div class="site-title">
<fieldset class="layui-elem-field layui-field-title site-title">
<legend>响应参数</legend>
<legend>业务响应参数</legend>
</fieldset>
</div>
<div class="site-text">

@ -19,6 +19,8 @@ function selectItem(docItem, layui) {
var $li = $('#docItemTree').find('li[nameversion="'+nameVersion+'"]');
$li.addClass('layui-this').siblings().removeClass('layui-this');
$('#httpMethodList').text(docItem.httpMethodList.join(' / ').toUpperCase());
}
function createRequestParameter(docItem) {

@ -83,8 +83,12 @@
<blockquote class="layui-elem-quote layui-text sop-description">
</blockquote>
<div class="site-title">
<fieldset class="layui-elem-field layui-field-title site-title">
<legend>参数配置</legend>
</fieldset>
</div>
<div class="site-text">
<h3>参数配置</h3>
<table class="layui-table">
<tr>
<td class="table-title">AppId</td>
@ -107,6 +111,12 @@
<div id="multipleDiv" style="margin-bottom: 20px;margin-top: 20px;display: none;">
<input id="multipleFile" name="file" type="file" multiple="multiple" value="上传文件" />
</div>
<div class="layui-form-item">
<label style="float: left;padding-top: 9px;">请求方法</label>
<div style="margin-left: 70px;width: 120px;">
<select id="httpMethodList"></select>
</div>
</div>
<button lay-submit lay-filter="formSend" class="layui-btn layui-btn-normal">发送请求</button>
</form>

@ -17,6 +17,7 @@ var treetable;
var currentItem;
function selectItem(docItem, layui) {
var form = layui.form;
currentItem = docItem;
resetResultDiv();
var nameVersion = docItem.nameVersion;
@ -31,11 +32,25 @@ function selectItem(docItem, layui) {
$('#multipleDiv').css('display', multiple ? 'block' : 'none');
$('#httpMethodList').html(buildHttpMethodOptions(docItem));
var $li = $('#docItemTree').find('li[nameversion="'+nameVersion+'"]');
$li.addClass('layui-this').siblings().removeClass('layui-this');
form.render();
InputCache.init();
}
function buildHttpMethodOptions(docItem) {
var methodList = docItem.httpMethodList;
var html = []
for (var i = 0; i < methodList.length; i++) {
var method = methodList[i];
html.push('<option value="' + method + '"> ' + method.toUpperCase() + ' </option>');
}
return html.join('');
}
function createRequestParameter(docItem) {
var data = buildTreeData(docItem.requestParameters);
createTreeTable('treeTableReq', data);
@ -105,7 +120,7 @@ function doTest() {
, privateKey: $('#privateKey').val()
, method: method
, version: version
, httpMethod: currentItem.httpMethod
, httpMethod: $('#httpMethodList').val()
};
var uploadFileObjects = getUploadFileObjects();
var $inputs = $body.find('.test-input');

@ -2,6 +2,7 @@ package com.gitee.sop.websiteserver.bean;
import lombok.Data;
import java.util.Collection;
import java.util.List;
/**
@ -14,9 +15,10 @@ public class DocItem {
private String version;
private String summary;
private String description;
// 是否多文件上传
/** 是否多文件上传 */
private boolean multiple;
private String httpMethod;
/** http method列表 */
private Collection<String> httpMethodList;
List<DocParameter> requestParameters;
List<DocParameter> responseParameters;
@ -24,4 +26,22 @@ public class DocItem {
public String getNameVersion() {
return name + version;
}
/**
* 是否是上传文件请求
* @return
*/
public boolean isUploadRequest() {
boolean upload = false;
if (requestParameters != null) {
for (DocParameter requestParameter : requestParameters) {
String type = requestParameter.getType();
if ("file".equalsIgnoreCase(type)) {
upload = true;
break;
}
}
}
return multiple || upload;
}
}

@ -0,0 +1,16 @@
package com.gitee.sop.websiteserver.bean;
import com.google.common.collect.Sets;
import java.util.Set;
/**
* @author tanghc
*/
public class DocParserContext {
/**
* 忽略显示
*/
public static volatile Set<String> ignoreHttpMethods = Sets.newHashSet("put", "options", "head", "put", "delete", "patch");
}

@ -6,10 +6,13 @@ import com.gitee.sop.websiteserver.bean.DocInfo;
import com.gitee.sop.websiteserver.bean.DocItem;
import com.gitee.sop.websiteserver.bean.DocModule;
import com.gitee.sop.websiteserver.bean.DocParameter;
import com.gitee.sop.websiteserver.bean.DocParserContext;
import com.google.common.collect.Sets;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -33,13 +36,17 @@ public class SwaggerDocParser implements DocParser {
for (String apiPath : pathNameSet) {
JSONObject pathInfo = paths.getJSONObject(apiPath);
// key: get,post,head...
Set<String> pathSet = pathInfo.keySet();
Optional<String> first = pathSet.stream().findFirst();
Collection<String> httpMethodList = getHttpMethods(pathInfo);
Optional<String> first = httpMethodList.stream().findFirst();
if (first.isPresent()) {
String method = first.get();
JSONObject docInfo = pathInfo.getJSONObject(method);
DocItem docItem = buildDocItem(docInfo, docRoot);
docItem.setHttpMethod(method);
if (docItem.isUploadRequest()) {
docItem.setHttpMethodList(Sets.newHashSet("post"));
} else {
docItem.setHttpMethodList(httpMethodList);
}
docItems.add(docItem);
}
}
@ -63,6 +70,22 @@ public class SwaggerDocParser implements DocParser {
return docInfo;
}
protected Collection<String> getHttpMethods(JSONObject pathInfo) {
// key: get,post,head...
List<String> retList;
Set<String> httpMethodList = pathInfo.keySet();
if (httpMethodList.size() <= 2) {
retList = new ArrayList<>(httpMethodList);
} else {
Set<String> ignoreHttpMethods = DocParserContext.ignoreHttpMethods;
retList = httpMethodList.stream()
.filter(method -> !ignoreHttpMethods.contains(method.toLowerCase()))
.collect(Collectors.toList());
}
Collections.sort(retList);
return retList;
}
protected DocItem buildDocItem(JSONObject docInfo, JSONObject docRoot) {
DocItem docItem = new DocItem();
docItem.setName(docInfo.getString("sop_name"));

Loading…
Cancel
Save