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