From cbaee753cbca0f24aa578d68a72a5eabe0725956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9A=AE=E5=85=89=EF=BC=9A=E5=9F=8E=E4=B8=AD=E5=9F=8E?= <806783409@qq.com> Date: Sun, 25 Aug 2019 22:43:14 +0800 Subject: [PATCH] =?UTF-8?q?swagger=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=90=8D=E5=AD=97=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MgDocumentController.java | 19 ++++++++++++------- .../swagger/controller/vo/LocationListVo.java | 9 +++++++++ .../main/resources/webjars/mg-ui/js/mg-ui.js | 3 ++- .../webjars/zpages/docUrlConfig.html | 11 ++++++++--- .../webjars/zpages/docUrlDetailConfig.html | 16 +++++++++++++--- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java index 5ba91207..b4b88f9c 100644 --- a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java +++ b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/MgDocumentController.java @@ -151,13 +151,14 @@ public class MgDocumentController { if (indexV2 >= 0) { resourcesUrl = location.getLocation().substring(0, indexV2); } - // 本来想转对象之后赋值,但是在此转成JSON字符串之后格式就不是之前的了,所有不能转。。。 + // 本来想转对象之后赋值,但是在此转成JSON字符串之后格式就不是之前的了,所以不能转。。。 // 直接字符串拼接,坑真多~ String rewriteDomainUrl = Optional.ofNullable(location.getRewriteDomainUrl()).orElse(""); resourceStr = resourceStr.substring(1); resourceStr = "{\"fullUrl\":\"" + location.getLocation() + "\"," + "\"domainUrl\":\"" + resourcesUrl + "\"," + "\"rewriteDomainUrl\":\"" + rewriteDomainUrl + "\"," + + "\"customName\":\"" + location.getCustomName() + "\"," + resourceStr; swaggerResourceStrList.add(resourceStr); } catch (Exception e) { @@ -298,9 +299,10 @@ public class MgDocumentController { * @return 添加结果 */ @PostMapping(value = "/addSwaggerResources") - public ResponseJson addSwaggerResources(HttpServletRequest request, String swaggerJson, String resourcesUrl, String rewriteDomainUrl, String oldUrl, Integer openVisit) { + public ResponseJson addSwaggerResources(HttpServletRequest request, String swaggerJson, String resourcesUrl, + String rewriteDomainUrl, String oldUrl, Integer openVisit, String customName) { // 通过json文档内容来添加 - ResponseJson responseJson = this.addSwaggerJsonApiDocs(request, swaggerJson, resourcesUrl, rewriteDomainUrl, openVisit); + ResponseJson responseJson = this.addSwaggerJsonApiDocs(request, swaggerJson, resourcesUrl, rewriteDomainUrl, openVisit, customName); if (responseJson != null) { return responseJson; } @@ -329,7 +331,7 @@ public class MgDocumentController { .addHeaders(this.getGlobalParamMap(globalParamList, "header")) .header("Accept", "application/json, text/javascript, */*; q=0.01") .timeout(docTimeout).execute().body(); - boolean isLocation = this.addSwaggerLocationList(resourcesStr, rewriteDomainUrl, resourcesUrl, oldUrl, openVisit); + boolean isLocation = this.addSwaggerLocationList(resourcesStr, rewriteDomainUrl, resourcesUrl, oldUrl, openVisit, customName); if (!isLocation) { List resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class); if (resourceList == null || resourceList.isEmpty()) { @@ -363,7 +365,8 @@ public class MgDocumentController { * @param swaggerJson swagger的文档内容 * @return 添加结果 */ - public ResponseJson addSwaggerJsonApiDocs(HttpServletRequest request, String swaggerJson, String resourcesUrl, String rewriteDomainUrl, Integer openVisit) { + public ResponseJson addSwaggerJsonApiDocs(HttpServletRequest request, String swaggerJson, String resourcesUrl, + String rewriteDomainUrl, Integer openVisit, String customName) { if (StringUtils.isNotBlank(swaggerJson)) { Integer nextId = 0; String customUrl = resourcesUrl; @@ -375,7 +378,7 @@ public class MgDocumentController { customUrl = customUrl.substring(0, customUrl.lastIndexOf("/")); customUrl = customUrl + Consts.PROXY_API_DOCS + "?id=" + nextId; } - boolean addResult = this.addSwaggerLocationList(swaggerJson, rewriteDomainUrl, customUrl, customUrl, openVisit); + boolean addResult = this.addSwaggerLocationList(swaggerJson, rewriteDomainUrl, customUrl, customUrl, openVisit, customName); if (addResult) { storageService.put(StorageKeys.PROXY_API_DOCS + nextId, swaggerJson); return DocResponseJson.ok(); @@ -462,7 +465,8 @@ public class MgDocumentController { /** * 直接添加地址 */ - private boolean addSwaggerLocationList(String resourcesStr, String rewriteDomainUrl, String locationUrl, String oldUrl, Integer openVisit) { + private boolean addSwaggerLocationList(String resourcesStr, String rewriteDomainUrl, String locationUrl, + String oldUrl, Integer openVisit, String customName) { try { SwaggerLocationVo swaggerLocationVo = null; try { @@ -489,6 +493,7 @@ public class MgDocumentController { locationListVo.setLocation(locationUrl); locationListVo.setRewriteDomainUrl(rewriteDomainUrl); locationListVo.setOpenVisit(openVisit); + locationListVo.setCustomName(customName); // 去除旧的,加入新的 locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), oldUrl)).collect(Collectors.toList()); locationList.add(locationListVo); diff --git a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/vo/LocationListVo.java b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/vo/LocationListVo.java index 719a3f6e..8e4ca466 100644 --- a/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/vo/LocationListVo.java +++ b/zyplayer-doc-swagger/src/main/java/com/zyplayer/doc/swagger/controller/vo/LocationListVo.java @@ -12,6 +12,7 @@ public class LocationListVo { private String location; private String resources; private Integer openVisit; + private String customName; private String rewriteDomainUrl; public LocationListVo(){ @@ -102,4 +103,12 @@ public class LocationListVo { public void setOpenVisit(Integer openVisit) { this.openVisit = openVisit; } + + public String getCustomName() { + return customName; + } + + public void setCustomName(String customName) { + this.customName = customName; + } } diff --git a/zyplayer-doc-swagger/src/main/resources/webjars/mg-ui/js/mg-ui.js b/zyplayer-doc-swagger/src/main/resources/webjars/mg-ui/js/mg-ui.js index e553fb00..889eb244 100644 --- a/zyplayer-doc-swagger/src/main/resources/webjars/mg-ui/js/mg-ui.js +++ b/zyplayer-doc-swagger/src/main/resources/webjars/mg-ui/js/mg-ui.js @@ -97,7 +97,8 @@ function getDocumentListByService() { if (validateResult(json) && json.data.length >= 1) { for (var i = 0; i < json.data.length; i++) { var item = json.data[i]; - $("#choiceLocationList .dropdown-menu").append('
  • ' + item.name + '
  • '); + var itemName = (!!item.customName) ? item.customName : item.name; + $("#choiceLocationList .dropdown-menu").append('
  • ' + itemName + '
  • '); } $("#choiceLocationList .dropdown-menu").append('
  • 全部文档
  • '); $("#choiceLocationList .choice-text").text(json.data[0].name); diff --git a/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlConfig.html b/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlConfig.html index 0dd2fd0c..8daf3fd8 100644 --- a/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlConfig.html +++ b/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlConfig.html @@ -9,6 +9,11 @@
    +
    +
    +
    Tips:保存的swagger-resources实际会自动获取所有文档到“详细地址管理”里,所以这里的地址无实际用处,实际起作用的是“详细地址管理”里的哦,所以这里面只保留查询列表了,不再提供增删改,想要添加修改就去“详细地址管理”里操作吧!
    +
    +
    @@ -26,8 +31,8 @@ @@ -35,7 +40,7 @@ diff --git a/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlDetailConfig.html b/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlDetailConfig.html index cf4e2ca0..c65bfa6b 100644 --- a/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlDetailConfig.html +++ b/zyplayer-doc-swagger/src/main/resources/webjars/zpages/docUrlDetailConfig.html @@ -16,6 +16,7 @@ + @@ -25,6 +26,7 @@ + - @@ -57,6 +59,10 @@
    {{item.rewriteDomainUrl}} {{item.lastSync}} - - + +
    - +
    序号名称 地址 开放文档地址 重写域名地址
    {{index+1}}{{item.customName}} {{item.location}} @@ -39,7 +41,7 @@
    +