swagger支持json文档录入
This commit is contained in:
@@ -41,6 +41,11 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-jta-atomikos</artifactId>
|
<artifactId>spring-boot-starter-jta-atomikos</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sourceforge.jtds</groupId>
|
||||||
|
<artifactId>jtds</artifactId>
|
||||||
|
<version>1.3.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mybatis</groupId>
|
<groupId>org.mybatis</groupId>
|
||||||
<artifactId>mybatis</artifactId>
|
<artifactId>mybatis</artifactId>
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import java.util.Optional;
|
|||||||
* @author 暮光:城中城
|
* @author 暮光:城中城
|
||||||
* @since 2019年7月27日
|
* @since 2019年7月27日
|
||||||
*/
|
*/
|
||||||
@AuthMan("ES_DATASOURCE_MANAGE")
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/zyplayer-doc-es/datasource")
|
@RequestMapping("/zyplayer-doc-es/datasource")
|
||||||
public class EsDatasourceController {
|
public class EsDatasourceController {
|
||||||
@@ -39,7 +38,8 @@ public class EsDatasourceController {
|
|||||||
List<EsDatasource> datasourceList = esDatasourceService.list(wrapper);
|
List<EsDatasource> datasourceList = esDatasourceService.list(wrapper);
|
||||||
return DocResponseJson.ok(datasourceList);
|
return DocResponseJson.ok(datasourceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AuthMan("ES_DATASOURCE_MANAGE")
|
||||||
@PostMapping(value = "/update")
|
@PostMapping(value = "/update")
|
||||||
public ResponseJson update(EsDatasource esDatasource) {
|
public ResponseJson update(EsDatasource esDatasource) {
|
||||||
if (StringUtils.isBlank(esDatasource.getName())) {
|
if (StringUtils.isBlank(esDatasource.getName())) {
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class MgStorageServiceImpl implements MgStorageService {
|
|||||||
ZyplayerStorage entity = new ZyplayerStorage();
|
ZyplayerStorage entity = new ZyplayerStorage();
|
||||||
entity.setDocValue(value);
|
entity.setDocValue(value);
|
||||||
UpdateWrapper<ZyplayerStorage> updateWrapper = new UpdateWrapper<>();
|
UpdateWrapper<ZyplayerStorage> updateWrapper = new UpdateWrapper<>();
|
||||||
updateWrapper.eq(true, "doc_key", key);
|
updateWrapper.eq("doc_key", key);
|
||||||
boolean update = zyplayerStorageService.update(entity, updateWrapper);
|
boolean update = zyplayerStorageService.update(entity, updateWrapper);
|
||||||
if (!update) {
|
if (!update) {
|
||||||
entity = new ZyplayerStorage();
|
entity = new ZyplayerStorage();
|
||||||
|
|||||||
@@ -45,6 +45,11 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
|
|||||||
@@ -11,15 +11,13 @@ import com.zyplayer.doc.swagger.controller.vo.SwaggerLocationVo;
|
|||||||
import com.zyplayer.doc.swagger.controller.vo.SwaggerResourcesInfoVo;
|
import com.zyplayer.doc.swagger.controller.vo.SwaggerResourcesInfoVo;
|
||||||
import com.zyplayer.doc.swagger.framework.configuration.EnableDocSwagger;
|
import com.zyplayer.doc.swagger.framework.configuration.EnableDocSwagger;
|
||||||
import com.zyplayer.doc.swagger.framework.configuration.SpringContextUtil;
|
import com.zyplayer.doc.swagger.framework.configuration.SpringContextUtil;
|
||||||
|
import com.zyplayer.doc.swagger.framework.constant.Consts;
|
||||||
import com.zyplayer.doc.swagger.framework.constant.StorageKeys;
|
import com.zyplayer.doc.swagger.framework.constant.StorageKeys;
|
||||||
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import springfox.documentation.swagger.web.SwaggerResource;
|
import springfox.documentation.swagger.web.SwaggerResource;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -300,7 +298,12 @@ public class MgDocumentController {
|
|||||||
* @return 添加结果
|
* @return 添加结果
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/addSwaggerResources")
|
@PostMapping(value = "/addSwaggerResources")
|
||||||
public ResponseJson<Object> addSwaggerResources(String resourcesUrl, String rewriteDomainUrl, String oldUrl, Integer openVisit) {
|
public ResponseJson<Object> addSwaggerResources(HttpServletRequest request, String swaggerJson, String resourcesUrl, String rewriteDomainUrl, String oldUrl, Integer openVisit) {
|
||||||
|
// 通过json文档内容来添加
|
||||||
|
ResponseJson<Object> responseJson = this.addSwaggerJsonApiDocs(request, swaggerJson, resourcesUrl);
|
||||||
|
if (responseJson != null) {
|
||||||
|
return responseJson;
|
||||||
|
}
|
||||||
// 总有些人喜欢填这个地址,那就替换来支持下吧
|
// 总有些人喜欢填这个地址,那就替换来支持下吧
|
||||||
int htmlIndex = resourcesUrl.indexOf("/swagger-ui.html");
|
int htmlIndex = resourcesUrl.indexOf("/swagger-ui.html");
|
||||||
if (htmlIndex > 0) {
|
if (htmlIndex > 0) {
|
||||||
@@ -352,6 +355,38 @@ public class MgDocumentController {
|
|||||||
return DocResponseJson.ok();
|
return DocResponseJson.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 增加json格式文档
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019年8月11日
|
||||||
|
* @param swaggerJson swagger的文档内容
|
||||||
|
* @return 添加结果
|
||||||
|
*/
|
||||||
|
public ResponseJson<Object> addSwaggerJsonApiDocs(HttpServletRequest request, String swaggerJson, String resourcesUrl) {
|
||||||
|
if (StringUtils.isNotBlank(swaggerJson)) {
|
||||||
|
Integer nextId = 0;
|
||||||
|
String customUrl = resourcesUrl;
|
||||||
|
if (resourcesUrl.contains(Consts.PROXY_API_DOCS)) {
|
||||||
|
nextId = Integer.valueOf(resourcesUrl.substring(resourcesUrl.indexOf("?id=") + 4));
|
||||||
|
} else {
|
||||||
|
nextId = storageService.getNextId();
|
||||||
|
customUrl = request.getRequestURL().toString();
|
||||||
|
customUrl = customUrl.substring(0, customUrl.lastIndexOf("/"));
|
||||||
|
customUrl = customUrl + Consts.PROXY_API_DOCS + "?id=" + nextId;
|
||||||
|
}
|
||||||
|
boolean addResult = this.addSwaggerLocationList(swaggerJson, null, customUrl, customUrl, 0);
|
||||||
|
if (addResult) {
|
||||||
|
storageService.put(StorageKeys.PROXY_API_DOCS + nextId, swaggerJson);
|
||||||
|
return DocResponseJson.ok();
|
||||||
|
}
|
||||||
|
return DocResponseJson.warn("添加失败");
|
||||||
|
} else if (resourcesUrl.contains(Consts.PROXY_API_DOCS)) {
|
||||||
|
return DocResponseJson.warn("添加失败,该地址是代理地址,必须填写文档内容");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增加/swagger-resources地址
|
* 增加/swagger-resources地址
|
||||||
*
|
*
|
||||||
@@ -403,6 +438,11 @@ public class MgDocumentController {
|
|||||||
String locationDel = this.encodeUrlParam(location);
|
String locationDel = this.encodeUrlParam(location);
|
||||||
locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), locationDel)).collect(Collectors.toList());
|
locationList = locationList.stream().filter(val -> !Objects.equals(val.getLocation(), locationDel)).collect(Collectors.toList());
|
||||||
this.storageSwaggerLocationList(locationList);
|
this.storageSwaggerLocationList(locationList);
|
||||||
|
// 代理地址判断
|
||||||
|
if (location.contains(Consts.PROXY_API_DOCS)) {
|
||||||
|
Integer nextId = Integer.valueOf(location.substring(location.indexOf("?id=") + 4));
|
||||||
|
storageService.remove(StorageKeys.PROXY_API_DOCS + nextId);
|
||||||
|
}
|
||||||
return DocResponseJson.ok();
|
return DocResponseJson.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,7 @@ import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@@ -100,6 +97,23 @@ public class MgOpenDocController {
|
|||||||
DocResponseJson.ok(swaggerResourceStrList).send(response);
|
DocResponseJson.ok(swaggerResourceStrList).send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取增加的json格式文档
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019年8月11日
|
||||||
|
* @param id swagger的文档内容的id
|
||||||
|
* @return 添加结果
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/proxyApiDocs")
|
||||||
|
public String getApiDocs(Long id) {
|
||||||
|
String result = storageService.get(StorageKeys.PROXY_API_DOCS + id);
|
||||||
|
if (StringUtils.isBlank(result)) {
|
||||||
|
return DocResponseJson.warn("未找到该文档").toJson();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局参数
|
* 全局参数
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.zyplayer.doc.swagger.controller;
|
||||||
|
|
||||||
|
import com.zyplayer.doc.core.json.DocResponseJson;
|
||||||
|
import com.zyplayer.doc.swagger.framework.constant.Consts;
|
||||||
|
import com.zyplayer.doc.swagger.framework.constant.StorageKeys;
|
||||||
|
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接口文档代理返回控制器
|
||||||
|
*
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019年8月11日
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/swagger-mg-ui/document")
|
||||||
|
public class MgProxyApiDocController {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(MgProxyApiDocController.class);
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MgStorageService storageService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取增加的json格式文档
|
||||||
|
*
|
||||||
|
* @param id swagger的文档内容的id
|
||||||
|
* @return 结果
|
||||||
|
* @author 暮光:城中城
|
||||||
|
* @since 2019年8月11日
|
||||||
|
*/
|
||||||
|
@GetMapping(value = Consts.PROXY_API_DOCS)
|
||||||
|
public String getApiDocs(Long id) {
|
||||||
|
String result = storageService.get(StorageKeys.PROXY_API_DOCS + id);
|
||||||
|
if (StringUtils.isBlank(result)) {
|
||||||
|
return DocResponseJson.warn("未找到该文档").toJson();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,4 +5,5 @@ public class Consts {
|
|||||||
public static final String ZYPLAYER_PROXY = "/zyplayer-proxy/";
|
public static final String ZYPLAYER_PROXY = "/zyplayer-proxy/";
|
||||||
public static final String V2_API_DOCS = "/v2/api-docs";
|
public static final String V2_API_DOCS = "/v2/api-docs";
|
||||||
public static final String SWAGGER_RESOURCES = "/swagger-resources";
|
public static final String SWAGGER_RESOURCES = "/swagger-resources";
|
||||||
|
public static final String PROXY_API_DOCS = "/proxy-api-docs";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,4 +19,6 @@ public class StorageKeys {
|
|||||||
public static final String SWAGGER_ID_WORKER = "swagger-id-worker";
|
public static final String SWAGGER_ID_WORKER = "swagger-id-worker";
|
||||||
// 全局参数
|
// 全局参数
|
||||||
public static final String GLOBAL_PARAM_LIST = "zyplayer-doc-global-param-list";
|
public static final String GLOBAL_PARAM_LIST = "zyplayer-doc-global-param-list";
|
||||||
|
// 代理的文档内容
|
||||||
|
public static final String PROXY_API_DOCS = "proxy-api-docs-";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="input-line">
|
<div class="input-line">
|
||||||
地址:
|
文档地址:
|
||||||
<input v-model="addNewDocumentInput" type="text" class="form-control" 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">
|
||||||
|
</div>
|
||||||
|
<div class="input-line">
|
||||||
|
swagger文档内容:
|
||||||
|
<textarea v-model="addNewSwaggerJson" type="text" class="form-control" placeholder="swagger的json文档内容,选填,如果填了则不再请求上面的地址获取内容,而是直接返回这里输入的"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-line">
|
<div class="input-line">
|
||||||
重写域名地址:
|
重写域名地址:
|
||||||
@@ -94,6 +98,7 @@
|
|||||||
data: {
|
data: {
|
||||||
swaggerLocationList: [],
|
swaggerLocationList: [],
|
||||||
addNewDocumentInput: '',
|
addNewDocumentInput: '',
|
||||||
|
addNewSwaggerJson: '',
|
||||||
rewriteDomainUrl: '',
|
rewriteDomainUrl: '',
|
||||||
openVisit: '',
|
openVisit: '',
|
||||||
oldLocation: ''
|
oldLocation: ''
|
||||||
@@ -131,12 +136,13 @@
|
|||||||
},
|
},
|
||||||
addNewDocumentBtn: function(){
|
addNewDocumentBtn: function(){
|
||||||
var addNewDocumentInput = app.addNewDocumentInput;
|
var addNewDocumentInput = app.addNewDocumentInput;
|
||||||
if(isEmpty(addNewDocumentInput)) {
|
if(isEmpty(addNewDocumentInput) && isEmpty(app.addNewSwaggerJson)) {
|
||||||
Toast.error("地址不可以为空");return;
|
Toast.error("地址不可以为空");return;
|
||||||
}
|
}
|
||||||
var param = {
|
var param = {
|
||||||
openVisit: app.openVisit ? 1 : 0,
|
openVisit: app.openVisit ? 1 : 0,
|
||||||
resourcesUrl: addNewDocumentInput,
|
resourcesUrl: addNewDocumentInput,
|
||||||
|
swaggerJson: app.addNewSwaggerJson,
|
||||||
rewriteDomainUrl: app.rewriteDomainUrl,
|
rewriteDomainUrl: app.rewriteDomainUrl,
|
||||||
oldUrl: app.oldLocation
|
oldUrl: app.oldLocation
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user