Skip to content

Commit 08abe94

Browse files
committed
feat(api-doc): ApiDocUtils 新增 buildGroupedOpenApi(构建分组接口文档) 方法
DocUtils => ApiDocUtils
1 parent 079adb8 commit 08abe94

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

continew-starter-api-doc/src/main/java/top/continew/starter/apidoc/handler/BaseEnumParameterHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.springdoc.core.customizers.ParameterCustomizer;
2727
import org.springdoc.core.customizers.PropertyCustomizer;
2828
import org.springframework.core.MethodParameter;
29-
import top.continew.starter.apidoc.util.DocUtils;
29+
import top.continew.starter.apidoc.util.ApiDocUtils;
3030
import top.continew.starter.core.enums.BaseEnum;
3131

3232
import java.lang.reflect.Type;
@@ -84,9 +84,9 @@ private void configureSchema(Schema schema, Class<?> enumClass) {
8484
BaseEnum[] enums = (BaseEnum[])enumClass.getEnumConstants();
8585
List<String> valueList = Arrays.stream(enums).map(e -> e.getValue().toString()).toList();
8686
schema.setEnum(valueList);
87-
String enumValueType = DocUtils.getEnumValueTypeAsString(enumClass);
87+
String enumValueType = ApiDocUtils.getEnumValueTypeAsString(enumClass);
8888
schema.setType(enumValueType);
89-
schema.setFormat(DocUtils.resolveFormat(enumValueType));
89+
schema.setFormat(ApiDocUtils.resolveFormat(enumValueType));
9090
}
9191

9292
/**
@@ -97,7 +97,7 @@ private void configureSchema(Schema schema, Class<?> enumClass) {
9797
* @return 追加后的描述字符串
9898
*/
9999
private String appendEnumDescription(String originalDescription, Class<?> enumClass) {
100-
return originalDescription + "<span style='color:red'>" + DocUtils.getDescMap(enumClass) + "</span>";
100+
return originalDescription + "<span style='color:red'>" + ApiDocUtils.getDescMap(enumClass) + "</span>";
101101
}
102102

103103
/**

continew-starter-api-doc/src/main/java/top/continew/starter/apidoc/util/DocUtils.java renamed to continew-starter-api-doc/src/main/java/top/continew/starter/apidoc/util/ApiDocUtils.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package top.continew.starter.apidoc.util;
1818

19+
import org.springdoc.core.models.GroupedOpenApi;
1920
import org.springframework.web.bind.annotation.RestController;
2021
import top.continew.starter.core.enums.BaseEnum;
2122

@@ -30,11 +31,37 @@
3031
* 接口文档工具类
3132
*
3233
* @author echo
34+
* @author Charles7c
3335
* @since 2.5.2
3436
*/
35-
public class DocUtils {
37+
public class ApiDocUtils {
3638

37-
private DocUtils() {
39+
private ApiDocUtils() {
40+
}
41+
42+
/**
43+
* 构建分组接口文档
44+
*
45+
* @param group 分组名称
46+
* @param pathsToMatch 路径匹配
47+
* @return GroupedOpenApi
48+
* @since 2.13.0
49+
*/
50+
public static GroupedOpenApi buildGroupedOpenApi(String group, String... pathsToMatch) {
51+
return buildGroupedOpenApi(group, group, pathsToMatch);
52+
}
53+
54+
/**
55+
* 构建分组接口文档
56+
*
57+
* @param group 分组名称
58+
* @param displayName 分组显示名称
59+
* @param pathsToMatch 路径匹配
60+
* @return GroupedOpenApi
61+
* @since 2.13.0
62+
*/
63+
public static GroupedOpenApi buildGroupedOpenApi(String group, String displayName, String... pathsToMatch) {
64+
return GroupedOpenApi.builder().group(group).displayName(displayName).pathsToMatch(pathsToMatch).build();
3865
}
3966

4067
/**

continew-starter-web/src/main/java/top/continew/starter/web/autoconfigure/response/ApiDocGlobalResponseHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.apache.commons.lang3.reflect.TypeUtils;
2121
import org.springdoc.core.parsers.ReturnTypeParser;
2222
import org.springframework.core.MethodParameter;
23-
import top.continew.starter.apidoc.util.DocUtils;
23+
import top.continew.starter.apidoc.util.ApiDocUtils;
2424

2525
import java.lang.reflect.Type;
2626

@@ -54,7 +54,7 @@ public Type getReturnType(MethodParameter methodParameter) {
5454
// 获取返回类型
5555
Type returnType = ReturnTypeParser.super.getReturnType(methodParameter);
5656
// 判断是否具有 RestController 注解
57-
if (!DocUtils.hasRestControllerAnnotation(methodParameter.getContainingClass())) {
57+
if (!ApiDocUtils.hasRestControllerAnnotation(methodParameter.getContainingClass())) {
5858
return returnType;
5959
}
6060
// 如果为响应类型,则直接返回

0 commit comments

Comments
 (0)