mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 07:02:14 +08:00
Merge branch 'master' into registry-nacos
This commit is contained in:
@@ -102,12 +102,17 @@
|
|||||||
<blockquote class="layui-elem-quote layui-text sop-description">
|
<blockquote class="layui-elem-quote layui-text sop-description">
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="site-title">
|
||||||
|
<fieldset class="layui-elem-field layui-field-title site-title">
|
||||||
|
<legend>请求地址</legend>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
<div class="site-text">
|
<div class="site-text">
|
||||||
<h3>请求地址</h3>
|
|
||||||
<table class="layui-table">
|
<table class="layui-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>环境</th>
|
<th style="width: 120px;">环境</th>
|
||||||
<th>请求地址</th>
|
<th>请求地址</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -120,6 +125,16 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</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">
|
<div class="site-title">
|
||||||
<fieldset class="layui-elem-field layui-field-title site-title">
|
<fieldset class="layui-elem-field layui-field-title site-title">
|
||||||
<legend>公共参数</legend>
|
<legend>公共参数</legend>
|
||||||
@@ -127,7 +142,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="site-text">
|
<div class="site-text">
|
||||||
<h3>公共请求参数</h3>
|
|
||||||
<table class="layui-table">
|
<table class="layui-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -244,7 +258,7 @@
|
|||||||
|
|
||||||
<div class="site-title">
|
<div class="site-title">
|
||||||
<fieldset class="layui-elem-field layui-field-title site-title">
|
<fieldset class="layui-elem-field layui-field-title site-title">
|
||||||
<legend>请求参数</legend>
|
<legend>业务参数</legend>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div class="site-text">
|
<div class="site-text">
|
||||||
@@ -308,7 +322,7 @@
|
|||||||
|
|
||||||
<div class="site-title">
|
<div class="site-title">
|
||||||
<fieldset class="layui-elem-field layui-field-title site-title">
|
<fieldset class="layui-elem-field layui-field-title site-title">
|
||||||
<legend>响应参数</legend>
|
<legend>业务响应参数</legend>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
<div class="site-text">
|
<div class="site-text">
|
||||||
|
@@ -19,6 +19,8 @@ function selectItem(docItem, layui) {
|
|||||||
|
|
||||||
var $li = $('#docItemTree').find('li[nameversion="'+nameVersion+'"]');
|
var $li = $('#docItemTree').find('li[nameversion="'+nameVersion+'"]');
|
||||||
$li.addClass('layui-this').siblings().removeClass('layui-this');
|
$li.addClass('layui-this').siblings().removeClass('layui-this');
|
||||||
|
|
||||||
|
$('#httpMethodList').text(docItem.httpMethodList.join(' / ').toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
function createRequestParameter(docItem) {
|
function createRequestParameter(docItem) {
|
||||||
|
@@ -83,8 +83,12 @@
|
|||||||
<blockquote class="layui-elem-quote layui-text sop-description">
|
<blockquote class="layui-elem-quote layui-text sop-description">
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
<div class="site-title">
|
||||||
|
<fieldset class="layui-elem-field layui-field-title site-title">
|
||||||
|
<legend>参数配置</legend>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
<div class="site-text">
|
<div class="site-text">
|
||||||
<h3>参数配置</h3>
|
|
||||||
<table class="layui-table">
|
<table class="layui-table">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="table-title">AppId</td>
|
<td class="table-title">AppId</td>
|
||||||
@@ -107,6 +111,12 @@
|
|||||||
<div id="multipleDiv" style="margin-bottom: 20px;margin-top: 20px;display: none;">
|
<div id="multipleDiv" style="margin-bottom: 20px;margin-top: 20px;display: none;">
|
||||||
<input id="multipleFile" name="file" type="file" multiple="multiple" value="上传文件" />
|
<input id="multipleFile" name="file" type="file" multiple="multiple" value="上传文件" />
|
||||||
</div>
|
</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>
|
<button lay-submit lay-filter="formSend" class="layui-btn layui-btn-normal">发送请求</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@ var treetable;
|
|||||||
var currentItem;
|
var currentItem;
|
||||||
|
|
||||||
function selectItem(docItem, layui) {
|
function selectItem(docItem, layui) {
|
||||||
|
var form = layui.form;
|
||||||
currentItem = docItem;
|
currentItem = docItem;
|
||||||
resetResultDiv();
|
resetResultDiv();
|
||||||
var nameVersion = docItem.nameVersion;
|
var nameVersion = docItem.nameVersion;
|
||||||
@@ -31,11 +32,25 @@ function selectItem(docItem, layui) {
|
|||||||
|
|
||||||
$('#multipleDiv').css('display', multiple ? 'block' : 'none');
|
$('#multipleDiv').css('display', multiple ? 'block' : 'none');
|
||||||
|
|
||||||
|
$('#httpMethodList').html(buildHttpMethodOptions(docItem));
|
||||||
|
|
||||||
var $li = $('#docItemTree').find('li[nameversion="'+nameVersion+'"]');
|
var $li = $('#docItemTree').find('li[nameversion="'+nameVersion+'"]');
|
||||||
$li.addClass('layui-this').siblings().removeClass('layui-this');
|
$li.addClass('layui-this').siblings().removeClass('layui-this');
|
||||||
|
|
||||||
|
form.render();
|
||||||
InputCache.init();
|
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) {
|
function createRequestParameter(docItem) {
|
||||||
var data = buildTreeData(docItem.requestParameters);
|
var data = buildTreeData(docItem.requestParameters);
|
||||||
createTreeTable('treeTableReq', data);
|
createTreeTable('treeTableReq', data);
|
||||||
@@ -105,7 +120,7 @@ function doTest() {
|
|||||||
, privateKey: $('#privateKey').val()
|
, privateKey: $('#privateKey').val()
|
||||||
, method: method
|
, method: method
|
||||||
, version: version
|
, version: version
|
||||||
, httpMethod: currentItem.httpMethod
|
, httpMethod: $('#httpMethodList').val()
|
||||||
};
|
};
|
||||||
var uploadFileObjects = getUploadFileObjects();
|
var uploadFileObjects = getUploadFileObjects();
|
||||||
var $inputs = $body.find('.test-input');
|
var $inputs = $body.find('.test-input');
|
||||||
|
@@ -2,6 +2,7 @@ package com.gitee.sop.websiteserver.bean;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,9 +15,10 @@ public class DocItem {
|
|||||||
private String version;
|
private String version;
|
||||||
private String summary;
|
private String summary;
|
||||||
private String description;
|
private String description;
|
||||||
// 是否多文件上传
|
/** 是否多文件上传 */
|
||||||
private boolean multiple;
|
private boolean multiple;
|
||||||
private String httpMethod;
|
/** http method列表 */
|
||||||
|
private Collection<String> httpMethodList;
|
||||||
|
|
||||||
List<DocParameter> requestParameters;
|
List<DocParameter> requestParameters;
|
||||||
List<DocParameter> responseParameters;
|
List<DocParameter> responseParameters;
|
||||||
@@ -24,4 +26,22 @@ public class DocItem {
|
|||||||
public String getNameVersion() {
|
public String getNameVersion() {
|
||||||
return name + version;
|
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.DocItem;
|
||||||
import com.gitee.sop.websiteserver.bean.DocModule;
|
import com.gitee.sop.websiteserver.bean.DocModule;
|
||||||
import com.gitee.sop.websiteserver.bean.DocParameter;
|
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.apache.commons.lang.StringUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -33,13 +36,17 @@ public class SwaggerDocParser implements DocParser {
|
|||||||
for (String apiPath : pathNameSet) {
|
for (String apiPath : pathNameSet) {
|
||||||
JSONObject pathInfo = paths.getJSONObject(apiPath);
|
JSONObject pathInfo = paths.getJSONObject(apiPath);
|
||||||
// key: get,post,head...
|
// key: get,post,head...
|
||||||
Set<String> pathSet = pathInfo.keySet();
|
Collection<String> httpMethodList = getHttpMethods(pathInfo);
|
||||||
Optional<String> first = pathSet.stream().findFirst();
|
Optional<String> first = httpMethodList.stream().findFirst();
|
||||||
if (first.isPresent()) {
|
if (first.isPresent()) {
|
||||||
String method = first.get();
|
String method = first.get();
|
||||||
JSONObject docInfo = pathInfo.getJSONObject(method);
|
JSONObject docInfo = pathInfo.getJSONObject(method);
|
||||||
DocItem docItem = buildDocItem(docInfo, docRoot);
|
DocItem docItem = buildDocItem(docInfo, docRoot);
|
||||||
docItem.setHttpMethod(method);
|
if (docItem.isUploadRequest()) {
|
||||||
|
docItem.setHttpMethodList(Sets.newHashSet("post"));
|
||||||
|
} else {
|
||||||
|
docItem.setHttpMethodList(httpMethodList);
|
||||||
|
}
|
||||||
docItems.add(docItem);
|
docItems.add(docItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,6 +70,22 @@ public class SwaggerDocParser implements DocParser {
|
|||||||
return docInfo;
|
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) {
|
protected DocItem buildDocItem(JSONObject docInfo, JSONObject docRoot) {
|
||||||
DocItem docItem = new DocItem();
|
DocItem docItem = new DocItem();
|
||||||
docItem.setName(docInfo.getString("sop_name"));
|
docItem.setName(docInfo.getString("sop_name"));
|
||||||
|
Reference in New Issue
Block a user