support url suffix
This commit is contained in:
parent
f2811364ed
commit
282d9b20ed
|
@ -24,6 +24,7 @@ package com.power.doc.handler;
|
|||
|
||||
import com.power.common.util.StringUtil;
|
||||
import com.power.common.util.UrlUtil;
|
||||
import com.power.doc.builder.ProjectDocConfigBuilder;
|
||||
import com.power.doc.constants.DocAnnotationConstants;
|
||||
import com.power.doc.constants.DocGlobalConstants;
|
||||
import com.power.doc.constants.Methods;
|
||||
|
@ -50,19 +51,19 @@ public class SpringMVCRequestMappingHandler {
|
|||
/**
|
||||
* handle spring request mapping
|
||||
*
|
||||
* @param serverUrl server url
|
||||
* @param projectBuilder projectBuilder
|
||||
* @param controllerBaseUrl spring mvc controller base url
|
||||
* @param method JavaMethod
|
||||
* @param constantsMap project constant container
|
||||
* @return RequestMapping
|
||||
*/
|
||||
public RequestMapping handle(String serverUrl, String controllerBaseUrl, JavaMethod method, Map<String, String> constantsMap) {
|
||||
public RequestMapping handle(ProjectDocConfigBuilder projectBuilder, String controllerBaseUrl, JavaMethod method, Map<String, String> constantsMap) {
|
||||
List<JavaAnnotation> annotations = method.getAnnotations();
|
||||
String url;
|
||||
String methodType = null;
|
||||
String shortUrl = null;
|
||||
String mediaType = null;
|
||||
|
||||
String serverUrl = projectBuilder.getServerUrl();
|
||||
boolean deprecated = false;
|
||||
for (JavaAnnotation annotation : annotations) {
|
||||
String annotationName = annotation.getType().getName();
|
||||
|
@ -127,8 +128,14 @@ public class SpringMVCRequestMappingHandler {
|
|||
shortUrl = shortUrl.replace("+", "");
|
||||
}
|
||||
}
|
||||
url = UrlUtil.simplifyUrl(url);
|
||||
shortUrl = UrlUtil.simplifyUrl(shortUrl);
|
||||
String urlSuffix = projectBuilder.getApiConfig().getUrlSuffix();
|
||||
if (StringUtil.isNotEmpty(urlSuffix)) {
|
||||
url = UrlUtil.simplifyUrl(url) + urlSuffix;
|
||||
shortUrl = UrlUtil.simplifyUrl(shortUrl) + urlSuffix;
|
||||
} else {
|
||||
url = UrlUtil.simplifyUrl(url);
|
||||
shortUrl = UrlUtil.simplifyUrl(shortUrl);
|
||||
}
|
||||
return RequestMapping.builder().setMediaType(mediaType).setMethodType(methodType)
|
||||
.setUrl(StringUtil.trim(url)).setShortUrl(StringUtil.trim(shortUrl)).setDeprecated(deprecated);
|
||||
}
|
||||
|
|
|
@ -271,6 +271,12 @@ public class ApiConfig {
|
|||
*/
|
||||
private boolean createDebugPage;
|
||||
|
||||
/**
|
||||
* Spring MVC url suffix
|
||||
* @since 2.1.0
|
||||
*/
|
||||
private String urlSuffix;
|
||||
|
||||
/**
|
||||
* public static final String APP_KEY = "20201216788835306945118208";
|
||||
* public static final String SECRET = "W.ZyGMOB9Q0UqujVxnfi@.I#V&tUUYZR";
|
||||
|
@ -303,6 +309,7 @@ public class ApiConfig {
|
|||
* 调试环境请求路径
|
||||
*/
|
||||
private String debugEnvUrl;
|
||||
|
||||
/**
|
||||
* torna调试开关
|
||||
*/
|
||||
|
@ -733,6 +740,14 @@ public class ApiConfig {
|
|||
this.debugEnvUrl = debugEnvUrl;
|
||||
}
|
||||
|
||||
public String getUrlSuffix() {
|
||||
return urlSuffix;
|
||||
}
|
||||
|
||||
public void setUrlSuffix(String urlSuffix) {
|
||||
this.urlSuffix = urlSuffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder("{");
|
||||
|
@ -816,6 +831,22 @@ public class ApiConfig {
|
|||
.append(style).append('\"');
|
||||
sb.append(",\"createDebugPage\":")
|
||||
.append(createDebugPage);
|
||||
sb.append(",\"urlSuffix\":\"")
|
||||
.append(urlSuffix).append('\"');
|
||||
sb.append(",\"appKey\":\"")
|
||||
.append(appKey).append('\"');
|
||||
sb.append(",\"secret\":\"")
|
||||
.append(secret).append('\"');
|
||||
sb.append(",\"appToken\":\"")
|
||||
.append(appToken).append('\"');
|
||||
sb.append(",\"openUrl\":\"")
|
||||
.append(openUrl).append('\"');
|
||||
sb.append(",\"debugEnvName\":\"")
|
||||
.append(debugEnvName).append('\"');
|
||||
sb.append(",\"debugEnvUrl\":\"")
|
||||
.append(debugEnvUrl).append('\"');
|
||||
sb.append(",\"tornaDebug\":")
|
||||
.append(tornaDebug);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ public class SpringBootDocBuildTemplate implements IDocBuildTemplate<ApiDoc> {
|
|||
}
|
||||
//handle request mapping
|
||||
RequestMapping requestMapping = new SpringMVCRequestMappingHandler()
|
||||
.handle(projectBuilder.getServerUrl(), baseUrl, method, constantsMap);
|
||||
.handle(projectBuilder, baseUrl, method, constantsMap);
|
||||
if (Objects.isNull(requestMapping)) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue