代码整理

This commit is contained in:
暮光:城中城
2018-12-08 14:59:26 +08:00
parent 67c584761d
commit 6465d3c412
80 changed files with 2043 additions and 882 deletions

View File

@@ -1,30 +0,0 @@
package com.mg.swagger.controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mg.swagger.controller.param.HttpRequestParam;
import com.mg.swagger.framework.json.MgUiResponseJson;
import com.mg.swagger.framework.json.ResponseJson;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
/**
* 后台代理网络请求的控制器
*
* @author 暮光:城中城
* @since 2018年8月21日
*/
@RestController
@RequestMapping("/swagger-mg-ui/http")
public class MgHttpRequestController {
@PostMapping(value = "/request")
public ResponseJson post(HttpRequestParam param) {
HttpRequest request = param.createRequest();
HttpResponse execute = request.execute();
return MgUiResponseJson.ok(execute);
}
}

View File

@@ -1,72 +0,0 @@
package com.mg.swagger.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mg.swagger.framework.constant.Toast;
import com.mg.swagger.framework.json.MgUiResponseJson;
import com.mg.swagger.framework.service.MgStorageService;
/**
* 后台存储服务控制器
*
* @author 暮光:城中城
* @since 2018年8月21日
*/
@RestController
@RequestMapping("/swagger-mg-ui/storage")
public class MgStorageController {
@Autowired(required = false)
private MgStorageService storageService;
@PostMapping(value = "/checkConfig")
public MgUiResponseJson checkConfig() {
// 本接口能访问到而且实现了MgStorageService才算配置好了
if (storageService == null) {
return MgUiResponseJson.error("服务不可用");
}
return MgUiResponseJson.ok();
}
@PostMapping(value = "/data")
public MgUiResponseJson setData(String key, String value) {
if (storageService == null) {
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
}
if (key == null || value == null) {
return MgUiResponseJson.warn("参数名或值不能为空");
}
storageService.put(key, value);
return MgUiResponseJson.ok();
}
@PostMapping(value = "/delete")
public MgUiResponseJson delete(String key) {
if (storageService == null) {
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
}
if (key == null) {
return MgUiResponseJson.warn("参数名不能为空");
}
String value = storageService.get(key);
value = (value == null) ? "" : value;
return MgUiResponseJson.ok(value);
}
@GetMapping(value = "/data")
public MgUiResponseJson getData(String key) {
if (storageService == null) {
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
}
if (key == null) {
return MgUiResponseJson.warn("参数名不能为空");
}
String value = storageService.get(key);
value = (value == null) ? "" : value;
return MgUiResponseJson.ok(value);
}
}

View File

@@ -1,29 +0,0 @@
package com.mg.swagger.framework.configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import com.mg.swagger.framework.filter.MgUiTestFilter;
//@EnableAutoConfiguration
@ComponentScan(basePackages = {
"com.mg.swagger.controller",
"com.mg.swagger.framework.service",
})
public class SwaggerCommonConfiguration {
@Autowired
private MgUiTestFilter mgUiTestFilter;
@Bean
public FilterRegistrationBean mockTestFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(mgUiTestFilter);
registration.addUrlPatterns("/*");
registration.setName("mgUiTestFilter");
registration.setOrder(2);
return registration;
}
}

View File

@@ -1,219 +0,0 @@
package com.mg.swagger.framework.json;
import java.io.IOException;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import com.mg.swagger.controller.vo.HttpCookieVo;
import com.mg.swagger.controller.vo.HttpHeaderVo;
import cn.hutool.http.HttpResponse;
import io.swagger.annotations.ApiModelProperty;
/**
* MgUi返回数据格式
*
* @author 暮光:城中城
* @since 2018年8月21日
*/
public class MgUiResponseJson implements ResponseJson {
private static SerializeConfig mapping = new SerializeConfig();
static {
mapping.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
}
@ApiModelProperty(value = "状态码")
private Integer errCode;
@ApiModelProperty(value = "返回值说明")
private String errMsg;
@ApiModelProperty(value = "返回数据")
private Object data;
@ApiModelProperty(value = "代理请求返回的cookie")
private List<HttpCookieVo> cookie;
@ApiModelProperty(value = "代理请求返回的header")
private List<HttpHeaderVo> header;
@ApiModelProperty(value = "代理请求返回的status")
private Integer status;
public MgUiResponseJson() {
this.errCode = 200;
}
public MgUiResponseJson(Object data) {
this.setData(data);
this.errCode = 200;
}
public MgUiResponseJson(int errCode, String errMsg) {
super();
this.errCode = errCode;
this.errMsg = errMsg;
}
public MgUiResponseJson(int errCode, String errMsg, Object data) {
super();
this.setData(data);
this.errCode = errCode;
this.errMsg = errMsg;
}
public MgUiResponseJson(Integer errCode) {
super();
this.errCode = errCode;
}
public Integer getErrCode() {
return errCode;
}
public void setErrCode(Integer errCode) {
this.errCode = errCode;
}
public String getErrMsg() {
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
/**
* 提示语
*
* @author 暮光:城中城
* @since 2018年8月7日
* @return
*/
public static MgUiResponseJson warn(String errMsg) {
return new MgUiResponseJson(300, errMsg);
}
/**
* 错误
*
* @author 暮光:城中城
* @since 2018年8月7日
* @return
*/
public static MgUiResponseJson error(String errMsg) {
return new MgUiResponseJson(500, errMsg);
}
/**
* 成功的返回方法
*
* @author 暮光:城中城
* @since 2018年8月7日
* @return
*/
public static MgUiResponseJson ok() {
return new MgUiResponseJson();
}
/**
* 成功的返回方法
*
* @author 暮光:城中城
* @since 2018年8月7日
* @return
*/
public static MgUiResponseJson ok(Object data) {
if (data == null) {
return MgUiResponseJson.ok();
}
MgUiResponseJson responseJson = new MgUiResponseJson();
if (data instanceof HttpResponse) {
HttpResponse response = (HttpResponse) data;
responseJson.setData(response.body());
responseJson.setStatus(response.getStatus());
List<HttpCookie> cookies = response.getCookies();
if (cookies != null && cookies.size() > 0) {
List<HttpCookieVo> cookie = new ArrayList<>(cookies.size());
for (HttpCookie httpCookie : cookies) {
HttpCookieVo vo = new HttpCookieVo();
vo.setName(httpCookie.getName());
vo.setValue(httpCookie.getValue());
cookie.add(vo);
}
responseJson.setCookie(cookie);
}
Map<String, List<String>> headers = response.headers();
if (headers != null && headers.size() > 0) {
List<HttpHeaderVo> header = new ArrayList<>(headers.size());
for (Entry<String, List<String>> httpHeader : headers.entrySet()) {
HttpHeaderVo vo = new HttpHeaderVo();
vo.setName(httpHeader.getKey());
vo.setValue(String.join(";", httpHeader.getValue()));
header.add(vo);
}
responseJson.setHeader(header);
}
} else {
responseJson.setData(data);
}
return responseJson;
}
public String toJson() {
return JSON.toJSONString(this, mapping);
}
public void send(HttpServletResponse response) {
try {
response.setStatus(200);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache, must-revalidate");
response.getWriter().write(toJson());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public String toString() {
return "DefaultResponseJson [errCode=" + errCode + ", errMsg=" + errMsg + ", data=" + data + "]";
}
public List<HttpCookieVo> getCookie() {
return cookie;
}
public void setCookie(List<HttpCookieVo> cookie) {
this.cookie = cookie;
}
public List<HttpHeaderVo> getHeader() {
return header;
}
public void setHeader(List<HttpHeaderVo> header) {
this.header = header;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}

View File

@@ -1,11 +0,0 @@
package com.mg.swagger.framework.json;
/**
* json视图
*
* @author 暮光:城中城
* @since 2018年8月21日
*/
public interface ResponseJson {
}

View File

@@ -1,4 +1,4 @@
package com.mg.swagger.controller;
package com.zyplayer.doc.swagger.controller;
import java.net.URLEncoder;
import java.util.Arrays;
@@ -24,13 +24,12 @@ import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.mg.swagger.framework.configuration.EnableSwaggerMgUi;
import com.mg.swagger.framework.configuration.SpringContextUtil;
import com.mg.swagger.framework.constant.StorageKeys;
import com.mg.swagger.framework.constant.Toast;
import com.mg.swagger.framework.json.MgUiResponseJson;
import com.mg.swagger.framework.json.ResponseJson;
import com.mg.swagger.framework.service.MgStorageService;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.core.json.ResponseJson;
import com.zyplayer.doc.swagger.framework.configuration.EnableSwaggerMgUi;
import com.zyplayer.doc.swagger.framework.configuration.SpringContextUtil;
import com.zyplayer.doc.swagger.framework.constant.StorageKeys;
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
import cn.hutool.http.HttpRequest;
import springfox.documentation.swagger.web.SwaggerResource;
@@ -47,7 +46,7 @@ public class MgDocumentController {
private static Logger logger = LoggerFactory.getLogger(MgDocumentController.class);
@Autowired(required = false)
@Autowired
private MgStorageService storageService;
/**
@@ -55,35 +54,30 @@ public class MgDocumentController {
*
* @author 暮光城中城
* @since 2018年8月21日
* @return 文档内容
*/
@ResponseBody
@PostMapping(value = "/resourcesList")
public ResponseJson resourcesList() {
if (storageService == null) {
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
}
public ResponseJson<Set<String>> resourcesList() {
String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
Set<String> resourcesSet = new HashSet<>();
if (StringUtils.isNotBlank(swaggerResourcesStr)) {
List<String> resourcesList = JSON.parseArray(swaggerResourcesStr, String.class);
resourcesSet.addAll(resourcesList);
}
return MgUiResponseJson.ok(resourcesSet);
return DocResponseJson.ok(resourcesSet);
}
/**
* 获取所有的文档
*
* @author 暮光城中城
* @since 2018年8月21日
* @param request request
* @param response response
*/
@ResponseBody
@PostMapping(value = "/docs")
public void docs(HttpServletRequest request, HttpServletResponse response) {
if (storageService == null) {
MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR).send(response);
return;
}
boolean needRestorage = true;
String choiseDocList = request.getParameter("choiseDocList");
// 转成set防止重复
@@ -123,15 +117,13 @@ public class MgDocumentController {
if (swaggerMgUi == null) {
resourcesSet.add(serverPath + "/swagger-resources");
} else {
boolean selfDoc = swaggerMgUi.selfDoc();
if (selfDoc) {
if (swaggerMgUi.selfDoc()) {
resourcesSet.add(serverPath + "/swagger-resources");
} else {
// 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
String[] defaultResources = swaggerMgUi.defaultResources();
if (defaultResources != null && defaultResources.length > 0) {
resourcesSet.addAll(Arrays.asList(defaultResources));
}
}
// 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
String[] defaultResources = swaggerMgUi.defaultResources();
if (defaultResources != null && defaultResources.length > 0) {
resourcesSet.addAll(Arrays.asList(defaultResources));
}
}
}
@@ -195,7 +187,7 @@ public class MgDocumentController {
storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet));
}
// 用默认的json解析要内存溢出解析不了JSONObject就只有这样写了~
MgUiResponseJson.ok(swaggerResourceStrList).send(response);
DocResponseJson.ok(swaggerResourceStrList).send(response);
}
/**
@@ -203,14 +195,11 @@ public class MgDocumentController {
*
* @author 暮光城中城
* @since 2018年8月21日
* @param resourcesUrl
* @return
* @param resourcesUrl swagger-resources地址
* @return 添加结果
*/
@PostMapping(value = "/addSwaggerResources")
public ResponseJson addSwaggerResources(String resourcesUrl) {
if (storageService == null) {
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
}
public ResponseJson<Object> addSwaggerResources(String resourcesUrl) {
String swaggerResourcesStr = storageService.get(StorageKeys.SWAGGER_RESOURCES_LIST);
String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST);
Set<String> swaggerDocsDeleteSet = new HashSet<>();
@@ -224,11 +213,12 @@ public class MgDocumentController {
List<String> resourcesList = JSON.parseArray(swaggerResourcesStr, String.class);
resourcesSet.addAll(resourcesList);
}
String resourcesStr = null;
try {
String resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body();
resourcesStr = HttpRequest.get(resourcesUrl).timeout(3000).execute().body();
List<SwaggerResource> resourceList = JSON.parseArray(resourcesStr, SwaggerResource.class);
if (resourceList == null || resourceList.isEmpty()) {
return MgUiResponseJson.warn("地址未找到文档");
return DocResponseJson.warn("地址未找到文档");
}
// 重新加入的时候把之前的已删除的回恢复
String resourcesDomain = resourcesUrl.substring(0, resourcesUrl.lastIndexOf("/") + 1);
@@ -249,12 +239,28 @@ public class MgDocumentController {
}
resourcesSet.add(resourcesUrl);
} catch (Exception e) {
logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage());
return MgUiResponseJson.warn("改地址查找文档失败");
// 暂不想支持直接添加地址
// try {
// SwaggerLocationVo swaggerLocationVo = JSON.parseObject(resourcesStr, SwaggerLocationVo.class);
// if (StringUtils.isNotBlank(swaggerLocationVo.getSwagger())) {
// Set<String> locationSet = new HashSet<>();
// if (StringUtils.isNotBlank(swaggerLocationListStr)) {
// String swaggerLocationListStr = storageService.get(StorageKeys.SWAGGER_LOCATION_LIST);
// List<String> locationList = JSON.parseArray(swaggerLocationListStr, String.class);
// locationSet.addAll(locationList);
// storageService.put(StorageKeys.SWAGGER_LOCATION_LIST, JSON.toJSONString(locationSet));
// }
// } else {
// return DocResponseJson.warn("该地址查找文档失败");
// }
// } catch (Exception e2) {
logger.error("获取文档失败:{}{}", resourcesUrl, e.getMessage());
return DocResponseJson.warn("该地址查找文档失败");
// }
}
storageService.put(StorageKeys.SWAGGER_RESOURCES_LIST, JSON.toJSONString(resourcesSet));
storageService.put(StorageKeys.SWAGGER_DOCS_DELETE_LIST, JSON.toJSONString(swaggerDocsDeleteSet));
return MgUiResponseJson.ok();
return DocResponseJson.ok();
}
/**
@@ -262,14 +268,11 @@ public class MgDocumentController {
*
* @author 暮光城中城
* @since 2018年8月21日
* @param docUrl
* @return
* @param docUrl 文档地址
* @return 删除结果
*/
@PostMapping(value = "/deleteSwaggerDoc")
public ResponseJson deleteSwaggerDoc(String docUrl) {
if (storageService == null) {
return MgUiResponseJson.warn(Toast.AUTOWIRED_ERROR);
}
public ResponseJson<Object> deleteSwaggerDoc(String docUrl) {
String swaggerDocsDeleteStr = storageService.get(StorageKeys.SWAGGER_DOCS_DELETE_LIST);
Set<String> swaggerDocsDeleteSet = new HashSet<>();
if (StringUtils.isNotBlank(swaggerDocsDeleteStr)) {
@@ -278,6 +281,6 @@ public class MgDocumentController {
}
swaggerDocsDeleteSet.add(docUrl);
storageService.put(StorageKeys.SWAGGER_DOCS_DELETE_LIST, JSON.toJSONString(swaggerDocsDeleteSet));
return MgUiResponseJson.ok();
return DocResponseJson.ok();
}
}

View File

@@ -0,0 +1,60 @@
package com.zyplayer.doc.swagger.controller;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.swagger.controller.param.HttpRequestParam;
import com.zyplayer.doc.swagger.controller.vo.HttpCookieVo;
import com.zyplayer.doc.swagger.controller.vo.HttpHeaderVo;
import com.zyplayer.doc.swagger.controller.vo.HttpRequestVo;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
/**
* 后台代理网络请求的控制器
*
* @author 暮光:城中城
* @since 2018年8月21日
*/
@RestController
@RequestMapping("/swagger-mg-ui/http")
public class MgHttpRequestController {
@PostMapping(value = "/request")
public DocResponseJson<HttpRequestVo> post(HttpRequestParam param) {
HttpRequest request = param.createRequest();
HttpResponse response = request.execute();
HttpRequestVo httpRequestVo = new HttpRequestVo();
httpRequestVo.setData(response.body());
httpRequestVo.setStatus(response.getStatus());
List<HttpCookie> cookies = response.getCookies();
if (cookies != null && cookies.size() > 0) {
List<HttpCookieVo> cookie = cookies.stream().map(val -> {
return new HttpCookieVo(val.getName(), val.getValue());
}).collect(Collectors.toList());
httpRequestVo.setCookie(cookie);
}
Map<String, List<String>> headers = response.headers();
if (headers != null && headers.size() > 0) {
List<HttpHeaderVo> header = new ArrayList<>(headers.size());
for (Entry<String, List<String>> httpHeader : headers.entrySet()) {
HttpHeaderVo vo = new HttpHeaderVo();
vo.setName(httpHeader.getKey());
vo.setValue(String.join(";", httpHeader.getValue()));
header.add(vo);
}
httpRequestVo.setHeader(header);
}
return DocResponseJson.ok(httpRequestVo);
}
}

View File

@@ -0,0 +1,66 @@
package com.zyplayer.doc.swagger.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zyplayer.doc.core.json.DocResponseJson;
import com.zyplayer.doc.swagger.framework.service.MgStorage;
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
/**
* 后台存储服务控制器
*
* @author 暮光:城中城
* @since 2018年8月21日
*/
@RestController
@RequestMapping("/swagger-mg-ui/storage")
public class MgStorageController {
@Autowired
private MgStorageService storageService;
@PostMapping(value = "/checkConfig")
public DocResponseJson<Object> checkConfig() {
return DocResponseJson.ok();
}
@PostMapping(value = "/data")
public DocResponseJson<Object> setData(String key, String value) {
if (key == null || value == null) {
return DocResponseJson.warn("参数名或值不能为空");
}
storageService.put(key, value);
return DocResponseJson.ok();
}
@GetMapping(value = "/data")
public DocResponseJson<String> getData(String key) {
if (key == null) {
return DocResponseJson.warn("参数名不能为空");
}
String value = storageService.get(key);
value = (value == null) ? "" : value;
return DocResponseJson.ok(value);
}
@PostMapping(value = "/delete")
public DocResponseJson<Object> delete(String key) {
if (key == null) {
return DocResponseJson.warn("参数名不能为空");
}
storageService.remove(key);
return DocResponseJson.ok();
}
@PostMapping(value = "/like")
public DocResponseJson<Object> like(String key, String value) {
List<MgStorage> likeList = storageService.like(key, value);
return DocResponseJson.ok(likeList);
}
}

View File

@@ -1,4 +1,4 @@
package com.mg.swagger.controller.param;
package com.zyplayer.doc.swagger.controller.param;
import java.util.HashMap;
import java.util.Map;
@@ -92,6 +92,7 @@ public class HttpRequestParam {
/**
* 组装请求
* @return HttpRequest
*/
public HttpRequest createRequest() {
if("get".equalsIgnoreCase(this.method)) return get();
@@ -107,6 +108,7 @@ public class HttpRequestParam {
/**
* POST请求
* @return HttpRequest
*/
public HttpRequest post() {
HttpRequest request = HttpRequest.post(this.getUrl());
@@ -116,6 +118,7 @@ public class HttpRequestParam {
/**
* GET请求
* @return HttpRequest
*/
public HttpRequest get() {
HttpRequest request = HttpRequest.get(this.getUrl());
@@ -125,6 +128,7 @@ public class HttpRequestParam {
/**
* HEAD请求
* @return HttpRequest
*/
public HttpRequest head() {
HttpRequest request = HttpRequest.head(this.getUrl());
@@ -134,6 +138,7 @@ public class HttpRequestParam {
/**
* OPTIONS请求
* @return HttpRequest
*/
public HttpRequest options() {
HttpRequest request = HttpRequest.options(this.getUrl());
@@ -143,6 +148,7 @@ public class HttpRequestParam {
/**
* PUT请求
* @return HttpRequest
*/
public HttpRequest put() {
HttpRequest request = HttpRequest.put(this.getUrl());
@@ -152,6 +158,7 @@ public class HttpRequestParam {
/**
* PATCH请求
* @return HttpRequest
*/
public HttpRequest patch() {
HttpRequest request = HttpRequest.patch(this.getUrl());
@@ -161,6 +168,7 @@ public class HttpRequestParam {
/**
* DELETE请求
* @return HttpRequest
*/
public HttpRequest delete() {
HttpRequest request = HttpRequest.delete(this.getUrl());
@@ -170,6 +178,7 @@ public class HttpRequestParam {
/**
* TRACE请求
* @return HttpRequest
*/
public HttpRequest trace() {
HttpRequest request = HttpRequest.trace(this.getUrl());

View File

@@ -1,7 +1,8 @@
package com.mg.swagger.controller.vo;
package com.zyplayer.doc.swagger.controller.vo;
/**
* cookie返回值对象
*
* @author 暮光城中城
* @since 2018年8月21日
*/
@@ -9,6 +10,15 @@ public class HttpCookieVo {
private String name;
private String value;
public HttpCookieVo() {
}
public HttpCookieVo(String name, String value) {
this.name = name;
this.value = value;
}
public String getName() {
return name;
}

View File

@@ -1,4 +1,4 @@
package com.mg.swagger.controller.vo;
package com.zyplayer.doc.swagger.controller.vo;
/**
* header返回值对象

View File

@@ -0,0 +1,55 @@
package com.zyplayer.doc.swagger.controller.vo;
import java.util.List;
import io.swagger.annotations.ApiModelProperty;
/**
* request返回值对象
*
* @author 暮光:城中城
* @since 2018年8月21日
*/
public class HttpRequestVo {
@ApiModelProperty(value = "代理请求返回的cookie")
private List<HttpCookieVo> cookie;
@ApiModelProperty(value = "代理请求返回的header")
private List<HttpHeaderVo> header;
@ApiModelProperty(value = "代理请求返回的status")
private Integer status;
@ApiModelProperty(value = "返回数据")
private Object data;
public Object getData() {
return data;
}
public void setData(Object data) {
this.data = data;
}
public List<HttpCookieVo> getCookie() {
return cookie;
}
public void setCookie(List<HttpCookieVo> cookie) {
this.cookie = cookie;
}
public List<HttpHeaderVo> getHeader() {
return header;
}
public void setHeader(List<HttpHeaderVo> header) {
this.header = header;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}

View File

@@ -0,0 +1,69 @@
package com.zyplayer.doc.swagger.controller.vo;
public class SwaggerLocationVo {
private String swagger;
private String info;
private String host;
private String paths;
private String definitions;
private String tags;
private String basePath;
public String getSwagger() {
return swagger;
}
public void setSwagger(String swagger) {
this.swagger = swagger;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public String getPaths() {
return paths;
}
public void setPaths(String paths) {
this.paths = paths;
}
public String getDefinitions() {
return definitions;
}
public void setDefinitions(String definitions) {
this.definitions = definitions;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
public String getBasePath() {
return basePath;
}
public void setBasePath(String basePath) {
this.basePath = basePath;
}
}

View File

@@ -1,4 +1,4 @@
package com.mg.swagger.framework.configuration;
package com.zyplayer.doc.swagger.framework.configuration;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
@@ -6,23 +6,21 @@ import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
import com.mg.swagger.framework.filter.MgUiTestFilter;
@Retention(value = java.lang.annotation.RetentionPolicy.RUNTIME)
@Target(value = { java.lang.annotation.ElementType.TYPE })
@Documented
@Import({ SwaggerCommonConfiguration.class, MgUiTestFilter.class, SpringContextUtil.class })
@Import({ SwaggerCommonConfiguration.class, SpringContextUtil.class })
public @interface EnableSwaggerMgUi {
/**
* 是否自动把自身的swagger-resources加进来
* @return
* @return 配置
*/
boolean selfDoc() default true;
/**
* 启动后第一次访问没有数据情况下需要加载进来的swagger-resources地址
* @return
* @return swagger-resources地址
*/
String[] defaultResources() default {};
}

View File

@@ -1,4 +1,4 @@
package com.mg.swagger.framework.configuration;
package com.zyplayer.doc.swagger.framework.configuration;
import java.lang.annotation.Annotation;
import java.util.Map;
@@ -35,8 +35,8 @@ public class SpringContextUtil implements ApplicationContextAware {
/**
* 获取类
* @param cacheName
* @return
* @param annotationType annotation
* @return 类对象
*/
public static Object getBeanWithAnnotation(Class<? extends Annotation> annotationType) {
if (context == null) {

View File

@@ -0,0 +1,25 @@
package com.zyplayer.doc.swagger.framework.configuration;
import org.springframework.context.annotation.ComponentScan;
//@EnableAutoConfiguration
@ComponentScan(basePackages = {
"com.zyplayer.doc.swagger.controller",
"com.zyplayer.doc.swagger.framework.service",
})
public class SwaggerCommonConfiguration {
// 不再默认开启拦截
// @Autowired
// private MgUiTestFilter mgUiTestFilter;
//
// @Bean
// public FilterRegistrationBean mockTestFilter() {
// FilterRegistrationBean registration = new FilterRegistrationBean();
// registration.setFilter(mgUiTestFilter);
// registration.addUrlPatterns("/*");
// registration.setName("mgUiTestFilter");
// registration.setOrder(2);
// return registration;
// }
}

View File

@@ -1,4 +1,4 @@
package com.mg.swagger.framework.constant;
package com.zyplayer.doc.swagger.framework.constant;
/**
* 存储数据的KEY常量类
@@ -11,4 +11,6 @@ public class StorageKeys {
public static final String SWAGGER_RESOURCES_LIST = "swagger-resources-list";
// 已删除的文档
public static final String SWAGGER_DOCS_DELETE_LIST = "swagger-docs-delete-list";
// 所有详细文档地址
public static final String SWAGGER_LOCATION_LIST = "swagger-location-list";
}

View File

@@ -1,4 +1,4 @@
package com.mg.swagger.framework.constant;
package com.zyplayer.doc.swagger.framework.constant;
/**
* 提示语常量类

View File

@@ -1,4 +1,4 @@
package com.mg.swagger.framework.filter;
package com.zyplayer.doc.swagger.framework.filter;
import java.io.IOException;
@@ -12,11 +12,11 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.mg.swagger.framework.service.MgStorageService;
import com.zyplayer.doc.swagger.framework.service.MgStorageService;
/**
* 有需要此拦截器的请自行拷贝至自身项目不再开启@Component<br>
* 判断是否是模拟请求功能需求<br>
* 很多时候后端定义好了接口但还未实现这时前端已经需要数据调试了这时就需要用到这个过滤器了<br>
* 在页面上先配置好模拟返回的数据然后在url上加入参数mgUiTestFlag=1<br>
@@ -27,7 +27,7 @@ import com.mg.swagger.framework.service.MgStorageService;
* 也许需要10天才能写完但前端两天就写好了急需数据看效果这时就让他们自己去设置模拟值加上参数自己测试好
* 而不是一味的催后台把各种锅丢给后端然后玩自己的去了浪费各环节等待时间
*/
@Component
//@Component
public class MgUiTestFilter implements Filter {
@Autowired(required = false)

View File

@@ -0,0 +1,47 @@
package com.zyplayer.doc.swagger.framework.service;
import java.io.Serializable;
/**
* 数据类型
* @author 暮光:城中城
* @since 2018-11-27
*/
public class MgStorage implements Serializable {
private static final long serialVersionUID = 1L;
private String key;
private String value;
public MgStorage() {
}
public MgStorage(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}

View File

@@ -1,4 +1,6 @@
package com.mg.swagger.framework.service;
package com.zyplayer.doc.swagger.framework.service;
import java.util.List;
/**
* 实现此类才能使用服务器端的存贮功能
@@ -11,17 +13,27 @@ public interface MgStorageService {
* 获取存储的值
* @author 暮光城中城
* @since 2018年8月19日
* @param key
* @return
* @param key 参数
* @return
*/
String get(String key);
/**
* 模糊获取存储的值
* @author 暮光城中城
* @since 2018年8月19日
* @param key 参数
* @param value
* @return
*/
List<MgStorage> like(String key, String value);
/**
* 存储数据
* @author 暮光城中城
* @since 2018年8月19日
* @param key
* @param value
* @param key 参数
* @param value
*/
void put(String key, String value);
@@ -29,7 +41,7 @@ public interface MgStorageService {
* 删除数据
* @author 暮光城中城
* @since 2018年8月19日
* @param key
* @param key 参数
*/
void remove(String key);

View File

@@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>swagger-mg-ui</title>
<title>接口文档管理系统 - zyplayer</title>
<link rel="shortcut icon" href="webjars/mg-ui/img/api.ico"/>
<link rel="stylesheet" href="webjars/zui/css/zui.min.css" />
<link rel="stylesheet" href="webjars/zui/lib/dashboard/zui.dashboard.min.css" />
@@ -12,12 +12,12 @@
<body>
<div class="left-body" id="leftContent">
<div class="left-header">
<span class="logo" id="logoText">swagger-mg-ui</span>
<span class="logo" id="logoText">zyplayer-doc-swagger</span>
<i class="icon icon-bars" id="changeContentWidth"></i>
</div>
<div class="scrollbar-hover left-container">
<!-- 样式类可选tree-menu tree-folders tree-chevrons tree-angles -->
<ul class="tree tree-lines tree-menu projects">
<ul class="tree tree-lines tree-menu projects" data-ride="tree">
<li>
<div class="input-group">
<input type="text" class="form-control" id="searchDocInput">
@@ -27,7 +27,16 @@
</div>
</li>
<li id="homePageLi"><a href="javascript:void(0)" path=""><i class="icon-home"></i> 控制台</a></li>
<li id="onlineDebugLi" class="local-storage"><a href="javascript:void(0)" path=""><i class="icon-bug"></i> 在线调试管理</a></li>
<li>
<a href="#"><i class="icon icon-cogs"></i> 文档管理</a>
<ul>
<li id="onlineDebugLi" class="local-storage"><a href="javascript:void(0)" path=""><i class="icon-bug"></i> 在线调试管理</a></li>
<li><a href="#" path=""><i class="icon-cog"></i> 文档展示配置</a></li>
<li><a href="#" path=""><i class="icon-globe"></i> 全局参数管理</a></li>
<li><a href="#" path=""><i class="icon-bug"></i> 调试数据管理</a></li>
<li><a href="#" path=""><i class="icon-list-ul"></i> 文档地址管理</a></li>
</ul>
</li>
</ul>
<div id="apiPathTree">
<ul class="tree tree-lines projects"></ul>
@@ -104,11 +113,11 @@
<tr>
<td colspan="2">
<div align="center">简介</div>
swagger-mg-ui是swagger-ui的一个前端实现使用简单、解析速度快、走心的设计
zyplayer-doc-swagger是swagger-ui的一个前端实现使用简单、解析速度快、走心的设计
支持多项目同时展示,多种文档目录的展示方案,多种自定义配置,满足各种使用习惯。
本项目是完全从头写的所以有任何属性未解析到、UI上有何建议都能及时处理得到。
使用中您有任何的意见和建议都可到源码地址处反馈哦!<br/>
源码地址:<a target="_blank" href="https://gitee.com/zyplayer/swagger-mg-ui">swagger-mg-ui</a>
源码地址:<a target="_blank" href="https://gitee.com/zyplayer/zyplayer-doc">zyplayer-doc-swagger</a>
前端框架:<a target="_blank" href="http://zui.sexy">zui</a>
我的网站:<a target="_blank" href="http://kongjianzhou.com">空间轴</a>
</td>
@@ -369,7 +378,7 @@
</tr>
<tr>
<td class="info">测试地址</td>
<td><a id="simulationResultUrlTest" href="" target="_blank"></a> <i class="icon icon-info-sign" title='需要被访问项目导入swagger-mg-ui包才能使用'></i></td>
<td><a id="simulationResultUrlTest" href="" target="_blank"></a> <i class="icon icon-info-sign" title='需要被访问项目导入zyplayer-doc包才能使用'></i></td>
</tr>
<tr>
<td class="info">返回内容</td>
@@ -417,7 +426,7 @@
</div>
<div class="modal-body">
<div class="alert alert-danger hidden">
1、请到 <a target="_blank" href="https://gitee.com/zyplayer/swagger-mg-ui">源码处下载</a>《对外文档模板.zip》解压<br/>
1、请到 <a target="_blank" href="https://gitee.com/zyplayer/zyplayer-doc">源码处下载</a>《对外文档模板.zip》解压<br/>
2、复制以下文本内容覆盖至 /js/mg-ui-data.js 文件内<br/>
3、然后双击打开目录下的document.html 即可看到导出的文档
</div>

View File

@@ -97,7 +97,7 @@ label{font-weight: normal;}
.param-box .param-table tbody td:nth-child(3){border-left: 0;padding: 0 10px 0 0;width: 10px;}
.param-box .param-table tbody td:nth-child(3) i{cursor: pointer;color: #ccc;}
.param-box .param-table tbody td:nth-child(3) i:hover{color: #888;}
.param-box .param-table tbody tr.base td:last-child{display: none;}
.param-box .param-table tbody tr.base td:last-child i{display: none;}
#bulkEditHeaderCheck{margin-left: 10px;}
#bulkEditHeader,#bulkEditForm{display: none;}

View File

@@ -100,22 +100,23 @@ $(document).ready(function(){
paramSendToServer.method = options;
ajaxTemp("swagger-mg-ui/http/request", "post", "json", paramSendToServer, function(result){
//console.log(result);
var requestObj = result.data;
setStorage('p-request-obj-' + docUrl, storeRequestParam);
var afterSendTime = new Date().getTime();
$("#httpRequestStatus").text(result.status);
$("#httpRequestStatus").text(requestObj.status);
$("#httpRequestTime").text((afterSendTime - beforSendTime) + "ms");
try {
var htmlStr = Formatjson.processObjectToHtmlPre(JSON.parse(result.data), 0, false, false, false, false);
var htmlStr = Formatjson.processObjectToHtmlPre(JSON.parse(requestObj.data), 0, false, false, false, false);
$("#responseBodyJsonDiv").html(htmlStr);
} catch (e) {
$("#responseBodyJsonDiv").html("<iframe id='responseBodyJsonIframe'></iframe>");
setTimeout(function(){
$("#responseBodyJsonIframe").contents().find("body").html(result.data);
$("#responseBodyJsonIframe").contents().find("body").html(requestObj.data);
}, 300);
}
$("#tabResponseHeader table tbody").empty();
$("#tabResponseCookie table tbody").empty();
var headers = result.header||[];
var headers = requestObj.header||[];
for (var i = 0; i < headers.length; i++) {
var name = getNotEmptyStr(headers[i].name);
var value = getNotEmptyStr(headers[i].value);
@@ -123,7 +124,7 @@ $(document).ready(function(){
'<tr>'+'<td>'+name+'</td>' + '<td>'+value+'</td>'+'</tr>'
);
}
var cookies = result.cookie||[];
var cookies = requestObj.cookie||[];
for (var i = 0; i < cookies.length; i++) {
var name = getNotEmptyStr(cookies[i].name);
var value = getNotEmptyStr(cookies[i].value);

View File

@@ -1,8 +1,8 @@
/**
* swagger-mg-ui是swagger-ui的一个前端实现使用简单、解析速度快、走心的设计
* zyplayer-doc-swagger是swagger-ui的一个前端实现使用简单、解析速度快、走心的设计
* 支持多项目同时展示,多种文档目录的展示方案,多种自定义配置,满足各种使用习惯。
* 使用中您有任何的意见和建议都可到源码地址处反馈哦!
* git地址https://gitee.com/zyplayer/swagger-mg-ui
* git地址https://gitee.com/zyplayer/zyplayer-doc-swagger
* @author 暮光:城中城
* @since 2018年5月20日
*/
@@ -873,11 +873,11 @@ function changeContentWidth(width) {
$("#leftContent").css("width", width + 'px');
$("#resizebleLeftRight").css("left", width + 'px');
$("#rightContent").css("left", width + 'px');
var logoText = "swagger-mg-ui";
if(width < 270 && width > 140){
logoText = "mg-ui";
} else if(width < 140){
logoText = "mui";
var logoText = "zyplayer-doc-swagger";
if(width < 370 && width > 290){
logoText = "zyplayer-doc";
} else if(width < 290){
logoText = "doc";
}
$("#logoText").text(logoText);
userSettings.prevWNow = width;