diff --git a/sop-website/website-front/pages/doc/docEvent.js b/sop-website/website-front/pages/doc/docEvent.js
index d8173867..e3aee12f 100644
--- a/sop-website/website-front/pages/doc/docEvent.js
+++ b/sop-website/website-front/pages/doc/docEvent.js
@@ -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) {
diff --git a/sop-website/website-front/pages/sandbox/sandbox.html b/sop-website/website-front/pages/sandbox/sandbox.html
index 1dd4b6cd..db969c7d 100644
--- a/sop-website/website-front/pages/sandbox/sandbox.html
+++ b/sop-website/website-front/pages/sandbox/sandbox.html
@@ -83,8 +83,12 @@
+
+
+
-
参数配置
AppId |
@@ -107,6 +111,12 @@
+
diff --git a/sop-website/website-front/pages/sandbox/sandbox.js b/sop-website/website-front/pages/sandbox/sandbox.js
index f8bf2673..27b63f90 100644
--- a/sop-website/website-front/pages/sandbox/sandbox.js
+++ b/sop-website/website-front/pages/sandbox/sandbox.js
@@ -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('');
+ }
+ 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');
diff --git a/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocItem.java b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocItem.java
index fa26ee3c..00762c52 100644
--- a/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocItem.java
+++ b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocItem.java
@@ -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 httpMethodList;
List requestParameters;
List 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;
+ }
}
diff --git a/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocParserContext.java b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocParserContext.java
new file mode 100644
index 00000000..8d79195b
--- /dev/null
+++ b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/DocParserContext.java
@@ -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 ignoreHttpMethods = Sets.newHashSet("put", "options", "head", "put", "delete", "patch");
+}
diff --git a/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java
index fc2876f9..7435df42 100644
--- a/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java
+++ b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/manager/SwaggerDocParser.java
@@ -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 pathSet = pathInfo.keySet();
- Optional first = pathSet.stream().findFirst();
+ Collection httpMethodList = getHttpMethods(pathInfo);
+ Optional 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 getHttpMethods(JSONObject pathInfo) {
+ // key: get,post,head...
+ List retList;
+ Set httpMethodList = pathInfo.keySet();
+ if (httpMethodList.size() <= 2) {
+ retList = new ArrayList<>(httpMethodList);
+ } else {
+ Set 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"));