Add pathPrefix to config context-path

This commit is contained in:
shalousun 2021-07-09 23:26:13 +08:00
parent 21cbef4b82
commit d9bdf58d95
7 changed files with 17 additions and 13 deletions

View File

@ -1,5 +1,10 @@
## smart-doc版本
#### 版本号2.2.3
- 更新日期: 2020-07-12
- 更新内容:
1. 增加pathPrefix配置项用于配置上下文引入该配置项后serverUrl仅用于配置服务器地址。
#### 版本号2.2.2
- 更新日期: 2020-07-04

View File

@ -125,7 +125,7 @@ smart-doc官方目前已经开发完成[Maven插件](https://gitee.com/smart-doc
"outPath": "D://md2", //指定文档的输出路径
"coverOld": true, //是否覆盖旧的文件主要用于mardown文件覆盖
"createDebugPage": true,//@since 2.0.0 smart-doc支持创建可以测试的html页面仅在AllInOne模式中起作用。
"packageFilters": "",//controller包过滤多个包用英文逗号隔开
"packageFilters": "",//controller包过滤多个包用英文逗号隔开需要采用正则com.test.controller.*
"md5EncryptedHtmlName": false,//只有每个controller生成一个html文件是才使用
"style":"xt256", //基于highlight.js的代码高设置,可选值很多可查看码云wiki喜欢配色统一简洁的同学可以不设置
"projectName": "smart-doc",//配置自己的项目名称

View File

@ -85,7 +85,7 @@ public class OpenApiBuilder {
json.put("openapi", "3.0.3");
json.put("info", buildInfo(config));
json.put("servers", buildServers(config));
json.put("paths", buildPaths(config, apiDocList));
json.put("paths", buildPaths(apiDocList));
json.put("components", buildComponentsSchema(apiDocList));
String filePath = config.getOutPath();
@ -127,7 +127,7 @@ public class OpenApiBuilder {
* @param apiDocList api列表
* @return
*/
private static Map<String, Object> buildPaths(ApiConfig config, List<ApiDoc> apiDocList) {
private static Map<String, Object> buildPaths(List<ApiDoc> apiDocList) {
Map<String, Object> pathMap = new HashMap<>(500);
apiDocList.forEach(
a -> {
@ -135,7 +135,7 @@ public class OpenApiBuilder {
apiMethodDocs.forEach(
method -> {
//设置paths的请求url 将双斜杠替换成单斜杠
String url = (config.getPathPrefix() + "/" + method.getPath()).replace("//", "/");
String url = method.getPath().replace("//", "/");
Map<String, Object> request = buildPathUrls(method, a);
//pathMap.put(method.getPath().replace("//", "/"), buildPathUrls(method, a));
if (!pathMap.containsKey(url)) {

View File

@ -193,9 +193,6 @@ public class ProjectDocConfigBuilder {
}
}
/**
* 设置高亮样式
*/
private void setHighlightStyle() {
String style = apiConfig.getStyle();
if (HighlightStyle.containsStyle(style)) {

View File

@ -215,4 +215,6 @@ public interface DocGlobalConstants {
String CSS_CDN = "https://fonts.googleapis.com";
String PATH_DELIMITER = "/";
}

View File

@ -35,7 +35,6 @@ import com.power.doc.utils.DocUtil;
import com.thoughtworks.qdox.model.JavaAnnotation;
import com.thoughtworks.qdox.model.JavaMethod;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -64,6 +63,7 @@ public class SpringMVCRequestMappingHandler {
String shortUrl = null;
String mediaType = null;
String serverUrl = projectBuilder.getServerUrl();
String contextPath = projectBuilder.getApiConfig().getPathPrefix();
boolean deprecated = false;
for (JavaAnnotation annotation : annotations) {
String annotationName = annotation.getType().getName();
@ -110,11 +110,11 @@ public class SpringMVCRequestMappingHandler {
shortUrl = StringUtil.removeQuotes(shortUrl);
List<String> urls = DocUtil.split(shortUrl);
if (urls.size() > 1) {
url = DocUrlUtil.getMvcUrls(serverUrl, controllerBaseUrl, urls);
shortUrl = DocUrlUtil.getMvcUrls("", controllerBaseUrl, urls);
url = DocUrlUtil.getMvcUrls(serverUrl, contextPath + "/" + controllerBaseUrl, urls);
shortUrl = DocUrlUtil.getMvcUrls(DocGlobalConstants.EMPTY, contextPath + "/" + controllerBaseUrl, urls);
} else {
url = serverUrl + "/" + controllerBaseUrl + "/" + shortUrl;
shortUrl = "/" + controllerBaseUrl + "/" + shortUrl;
url = String.join(DocGlobalConstants.PATH_DELIMITER, serverUrl, contextPath, controllerBaseUrl, shortUrl);
shortUrl = String.join(DocGlobalConstants.PATH_DELIMITER, DocGlobalConstants.PATH_DELIMITER, contextPath, controllerBaseUrl, shortUrl);
}
for (Map.Entry<String, String> entry : constantsMap.entrySet()) {
String key = entry.getKey();

View File

@ -46,7 +46,7 @@ public class ApiConfig {
/**
* Path Prefix, eg: Servlet ContextPath
*/
private String pathPrefix;
private String pathPrefix = "";
/**
* Set comments check mode