From 6b7542620b44009e4476a35d27b0908177379e6b Mon Sep 17 00:00:00 2001
From: JEECG <445654970@qq.com>
Date: Wed, 13 Aug 2025 16:44:16 +0800
Subject: [PATCH] =?UTF-8?q?swagger=E4=B8=8A=E9=80=89=E6=8B=A9=E7=9A=84?=
=?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=92=8C=E5=AE=9E=E9=99=85=E6=8E=A5=E5=8F=A3?=
=?UTF-8?q?=E4=B8=8D=E5=AF=B9=E5=BA=94=20#8705?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
jeecg-boot/jeecg-boot-base-core/pom.xml | 10 +++---
.../java/org/jeecg/config/Swagger3Config.java | 31 ++++++-------------
jeecg-boot/pom.xml | 2 +-
3 files changed, 16 insertions(+), 27 deletions(-)
diff --git a/jeecg-boot/jeecg-boot-base-core/pom.xml b/jeecg-boot/jeecg-boot-base-core/pom.xml
index c667353c8..d6f8b9bf0 100644
--- a/jeecg-boot/jeecg-boot-base-core/pom.xml
+++ b/jeecg-boot/jeecg-boot-base-core/pom.xml
@@ -264,12 +264,12 @@
-
- com.github.xingfudeshi
+
+
com.github.xiaoymin
knife4j-openapi3-ui
@@ -279,7 +279,7 @@
org.springdoc
springdoc-openapi-starter-webmvc-ui
2.7.0
- -->
+
diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger3Config.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger3Config.java
index 1878b5827..0700b463a 100644
--- a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger3Config.java
+++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/Swagger3Config.java
@@ -10,11 +10,12 @@ import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.constant.CommonConstant;
-import org.springdoc.core.customizers.GlobalOpenApiCustomizer;
+import org.springdoc.core.customizers.OperationCustomizer;
import org.springdoc.core.filters.GlobalOpenApiMethodFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
+import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@@ -61,29 +62,17 @@ public class Swagger3Config implements WebMvcConfigurer {
}
@Bean
- public GlobalOpenApiCustomizer globalOpenApiCustomizer() {
- return openApi -> {
- // 全局添加鉴权参数
- if (openApi.getPaths() != null) {
- openApi.getPaths().forEach((path, pathItem) -> {
- //log.info("path: {}", path);
- // 检查当前路径是否在排除列表中
- boolean isExcluded = excludedPaths.stream().anyMatch(
- excludedPath -> excludedPath.equals(path) || (excludedPath.endsWith("**") && path.startsWith(excludedPath.substring(0, excludedPath.length() - 2)))
- );
-
- if (!isExcluded) {
- //log.info(" 接口添加默认X_ACCESS_TOKEN: {}", path);
- // 接口添加鉴权参数
- pathItem.readOperations().forEach(operation ->
- operation.addSecurityItem(new SecurityRequirement().addList(CommonConstant.X_ACCESS_TOKEN))
- );
- }
- });
+ public OperationCustomizer operationCustomizer() {
+ return (operation, handlerMethod) -> {
+ String path = handlerMethod.getBeanType().getAnnotation(RequestMapping.class).value()[0];
+ if (!excludedPaths.contains(path)) {
+ operation.addSecurityItem(new SecurityRequirement().addList(CommonConstant.X_ACCESS_TOKEN));
}
+ return operation;
};
}
-
+
+
@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI()
diff --git a/jeecg-boot/pom.xml b/jeecg-boot/pom.xml
index 92029babc..f466c651d 100644
--- a/jeecg-boot/pom.xml
+++ b/jeecg-boot/pom.xml
@@ -43,7 +43,7 @@
5.2.6
1.6.0
0.17.0
- 4.6.0
+ 4.5.0
42.2.25
11.2.0.3