mirror of https://github.com/jeecgboot/jeecg-boot
swagger上选择的接口和实际接口不对应 #8705
parent
67d9865861
commit
6b7542620b
|
@ -264,12 +264,12 @@
|
|||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.xingfudeshi</groupId>
|
||||
<!-- <dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
|
||||
<version>${knife4j-spring-boot-starter.version}</version>
|
||||
</dependency>
|
||||
<!-- knife4j 升级springboot3.4.5报错
|
||||
</dependency>-->
|
||||
<!-- knife4j 升级springboot3.4.5报错 -->
|
||||
<dependency>
|
||||
<groupId>com.github.xiaoymin</groupId>
|
||||
<artifactId>knife4j-openapi3-ui</artifactId>
|
||||
|
@ -279,7 +279,7 @@
|
|||
<groupId>org.springdoc</groupId>
|
||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency> -->
|
||||
</dependency>
|
||||
|
||||
<!-- 代码生成器 -->
|
||||
<!-- 如下载失败,请参考此文档 https://help.jeecg.com/java/setup/maven.html -->
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<aviator.version>5.2.6</aviator.version>
|
||||
<pegdown.version>1.6.0</pegdown.version>
|
||||
<commonmark.version>0.17.0</commonmark.version>
|
||||
<knife4j-spring-boot-starter.version>4.6.0</knife4j-spring-boot-starter.version>
|
||||
<knife4j-spring-boot-starter.version>4.5.0</knife4j-spring-boot-starter.version>
|
||||
<!-- 数据库驱动 -->
|
||||
<postgresql.version>42.2.25</postgresql.version>
|
||||
<ojdbc6.version>11.2.0.3</ojdbc6.version>
|
||||
|
|
Loading…
Reference in New Issue