refactor(web): 移除 SpringDoc 全局响应处理器及相关依赖

- 删除 ApiDocGlobalResponseHandler 类及其相关配置
- 移除对 continew-starter-api-doc 模块的依赖
- 替换为 swagger-annotations-jakarta 依赖
- 清理 GlobalResponseAutoConfiguration 中的条件加载逻辑
- 更新 pom.xml 中的注释说明
This commit is contained in:
吴泽威
2025-10-20 16:06:45 +08:00
parent a60d452aee
commit f1937d3968
3 changed files with 3 additions and 89 deletions

View File

@@ -22,11 +22,10 @@
<artifactId>continew-starter-json-jackson</artifactId>
</dependency>
<!-- API 文档模块 -->
<!-- Swagger 注解 -->
<dependency>
<groupId>top.continew.starter</groupId>
<artifactId>continew-starter-api-doc</artifactId>
<optional>true</optional>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations-jakarta</artifactId>
</dependency>
<!-- Spring Boot Web提供 Spring MVC Web 开发能力,默认内置 Tomcat 服务器) -->

View File

@@ -1,71 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.starter.web.autoconfigure.response;
import cn.hutool.core.util.ClassUtil;
import org.apache.commons.lang3.reflect.TypeUtils;
import org.springdoc.core.parsers.ReturnTypeParser;
import org.springframework.core.MethodParameter;
import top.continew.starter.apidoc.util.ApiDocUtils;
import java.lang.reflect.Type;
/**
* SpringDoc 全局响应处理器
* <p>
* 接口文档全局添加响应格式 {@link com.feiniaojin.gracefulresponse.data.Response}
* </p>
*
* @author echo
* @since 2.5.2
*/
public class ApiDocGlobalResponseHandler implements ReturnTypeParser {
private final GlobalResponseProperties globalResponseProperties;
private final Class<Object> responseClass;
public ApiDocGlobalResponseHandler(GlobalResponseProperties globalResponseProperties) {
this.globalResponseProperties = globalResponseProperties;
this.responseClass = ClassUtil.loadClass(globalResponseProperties.getResponseClassFullName());
}
/**
* 获取返回类型
*
* @param methodParameter 方法参数
* @return {@link Type }
*/
@Override
public Type getReturnType(MethodParameter methodParameter) {
// 获取返回类型
Type returnType = ReturnTypeParser.super.getReturnType(methodParameter);
// 判断是否具有 RestController 注解
if (!ApiDocUtils.hasRestControllerAnnotation(methodParameter.getContainingClass())) {
return returnType;
}
// 如果为响应类型,则直接返回
if (returnType.getTypeName().contains(globalResponseProperties.getResponseClassFullName())) {
return returnType;
}
// 如果是 void类型则返回 R<Void>
if (returnType == void.class || returnType == Void.class) {
return TypeUtils.parameterize(responseClass, Void.class);
}
// 返回 R<T>
return TypeUtils.parameterize(responseClass, returnType);
}
}

View File

@@ -28,8 +28,6 @@ import com.feiniaojin.gracefulresponse.defaults.DefaultResponseStatusFactoryImpl
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springdoc.core.parsers.ReturnTypeParser;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@@ -223,18 +221,6 @@ public class GlobalResponseAutoConfiguration {
return new AdviceSupport();
}
/**
* SpringDoc 全局响应处理器
*
* @return {@link ApiDocGlobalResponseHandler }
*/
@Bean
@ConditionalOnClass(ReturnTypeParser.class)
@ConditionalOnMissingBean
public ApiDocGlobalResponseHandler apiDocGlobalResponseHandler() {
return new ApiDocGlobalResponseHandler(globalResponseProperties);
}
@PostConstruct
public void postConstruct() {
log.debug("[ContiNew Starter] - Auto Configuration 'Web-Global Response' completed initialization.");