diff --git a/README.md b/README.md
index 7933201..063f32e 100644
--- a/README.md
+++ b/README.md
@@ -114,6 +114,7 @@ When you need to use smart-doc to generate more API document information, you ca
```
{
"serverUrl": "http://127.0.0.1", // Set the server address, not required
+ "pathPrefix": "", //Set the path prefix,not required。eg: Servlet ContextPath
"isStrict": false, // whether to enable strict mode
"allInOne": true, // whether to merge documents into one file, generally recommended as true
"outPath": "D: // md2", // Specify the output path of the document
diff --git a/README_CN.md b/README_CN.md
index 7044855..730af20 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -119,6 +119,7 @@ smart-doc官方目前已经开发完成[Maven插件](https://gitee.com/smart-doc
```
{
"serverUrl": "http://127.0.0.1", //服务器地址,非必须。导出postman建议设置成http://{{server}}方便直接在postman直接设置环境变量
+ "pathPrefix": "", //设置path前缀,非必须。如配置Servlet ContextPath
"isStrict": false, //是否开启严格模式
"allInOne": true, //是否将文档合并到一个文件中,一般推荐为true
"outPath": "D://md2", //指定文档的输出路径
@@ -334,4 +335,4 @@ the [LICENSE](https://gitee.com/smart-doc-team/smart-doc/blob/master/LICENSE) fi
## Donate
如果您觉得我们的开源软件对你有所帮助,请扫下方二维码打赏我们一杯咖啡
-
\ No newline at end of file
+
diff --git a/src/main/java/com/power/doc/builder/OpenApiBuilder.java b/src/main/java/com/power/doc/builder/OpenApiBuilder.java
index cdb13ef..03ba671 100644
--- a/src/main/java/com/power/doc/builder/OpenApiBuilder.java
+++ b/src/main/java/com/power/doc/builder/OpenApiBuilder.java
@@ -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(apiDocList));
+ json.put("paths", buildPaths(config, apiDocList));
json.put("components", buildComponentsSchema(apiDocList));
String filePath = config.getOutPath();
@@ -127,7 +127,7 @@ public class OpenApiBuilder {
* @param apiDocList api列表
* @return
*/
- private static Map buildPaths(List apiDocList) {
+ private static Map buildPaths(ApiConfig config, List apiDocList) {
Map pathMap = new HashMap<>(500);
apiDocList.forEach(
a -> {
@@ -135,7 +135,7 @@ public class OpenApiBuilder {
apiMethodDocs.forEach(
method -> {
//设置paths的请求url 将双斜杠替换成单斜杠
- String url = method.getPath().replace("//", "/");
+ String url = (config.getPathPrefix() + "/" + method.getPath()).replace("//", "/");
Map request = buildPathUrls(method, a);
//pathMap.put(method.getPath().replace("//", "/"), buildPathUrls(method, a));
if (!pathMap.containsKey(url)) {
diff --git a/src/main/java/com/power/doc/model/ApiConfig.java b/src/main/java/com/power/doc/model/ApiConfig.java
index c98d911..5523c08 100644
--- a/src/main/java/com/power/doc/model/ApiConfig.java
+++ b/src/main/java/com/power/doc/model/ApiConfig.java
@@ -43,6 +43,11 @@ public class ApiConfig {
*/
private String serverUrl;
+ /**
+ * Path Prefix, eg: Servlet ContextPath
+ */
+ private String pathPrefix;
+
/**
* Set comments check mode
*/
@@ -337,6 +342,14 @@ public class ApiConfig {
*/
private String framework;
+ public String getPathPrefix() {
+ return pathPrefix;
+ }
+
+ public void setPathPrefix(String pathPrefix) {
+ this.pathPrefix = pathPrefix;
+ }
+
public String getAuthor() {
return author;
}
@@ -915,4 +928,4 @@ public class ApiConfig {
sb.append('}');
return sb.toString();
}
-}
\ No newline at end of file
+}