mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-12 03:03:08 +08:00
feat(api-doc): ApiDocUtils 新增 buildGroupedOpenApi(构建分组接口文档) 方法
DocUtils => ApiDocUtils
This commit is contained in:
@@ -26,7 +26,7 @@ import io.swagger.v3.oas.models.parameters.Parameter;
|
|||||||
import org.springdoc.core.customizers.ParameterCustomizer;
|
import org.springdoc.core.customizers.ParameterCustomizer;
|
||||||
import org.springdoc.core.customizers.PropertyCustomizer;
|
import org.springdoc.core.customizers.PropertyCustomizer;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import top.continew.starter.apidoc.util.DocUtils;
|
import top.continew.starter.apidoc.util.ApiDocUtils;
|
||||||
import top.continew.starter.core.enums.BaseEnum;
|
import top.continew.starter.core.enums.BaseEnum;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
@@ -84,9 +84,9 @@ public class BaseEnumParameterHandler implements ParameterCustomizer, PropertyCu
|
|||||||
BaseEnum[] enums = (BaseEnum[])enumClass.getEnumConstants();
|
BaseEnum[] enums = (BaseEnum[])enumClass.getEnumConstants();
|
||||||
List<String> valueList = Arrays.stream(enums).map(e -> e.getValue().toString()).toList();
|
List<String> valueList = Arrays.stream(enums).map(e -> e.getValue().toString()).toList();
|
||||||
schema.setEnum(valueList);
|
schema.setEnum(valueList);
|
||||||
String enumValueType = DocUtils.getEnumValueTypeAsString(enumClass);
|
String enumValueType = ApiDocUtils.getEnumValueTypeAsString(enumClass);
|
||||||
schema.setType(enumValueType);
|
schema.setType(enumValueType);
|
||||||
schema.setFormat(DocUtils.resolveFormat(enumValueType));
|
schema.setFormat(ApiDocUtils.resolveFormat(enumValueType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -97,7 +97,7 @@ public class BaseEnumParameterHandler implements ParameterCustomizer, PropertyCu
|
|||||||
* @return 追加后的描述字符串
|
* @return 追加后的描述字符串
|
||||||
*/
|
*/
|
||||||
private String appendEnumDescription(String originalDescription, Class<?> enumClass) {
|
private String appendEnumDescription(String originalDescription, Class<?> enumClass) {
|
||||||
return originalDescription + "<span style='color:red'>" + DocUtils.getDescMap(enumClass) + "</span>";
|
return originalDescription + "<span style='color:red'>" + ApiDocUtils.getDescMap(enumClass) + "</span>";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package top.continew.starter.apidoc.util;
|
package top.continew.starter.apidoc.util;
|
||||||
|
|
||||||
|
import org.springdoc.core.models.GroupedOpenApi;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import top.continew.starter.core.enums.BaseEnum;
|
import top.continew.starter.core.enums.BaseEnum;
|
||||||
|
|
||||||
@@ -30,11 +31,37 @@ import java.util.stream.Collectors;
|
|||||||
* 接口文档工具类
|
* 接口文档工具类
|
||||||
*
|
*
|
||||||
* @author echo
|
* @author echo
|
||||||
|
* @author Charles7c
|
||||||
* @since 2.5.2
|
* @since 2.5.2
|
||||||
*/
|
*/
|
||||||
public class DocUtils {
|
public class ApiDocUtils {
|
||||||
|
|
||||||
private DocUtils() {
|
private ApiDocUtils() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建分组接口文档
|
||||||
|
*
|
||||||
|
* @param group 分组名称
|
||||||
|
* @param pathsToMatch 路径匹配
|
||||||
|
* @return GroupedOpenApi
|
||||||
|
* @since 2.13.0
|
||||||
|
*/
|
||||||
|
public static GroupedOpenApi buildGroupedOpenApi(String group, String... pathsToMatch) {
|
||||||
|
return buildGroupedOpenApi(group, group, pathsToMatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建分组接口文档
|
||||||
|
*
|
||||||
|
* @param group 分组名称
|
||||||
|
* @param displayName 分组显示名称
|
||||||
|
* @param pathsToMatch 路径匹配
|
||||||
|
* @return GroupedOpenApi
|
||||||
|
* @since 2.13.0
|
||||||
|
*/
|
||||||
|
public static GroupedOpenApi buildGroupedOpenApi(String group, String displayName, String... pathsToMatch) {
|
||||||
|
return GroupedOpenApi.builder().group(group).displayName(displayName).pathsToMatch(pathsToMatch).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
@@ -20,7 +20,7 @@ import cn.hutool.core.util.ClassUtil;
|
|||||||
import org.apache.commons.lang3.reflect.TypeUtils;
|
import org.apache.commons.lang3.reflect.TypeUtils;
|
||||||
import org.springdoc.core.parsers.ReturnTypeParser;
|
import org.springdoc.core.parsers.ReturnTypeParser;
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import top.continew.starter.apidoc.util.DocUtils;
|
import top.continew.starter.apidoc.util.ApiDocUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ public class ApiDocGlobalResponseHandler implements ReturnTypeParser {
|
|||||||
// 获取返回类型
|
// 获取返回类型
|
||||||
Type returnType = ReturnTypeParser.super.getReturnType(methodParameter);
|
Type returnType = ReturnTypeParser.super.getReturnType(methodParameter);
|
||||||
// 判断是否具有 RestController 注解
|
// 判断是否具有 RestController 注解
|
||||||
if (!DocUtils.hasRestControllerAnnotation(methodParameter.getContainingClass())) {
|
if (!ApiDocUtils.hasRestControllerAnnotation(methodParameter.getContainingClass())) {
|
||||||
return returnType;
|
return returnType;
|
||||||
}
|
}
|
||||||
// 如果为响应类型,则直接返回
|
// 如果为响应类型,则直接返回
|
||||||
|
Reference in New Issue
Block a user