swagger增加自定义名字展示
This commit is contained in:
@@ -151,13 +151,14 @@ public class MgDocumentController {
|
|||||||
if (indexV2 >= 0) {
|
if (indexV2 >= 0) {
|
||||||
resourcesUrl = location.getLocation().substring(0, indexV2);
|
resourcesUrl = location.getLocation().substring(0, indexV2);
|
||||||
}
|
}
|
||||||
// 本来想转对象之后赋值,但是在此转成JSON字符串之后格式就不是之前的了,所有不能转。。。
|
// 本来想转对象之后赋值,但是在此转成JSON字符串之后格式就不是之前的了,所以不能转。。。
|
||||||
// 直接字符串拼接,坑真多~
|
// 直接字符串拼接,坑真多~
|
||||||
String rewriteDomainUrl = Optional.ofNullable(location.getRewriteDomainUrl()).orElse("");
|
String rewriteDomainUrl = Optional.ofNullable(location.getRewriteDomainUrl()).orElse("");
|
||||||
resourceStr = resourceStr.substring(1);
|
resourceStr = resourceStr.substring(1);
|
||||||
resourceStr = "{\"fullUrl\":\"" + location.getLocation() + "\","
|
resourceStr = "{\"fullUrl\":\"" + location.getLocation() + "\","
|
||||||
+ "\"domainUrl\":\"" + resourcesUrl + "\","
|
+ "\"domainUrl\":\"" + resourcesUrl + "\","
|
||||||
+ "\"rewriteDomainUrl\":\"" + rewriteDomainUrl + "\","
|
+ "\"rewriteDomainUrl\":\"" + rewriteDomainUrl + "\","
|
||||||
|
+ "\"customName\":\"" + location.getCustomName() + "\","
|
||||||
+ resourceStr;
|
+ resourceStr;
|
||||||
swaggerResourceStrList.add(resourceStr);
|
swaggerResourceStrList.add(resourceStr);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -298,9 +299,10 @@ public class MgDocumentController {
|
|||||||
* @return 添加结果
|
* @return 添加结果
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/addSwaggerResources")
|
@PostMapping(value = "/addSwaggerResources")
|
||||||
public ResponseJson<Object> addSwaggerResources(HttpServletRequest request, String swaggerJson, String resourcesUrl, String rewriteDomainUrl, String oldUrl, Integer openVisit) {
|
public ResponseJson<Object> addSwaggerResources(HttpServletRequest request, String swaggerJson, String resourcesUrl,
|
||||||
|
String rewriteDomainUrl, String oldUrl, Integer openVisit, String customName) {
|
||||||
// 通过json文档内容来添加
|
// 通过json文档内容来添加
|
||||||
ResponseJson<Object> responseJson = this.addSwaggerJsonApiDocs(request, swaggerJson, resourcesUrl, rewriteDomainUrl, openVisit);
|
ResponseJson<Object> responseJson = this.addSwaggerJsonApiDocs(request, swaggerJson, resourcesUrl, rewriteDomainUrl, openVisit, customName);
|
||||||
if (responseJson != null) {
|
if (responseJson != null) {
|
||||||
return responseJson;
|
return responseJson;
|
||||||
}
|
}
|
||||||
@@ -329,7 +331,7 @@ public class MgDocumentController {
|
|||||||
.addHeaders(this.getGlobalParamMap(globalParamList, "header"))
|
.addHeaders(this.getGlobalParamMap(globalParamList, "header"))
|
||||||
.header("Accept", "application/json, text/javascript, */*; q=0.01")
|
.header("Accept", "application/json, text/javascript, */*; q=0.01")
|
||||||
.timeout(docTimeout).execute().body();
|
.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) {
|
if (!isLocation) {
|
||||||
List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
|
List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
|
||||||
if (resourceList == null || resourceList.isEmpty()) {
|
if (resourceList == null || resourceList.isEmpty()) {
|
||||||
@@ -363,7 +365,8 @@ public class MgDocumentController {
|
|||||||
* @param swaggerJson swagger的文档内容
|
* @param swaggerJson swagger的文档内容
|
||||||
* @return 添加结果
|
* @return 添加结果
|
||||||
*/
|
*/
|
||||||
public ResponseJson<Object> addSwaggerJsonApiDocs(HttpServletRequest request, String swaggerJson, String resourcesUrl, String rewriteDomainUrl, Integer openVisit) {
|
public ResponseJson<Object> addSwaggerJsonApiDocs(HttpServletRequest request, String swaggerJson, String resourcesUrl,
|
||||||
|
String rewriteDomainUrl, Integer openVisit, String customName) {
|
||||||
if (StringUtils.isNotBlank(swaggerJson)) {
|
if (StringUtils.isNotBlank(swaggerJson)) {
|
||||||
Integer nextId = 0;
|
Integer nextId = 0;
|
||||||
String customUrl = resourcesUrl;
|
String customUrl = resourcesUrl;
|
||||||
@@ -375,7 +378,7 @@ public class MgDocumentController {
|
|||||||
customUrl = customUrl.substring(0, customUrl.lastIndexOf("/"));
|
customUrl = customUrl.substring(0, customUrl.lastIndexOf("/"));
|
||||||
customUrl = customUrl + Consts.PROXY_API_DOCS + "?id=" + nextId;
|
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) {
|
if (addResult) {
|
||||||
storageService.put(StorageKeys.PROXY_API_DOCS + nextId, swaggerJson);
|
storageService.put(StorageKeys.PROXY_API_DOCS + nextId, swaggerJson);
|
||||||
return DocResponseJson.ok();
|
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 {
|
try {
|
||||||
SwaggerLocationVo swaggerLocationVo = null;
|
SwaggerLocationVo swaggerLocationVo = null;
|
||||||
try {
|
try {
|
||||||
@@ -489,6 +493,7 @@ public class MgDocumentController {
|
|||||||
locationListVo.setLocation(locationUrl);
|
locationListVo.setLocation(locationUrl);
|
||||||
locationListVo.setRewriteDomainUrl(rewriteDomainUrl);
|
locationListVo.setRewriteDomainUrl(rewriteDomainUrl);
|
||||||
locationListVo.setOpenVisit(openVisit);
|
locationListVo.setOpenVisit(openVisit);
|
||||||
|
locationListVo.setCustomName(customName);
|
||||||
// 去除旧的,加入新的
|
// 去除旧的,加入新的
|
||||||
locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), oldUrl)).collect(Collectors.toList());
|
locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), oldUrl)).collect(Collectors.toList());
|
||||||
locationList.add(locationListVo);
|
locationList.add(locationListVo);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class LocationListVo {
|
|||||||
private String location;
|
private String location;
|
||||||
private String resources;
|
private String resources;
|
||||||
private Integer openVisit;
|
private Integer openVisit;
|
||||||
|
private String customName;
|
||||||
private String rewriteDomainUrl;
|
private String rewriteDomainUrl;
|
||||||
|
|
||||||
public LocationListVo(){
|
public LocationListVo(){
|
||||||
@@ -102,4 +103,12 @@ public class LocationListVo {
|
|||||||
public void setOpenVisit(Integer openVisit) {
|
public void setOpenVisit(Integer openVisit) {
|
||||||
this.openVisit = openVisit;
|
this.openVisit = openVisit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCustomName() {
|
||||||
|
return customName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCustomName(String customName) {
|
||||||
|
this.customName = customName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,8 @@ function getDocumentListByService() {
|
|||||||
if (validateResult(json) && json.data.length >= 1) {
|
if (validateResult(json) && json.data.length >= 1) {
|
||||||
for (var i = 0; i < json.data.length; i++) {
|
for (var i = 0; i < json.data.length; i++) {
|
||||||
var item = json.data[i];
|
var item = json.data[i];
|
||||||
$("#choiceLocationList .dropdown-menu").append('<li><a href="javascript:void(0);" data-location="' + item.location + '">' + item.name + '</a></li>');
|
var itemName = (!!item.customName) ? item.customName : item.name;
|
||||||
|
$("#choiceLocationList .dropdown-menu").append('<li><a href="javascript:void(0);" data-location="' + item.location + '">' + itemName + '</a></li>');
|
||||||
}
|
}
|
||||||
$("#choiceLocationList .dropdown-menu").append('<li><a href="javascript:void(0);" data-location="">全部文档</a></li>');
|
$("#choiceLocationList .dropdown-menu").append('<li><a href="javascript:void(0);" data-location="">全部文档</a></li>');
|
||||||
$("#choiceLocationList .choice-text").text(json.data[0].name);
|
$("#choiceLocationList .choice-text").text(json.data[0].name);
|
||||||
|
|||||||
@@ -9,6 +9,11 @@
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
|
<div class="title-info">
|
||||||
|
<div class="alert alert-primary">
|
||||||
|
<div class="content">Tips:保存的swagger-resources实际会自动获取所有文档到“详细地址管理”里,所以这里的地址无实际用处,实际起作用的是“详细地址管理”里的哦,所以这里面只保留查询列表了,不再提供增删改,想要添加修改就去“详细地址管理”里操作吧!</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<table class="table table-bordered setting-table">
|
<table class="table table-bordered setting-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -26,8 +31,8 @@
|
|||||||
<td>{{item.rewriteDomainUrl}}</td>
|
<td>{{item.rewriteDomainUrl}}</td>
|
||||||
<td>{{item.lastSync}}</td>
|
<td>{{item.lastSync}}</td>
|
||||||
<td>
|
<td>
|
||||||
<button class="btn btn-danger" type="button" v-on:click="deleteDocUrl($event)">删除</button>
|
<!-- <button class="btn btn-danger" type="button" v-on:click="deleteDocUrl($event)">删除</button>-->
|
||||||
<button class="btn btn-info" type="button" v-on:click="editDocUrl($event)">编辑</button>
|
<!-- <button class="btn btn-info" type="button" v-on:click="editDocUrl($event)">编辑</button>-->
|
||||||
<!--<button class="btn btn-danger" type="button" v-on:click="syncDocData($event)">持久化</button>-->
|
<!--<button class="btn btn-danger" type="button" v-on:click="syncDocData($event)">持久化</button>-->
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -35,7 +40,7 @@
|
|||||||
<td colspan="5" align="center">
|
<td colspan="5" align="center">
|
||||||
<button class="btn" type="button" v-on:click="btnRefreshList"> 刷新 </button>
|
<button class="btn" type="button" v-on:click="btnRefreshList"> 刷新 </button>
|
||||||
<button class="btn btn-info" type="button" v-on:click="exportDocument">导出文档</button>
|
<button class="btn btn-info" type="button" v-on:click="exportDocument">导出文档</button>
|
||||||
<button class="btn btn-primary" type="button" v-on:click="addNewDocument">增加文档</button>
|
<!-- <button class="btn btn-primary" type="button" v-on:click="addNewDocument">增加文档</button>-->
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="width: 50px;">序号</td>
|
<td style="width: 50px;">序号</td>
|
||||||
|
<td>名称</td>
|
||||||
<td>地址</td>
|
<td>地址</td>
|
||||||
<td>开放文档地址</td>
|
<td>开放文档地址</td>
|
||||||
<td>重写域名地址</td>
|
<td>重写域名地址</td>
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="(item,index) in swaggerLocationList" :key="item.id" :data-id="item.id" :data-index="index" >
|
<tr v-for="(item,index) in swaggerLocationList" :key="item.id" :data-id="item.id" :data-index="index" >
|
||||||
<td>{{index+1}}</td>
|
<td>{{index+1}}</td>
|
||||||
|
<td>{{item.customName}}</td>
|
||||||
<td>{{item.location}}</td>
|
<td>{{item.location}}</td>
|
||||||
<td>
|
<td>
|
||||||
<!--未开放时即使访问这个地址也看不了-->
|
<!--未开放时即使访问这个地址也看不了-->
|
||||||
@@ -39,7 +41,7 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="5" align="center">
|
<td colspan="6" align="center">
|
||||||
<button class="btn" type="button" v-on:click="btnRefreshList"> 刷新 </button>
|
<button class="btn" type="button" v-on:click="btnRefreshList"> 刷新 </button>
|
||||||
<button class="btn btn-primary" type="button" v-on:click="addNewDocument">增加文档</button>
|
<button class="btn btn-primary" type="button" v-on:click="addNewDocument">增加文档</button>
|
||||||
</td>
|
</td>
|
||||||
@@ -57,6 +59,10 @@
|
|||||||
<h4 class="modal-title">输入文档地址</h4>
|
<h4 class="modal-title">输入文档地址</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
<div class="input-line">
|
||||||
|
文档名字:
|
||||||
|
<input v-model="addNewCustomName" type="text" class="form-control" placeholder="可以自定义一个名字,将会在左上角下拉框里展示哦~">
|
||||||
|
</div>
|
||||||
<div class="input-line">
|
<div class="input-line">
|
||||||
文档地址:
|
文档地址:
|
||||||
<input v-model="addNewDocumentInput" type="text" class="form-control" :readonly="addNewDocumentInput.indexOf('proxy-api-docs') > 0" placeholder="例:http://127.0.0.1/swagger-resources 或 http://127.0.0.1/v2/api-docs">
|
<input v-model="addNewDocumentInput" type="text" class="form-control" :readonly="addNewDocumentInput.indexOf('proxy-api-docs') > 0" placeholder="例:http://127.0.0.1/swagger-resources 或 http://127.0.0.1/v2/api-docs">
|
||||||
@@ -101,7 +107,8 @@
|
|||||||
addNewSwaggerJson: '',
|
addNewSwaggerJson: '',
|
||||||
rewriteDomainUrl: '',
|
rewriteDomainUrl: '',
|
||||||
openVisit: '',
|
openVisit: '',
|
||||||
oldLocation: ''
|
oldLocation: '',
|
||||||
|
addNewCustomName: '',
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
},
|
},
|
||||||
@@ -128,6 +135,7 @@
|
|||||||
app.addNewDocumentInput = item.location;
|
app.addNewDocumentInput = item.location;
|
||||||
app.rewriteDomainUrl = item.rewriteDomainUrl;
|
app.rewriteDomainUrl = item.rewriteDomainUrl;
|
||||||
app.addNewSwaggerJson = "";
|
app.addNewSwaggerJson = "";
|
||||||
|
app.addNewCustomName = item.customName;
|
||||||
app.openVisit = (item.openVisit == 1);
|
app.openVisit = (item.openVisit == 1);
|
||||||
if (item.location.indexOf('proxy-api-docs') > 0) {
|
if (item.location.indexOf('proxy-api-docs') > 0) {
|
||||||
var docId = item.location.substring(item.location.indexOf("?id=") + 4);
|
var docId = item.location.substring(item.location.indexOf("?id=") + 4);
|
||||||
@@ -145,6 +153,7 @@
|
|||||||
app.oldLocation = '';
|
app.oldLocation = '';
|
||||||
app.addNewDocumentInput = '';
|
app.addNewDocumentInput = '';
|
||||||
app.addNewSwaggerJson = "";
|
app.addNewSwaggerJson = "";
|
||||||
|
app.addNewCustomName = "";
|
||||||
$('#addNewDocumentModal').modal({moveable:true});
|
$('#addNewDocumentModal').modal({moveable:true});
|
||||||
},
|
},
|
||||||
addNewDocumentBtn: function(){
|
addNewDocumentBtn: function(){
|
||||||
@@ -157,7 +166,8 @@
|
|||||||
resourcesUrl: addNewDocumentInput,
|
resourcesUrl: addNewDocumentInput,
|
||||||
swaggerJson: app.addNewSwaggerJson,
|
swaggerJson: app.addNewSwaggerJson,
|
||||||
rewriteDomainUrl: app.rewriteDomainUrl,
|
rewriteDomainUrl: app.rewriteDomainUrl,
|
||||||
oldUrl: app.oldLocation
|
oldUrl: app.oldLocation,
|
||||||
|
customName: app.addNewCustomName,
|
||||||
};
|
};
|
||||||
ajaxTemp(urlBase + "swagger-mg-ui/document/addSwaggerResources", "post", "json", param, function(json){
|
ajaxTemp(urlBase + "swagger-mg-ui/document/addSwaggerResources", "post", "json", param, function(json){
|
||||||
if(validateResult(json)) {
|
if(validateResult(json)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user