修改swagger解析报错,白名单域名默认为不限制

This commit is contained in:
暮光:城中城
2019-06-24 22:43:21 +08:00
parent f83c27882f
commit 29586f35d7
3 changed files with 130 additions and 130 deletions

View File

@@ -41,7 +41,7 @@ zyplayer:
swagger: swagger:
proxy-request: proxy-request:
# 允许代理请求的域名,正则表达式,多个使用 ; 分割,必须设置,防止通过代理接口访问到内部资源,实在觉得没必要可设置为:.+ # 允许代理请求的域名,正则表达式,多个使用 ; 分割,必须设置,防止通过代理接口访问到内部资源,实在觉得没必要可设置为:.+
white-domain: \S+\.zyplayer\.com;127.0.1:8080;\S+\.xiaominfo\.com; white-domain: .+
# ------dubbo相关配置------ # ------dubbo相关配置------
dubbo: dubbo:
# 优先使用zookeeper未配置时找nacos的配置 # 优先使用zookeeper未配置时找nacos的配置

View File

@@ -1,128 +1,128 @@
/** /**
* 以每个Tag方式生成并展示 * 以每个Tag方式生成并展示
* 核心信息控制器 * 核心信息控制器
* /api/data/getDataList * /api/data/getDataList
* /api/data/getDataDetail * /api/data/getDataDetail
* 跟进控制器 * 跟进控制器
* /api/track/getTrackList * /api/track/getTrackList
* /api/track/getTrackDetail * /api/track/getTrackDetail
* *
* 先把树形的写完了再写这个,, * 先把树形的写完了再写这个,,
* *
* @author 暮光:城中城 * @author 暮光:城中城
* @since 2018年5月26日 * @since 2018年5月26日
*/ */
function createTreeViewByTag(json, keywords) { function createTreeViewByTag(json, keywords) {
var pathIndex = {}; var pathIndex = {};
var paths = json.paths; var paths = json.paths;
var domain = json.domainUrl;// 服务器代理会返回此属性 var domain = json.domainUrl;// 服务器代理会返回此属性
if(isEmpty(domain)) { if(isEmpty(domain)) {
domain = "http://" + json.host + json.basePath; domain = "http://" + json.host + json.basePath;
} }
if(domain.endWith("/")) { if(domain.endWith("/")) {
domain = domain.substring(0, domain.length - 1); domain = domain.substring(0, domain.length - 1);
} }
if (isEmptyObject(paths)) { if (isEmptyObject(paths)) {
return; return;
} }
//console.log(paths); //console.log(paths);
Object.keys(paths).forEach(function(key){ Object.keys(paths).forEach(function(key){
//console.log(key, paths[key]); //console.log(key, paths[key]);
if(!findInPathsValue(key, paths[key], keywords)) { if(!findInPathsValue(key, paths[key], keywords)) {
return; return;
} }
setRequestMethodForTag(domain, paths[key], pathIndex, key, "get"); setRequestMethodForTag(domain, paths[key], pathIndex, key, "get");
setRequestMethodForTag(domain, paths[key], pathIndex, key, "head"); setRequestMethodForTag(domain, paths[key], pathIndex, key, "head");
setRequestMethodForTag(domain, paths[key], pathIndex, key, "post"); setRequestMethodForTag(domain, paths[key], pathIndex, key, "post");
setRequestMethodForTag(domain, paths[key], pathIndex, key, "put"); setRequestMethodForTag(domain, paths[key], pathIndex, key, "put");
setRequestMethodForTag(domain, paths[key], pathIndex, key, "patch"); setRequestMethodForTag(domain, paths[key], pathIndex, key, "patch");
setRequestMethodForTag(domain, paths[key], pathIndex, key, "delete"); setRequestMethodForTag(domain, paths[key], pathIndex, key, "delete");
setRequestMethodForTag(domain, paths[key], pathIndex, key, "options"); setRequestMethodForTag(domain, paths[key], pathIndex, key, "options");
setRequestMethodForTag(domain, paths[key], pathIndex, key, "trace"); setRequestMethodForTag(domain, paths[key], pathIndex, key, "trace");
}); });
//console.log(pathIndex); //console.log(pathIndex);
var htmlStr = '<li>'; var htmlStr = '<li>';
htmlStr += '<a href="#">'+json.info.title+'</a>'; htmlStr += '<a href="#">'+json.info.title+'</a>';
htmlStr += '<ul>'; htmlStr += '<ul>';
htmlStr += getTreeHtmlForTag(pathIndex, projectTreeIdIndex); htmlStr += getTreeHtmlForTag(pathIndex, projectTreeIdIndex);
htmlStr += '</ul>'; htmlStr += '</ul>';
htmlStr += '</li>'; htmlStr += '</li>';
$('#apiPathTree .projects').append(htmlStr); $('#apiPathTree .projects').append(htmlStr);
projectTreeIdIndex++; projectTreeIdIndex++;
} }
/** /**
* 设置对象的各种请求方式,存在则复制 * 设置对象的各种请求方式,存在则复制
* @param source 资源原始json的paths的指定对象 * @param source 资源原始json的paths的指定对象
* @param pathObj 当前的待赋值对象 * @param pathObj 当前的待赋值对象
* @param url url绝对路径 * @param url url绝对路径
* @param method 请求方式post、get... * @param method 请求方式post、get...
* @returns * @returns
*/ */
function setRequestMethodForTag(domain, source, pathObj, url, method) { function setRequestMethodForTag(domain, source, pathObj, url, method) {
if (isEmpty(source[method])) { if (isEmpty(source[method]) || !source[method].tags) {
return; return;
} }
source[method].tags.forEach(function(val, index) { source[method].tags.forEach(function(val, index) {
var tempObj = pathObj[val]; var tempObj = pathObj[val];
if(isEmpty(tempObj)) { if(isEmpty(tempObj)) {
tempObj = pathObj[val] = {}; tempObj = pathObj[val] = {};
} }
var tempUrlObj = tempObj[url]; var tempUrlObj = tempObj[url];
if(isEmpty(tempUrlObj)) { if(isEmpty(tempUrlObj)) {
tempUrlObj = tempObj[url] = {}; tempUrlObj = tempObj[url] = {};
} }
var tempPath = projectTreeIdIndex + url + "." + method; var tempPath = projectTreeIdIndex + url + "." + method;
tempUrlObj[method] = source[method]; tempUrlObj[method] = source[method];
tempUrlObj[method].path = tempPath; tempUrlObj[method].path = tempPath;
tempUrlObj[method].url = url; tempUrlObj[method].url = url;
tempUrlObj[method].method = method; tempUrlObj[method].method = method;
tempUrlObj[method].domain = domain; tempUrlObj[method].domain = domain;
treePathDataMap.set(tempPath, source[method]); treePathDataMap.set(tempPath, source[method]);
}); });
} }
/** /**
* 将对象列表递归的方式转换成文档格式html字符串 * 将对象列表递归的方式转换成文档格式html字符串
* @param pathData 处理后的对象列表 * @param pathData 处理后的对象列表
* @returns 生成的html字符串 * @returns 生成的html字符串
*/ */
function getTreeHtmlForTag(pathData, treeIdStr) { function getTreeHtmlForTag(pathData, treeIdStr) {
var tempStr = ""; var tempStr = "";
var indexNow = 1; var indexNow = 1;
// get, head, post, put, patch, delete, options, trace // get, head, post, put, patch, delete, options, trace
var actionArrays = ["get", "head", "post", "put", "patch", "delete", "options", "trace"]; var actionArrays = ["get", "head", "post", "put", "patch", "delete", "options", "trace"];
Object.keys(pathData).forEach(function(key){ Object.keys(pathData).forEach(function(key){
var tempNode = pathData[key]; var tempNode = pathData[key];
var tempTreeId = treeIdStr + "_" + indexNow; var tempTreeId = treeIdStr + "_" + indexNow;
// 只有一个子元素而且有method元素说明是只有一个节点 // 只有一个子元素而且有method元素说明是只有一个节点
var nodeSub = getObjectFirstAttributeIfOnly(tempNode); var nodeSub = getObjectFirstAttributeIfOnly(tempNode);
if(nodeSub != null && isNotEmpty(nodeSub.method)) { if(nodeSub != null && isNotEmpty(nodeSub.method)) {
var summary = isEmpty(nodeSub.summary) ? "" : "(" + nodeSub.summary + ")"; var summary = isEmpty(nodeSub.summary) ? "" : "(" + nodeSub.summary + ")";
if(summary.length > 10){ if(summary.length > 10){
summary = summary.substring(0, 10)+"...)";// 防止被撑得太长只显示10个字 summary = summary.substring(0, 10)+"...)";// 防止被撑得太长只显示10个字
} }
nodeSub.treeId = tempTreeId; nodeSub.treeId = tempTreeId;
tempStr += '<li m-id="'+tempTreeId+'"><a href="#" class="show-doc" path="'+nodeSub.path+'">'+key+'<span>'+summary+'</span></a></li>'; tempStr += '<li m-id="'+tempTreeId+'"><a href="#" class="show-doc" path="'+nodeSub.path+'">'+key+'<span>'+summary+'</span></a></li>';
} else if(haveString(actionArrays, key)) { } else if(haveString(actionArrays, key)) {
//console.log(tempTreeId); //console.log(tempTreeId);
tempNode.treeId = tempTreeId; tempNode.treeId = tempTreeId;
var summary = isEmpty(tempNode.summary) ? "" : "("+tempNode.summary+")"; var summary = isEmpty(tempNode.summary) ? "" : "("+tempNode.summary+")";
if(summary.length > 10){ if(summary.length > 10){
summary = summary.substring(0, 10)+"...)";// 防止被撑得太长只显示10个字 summary = summary.substring(0, 10)+"...)";// 防止被撑得太长只显示10个字
} }
tempStr += '<li m-id="'+tempTreeId+'"><a href="#" class="show-doc" path="'+tempNode.path+'">'+key+'<span>'+summary+'</span></a></li>'; tempStr += '<li m-id="'+tempTreeId+'"><a href="#" class="show-doc" path="'+tempNode.path+'">'+key+'<span>'+summary+'</span></a></li>';
} else { } else {
tempStr += '<li>'; tempStr += '<li>';
tempStr += '<a href="#">'+key+'</a>'; tempStr += '<a href="#">'+key+'</a>';
tempStr += '<ul>'; tempStr += '<ul>';
tempStr += getTreeHtmlForTag(tempNode, tempTreeId); tempStr += getTreeHtmlForTag(tempNode, tempTreeId);
tempStr += '</ul>'; tempStr += '</ul>';
tempStr += '</li>'; tempStr += '</li>';
} }
indexNow++; indexNow++;
}); });
return tempStr; return tempStr;
} }

View File

@@ -62,7 +62,7 @@ function createTreeViewByTag(json, keywords) {
* @returns * @returns
*/ */
function setRequestMethodForTag(rewriteDomainUrl, domain, source, pathObj, url, method) { function setRequestMethodForTag(rewriteDomainUrl, domain, source, pathObj, url, method) {
if (isEmpty(source[method])) { if (isEmpty(source[method]) || !source[method].tags) {
return; return;
} }
source[method].tags.forEach(function(val, index) { source[method].tags.forEach(function(val, index) {