mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-10-21 20:57:15 +08:00
refactor(web): 移除 SpringDoc 全局响应处理器及相关依赖
- 删除 ApiDocGlobalResponseHandler 类及其相关配置 - 移除对 continew-starter-api-doc 模块的依赖 - 替换为 swagger-annotations-jakarta 依赖 - 清理 GlobalResponseAutoConfiguration 中的条件加载逻辑 - 更新 pom.xml 中的注释说明
This commit is contained in:
@@ -22,11 +22,10 @@
|
|||||||
<artifactId>continew-starter-json-jackson</artifactId>
|
<artifactId>continew-starter-json-jackson</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- API 文档模块 -->
|
<!-- Swagger 注解 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>top.continew.starter</groupId>
|
<groupId>io.swagger.core.v3</groupId>
|
||||||
<artifactId>continew-starter-api-doc</artifactId>
|
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring Boot Web(提供 Spring MVC Web 开发能力,默认内置 Tomcat 服务器) -->
|
<!-- Spring Boot Web(提供 Spring MVC Web 开发能力,默认内置 Tomcat 服务器) -->
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -28,8 +28,6 @@ import com.feiniaojin.gracefulresponse.defaults.DefaultResponseStatusFactoryImpl
|
|||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.ConditionalOnMissingBean;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
@@ -223,18 +221,6 @@ public class GlobalResponseAutoConfiguration {
|
|||||||
return new AdviceSupport();
|
return new AdviceSupport();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* SpringDoc 全局响应处理器
|
|
||||||
*
|
|
||||||
* @return {@link ApiDocGlobalResponseHandler }
|
|
||||||
*/
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnClass(ReturnTypeParser.class)
|
|
||||||
@ConditionalOnMissingBean
|
|
||||||
public ApiDocGlobalResponseHandler apiDocGlobalResponseHandler() {
|
|
||||||
return new ApiDocGlobalResponseHandler(globalResponseProperties);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void postConstruct() {
|
public void postConstruct() {
|
||||||
log.debug("[ContiNew Starter] - Auto Configuration 'Web-Global Response' completed initialization.");
|
log.debug("[ContiNew Starter] - Auto Configuration 'Web-Global Response' completed initialization.");
|
||||||
|
Reference in New Issue
Block a user