Merge pull request #129 from Taogang00/master

feat:添加支持Path前缀
This commit is contained in:
shalousun 2021-07-09 21:27:23 +08:00 committed by GitHub
commit 6d8182dd08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 5 deletions

View File

@ -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

View File

@ -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", //指定文档的输出路径
@ -333,4 +334,4 @@ the [LICENSE](https://gitee.com/smart-doc-team/smart-doc/blob/master/LICENSE) fi
## Donate
如果您觉得我们的开源软件对你有所帮助,请扫下方二维码打赏我们一杯咖啡
<img src="https://images.gitee.com/uploads/images/2020/0831/225756_9aecdd4d_144669.png" width="200px" height="210px"/>
<img src="https://images.gitee.com/uploads/images/2020/0831/225756_9aecdd4d_144669.png" width="200px" height="210px"/>

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(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<String, Object> buildPaths(List<ApiDoc> apiDocList) {
private static Map<String, Object> buildPaths(ApiConfig config, 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 = method.getPath().replace("//", "/");
String url = (config.getPathPrefix() + "/" + method.getPath()).replace("//", "/");
Map<String, Object> request = buildPathUrls(method, a);
//pathMap.put(method.getPath().replace("//", "/"), buildPathUrls(method, a));
if (!pathMap.containsKey(url)) {

View File

@ -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();
}
}
}