diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 8255a86b8..3500c8341 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -18,7 +18,7 @@ 2.7.7 - 3.0.3 + 4.0.0 1.6.8 2.5 @@ -166,7 +166,7 @@ com.github.xiaoymin - knife4j-spring-boot-starter + knife4j-openapi2-spring-boot-starter ${knife4j.version} diff --git a/yudao-framework/yudao-spring-boot-starter-web/pom.xml b/yudao-framework/yudao-spring-boot-starter-web/pom.xml index 7d277790c..05971ca16 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-web/pom.xml @@ -21,6 +21,12 @@ yudao-common + + org.apache.commons + commons-lang3 + provided + + org.springframework.boot @@ -35,7 +41,7 @@ com.github.xiaoymin - knife4j-spring-boot-starter + knife4j-openapi2-spring-boot-starter io.swagger @@ -72,6 +78,7 @@ org.jsoup jsoup + diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java index 240f0f284..5ccbc06c4 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java @@ -9,15 +9,16 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.http.HttpHeaders; import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.ExampleBuilder; +import springfox.documentation.builders.ParameterBuilder; import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestParameterBuilder; +import springfox.documentation.schema.ModelRef; import springfox.documentation.service.*; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spring.web.plugins.Docket; -import springfox.documentation.swagger2.annotations.EnableSwagger2; +import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -30,7 +31,7 @@ import static springfox.documentation.builders.RequestHandlerSelectors.basePacka * @author 芋道源码 */ @AutoConfiguration -@EnableSwagger2 +@EnableSwagger2WebMvc @EnableKnife4j @ConditionalOnClass({Docket.class, ApiInfoBuilder.class}) // 允许使用 swagger.enable=false 禁用 Swagger @@ -59,7 +60,7 @@ public class YudaoSwaggerAutoConfiguration { .securitySchemes(securitySchemes()) .securityContexts(securityContexts()) // ④ 全局参数(多租户 header) - .globalRequestParameters(globalRequestParameters()); + .globalOperationParameters(globalRequestParameters()); } // ========== apiInfo ========== @@ -95,7 +96,7 @@ public class YudaoSwaggerAutoConfiguration { return Collections.singletonList(SecurityContext.builder() .securityReferences(securityReferences()) // 通过 PathSelectors.regex("^(?!auth).*$"),排除包含 "auth" 的接口不需要使用securitySchemes - .operationSelector(o -> o.requestMappingPattern().matches("^(?!auth).*$")) + .forPaths(PathSelectors.regex("^(?!auth).*$")) .build()); } @@ -109,11 +110,17 @@ public class YudaoSwaggerAutoConfiguration { // ========== globalRequestParameters ========== - private static List globalRequestParameters() { - RequestParameterBuilder tenantParameter = new RequestParameterBuilder() - .name(HEADER_TENANT_ID).description("租户编号") - .in(ParameterType.HEADER).example(new ExampleBuilder().value(1L).build()); - return Collections.singletonList(tenantParameter.build()); + private static List globalRequestParameters() { + List tenantParameter = new ArrayList<>(); + tenantParameter.add(new ParameterBuilder() + .name(HEADER_TENANT_ID) + .description("租户编号") + .modelRef(new ModelRef("long")) + .defaultValue("1") + .parameterType("header") + .required(true) + .build()); + return tenantParameter; } } diff --git a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/core/SpringFoxHandlerProviderBeanPostProcessor.java b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/core/SpringFoxHandlerProviderBeanPostProcessor.java index c9d178ac8..e43e2f0f8 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/core/SpringFoxHandlerProviderBeanPostProcessor.java +++ b/yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/core/SpringFoxHandlerProviderBeanPostProcessor.java @@ -5,7 +5,6 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping; -import springfox.documentation.spring.web.plugins.WebFluxRequestHandlerProvider; import springfox.documentation.spring.web.plugins.WebMvcRequestHandlerProvider; import java.util.List; @@ -20,7 +19,7 @@ public class SpringFoxHandlerProviderBeanPostProcessor implements BeanPostProces @Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof WebMvcRequestHandlerProvider || bean instanceof WebFluxRequestHandlerProvider) { + if (bean instanceof WebMvcRequestHandlerProvider) { customizeSpringfoxHandlerMappings(getHandlerMappings(bean)); } return bean;