From 372cf5b2fda780f1959b1bb047bb1fb12db174cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=BB=A7=E4=B8=9C?= Date: Sun, 4 Feb 2024 06:42:26 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9swagger=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=A4=9A=E4=B8=AA=E5=8C=85=E6=89=AB=E6=8F=8F=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=A4=BA=E4=BE=8B=EF=BC=9A=20swagger:=20=20?= =?UTF-8?q?=20basePackage:=20"com.company.mes.api;com.company.mes.plan"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 刘继东 --- .../swagger/config/SwaggerAutoConfiguration.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerAutoConfiguration.java b/ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerAutoConfiguration.java index 22dfeeb1..9fe4a452 100644 --- a/ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerAutoConfiguration.java +++ b/ruoyi-common/ruoyi-common-swagger/src/main/java/com/ruoyi/common/swagger/config/SwaggerAutoConfiguration.java @@ -9,6 +9,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; +import springfox.documentation.RequestHandler; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; @@ -59,9 +60,16 @@ public class SwaggerAutoConfiguration List> excludePath = new ArrayList<>(); swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path))); + String[] basePackages = swaggerProperties.getBasePackage().split(";"); + Predicate basePackageP = RequestHandlerSelectors.basePackage(basePackages[0]); + if(basePackages.length>1) { + for (int i = 1; i < basePackages.length; i++) { + basePackageP = basePackageP.or(RequestHandlerSelectors.basePackage(basePackages[i])); + } + } ApiSelectorBuilder builder = new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost()) .apiInfo(apiInfo(swaggerProperties)).select() - .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage())); + .apis(basePackageP); swaggerProperties.getBasePath().forEach(p -> builder.paths(PathSelectors.ant(p))); swaggerProperties.getExcludePath().forEach(p -> builder.paths(PathSelectors.ant(p).negate()));