From d79f000ce193be002e42ec4e28b729190eb0a81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= Date: Wed, 25 Jul 2018 22:18:38 +0800 Subject: [PATCH] =?UTF-8?q?:recycle:=20=E9=87=8D=E6=9E=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/SwaggerAutoConfiguration.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java b/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java index b9c27ee31..829b8f3b5 100644 --- a/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java +++ b/pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java @@ -17,6 +17,7 @@ package com.pig4cloud.pigx.common.swagger.config; +import cn.hutool.core.collection.CollUtil; import com.google.common.base.Predicate; import com.google.common.base.Predicates; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -37,7 +38,7 @@ import java.util.Collections; import java.util.List; /** - * @author Sywd + * @author lengleng * swagger配置 */ @Configuration @@ -58,29 +59,29 @@ public class SwaggerAutoConfiguration { @Bean public Docket api(SwaggerProperties swaggerProperties) { // base-path处理 - // 当没有配置任何path的时候,解析/** - if (swaggerProperties.getBasePath().isEmpty()) { + if (CollUtil.isEmpty(swaggerProperties.getBasePath())) { swaggerProperties.getBasePath().add(BASE_PATH); } + List> basePath = new ArrayList(); - for (String path : swaggerProperties.getBasePath()) { - basePath.add(PathSelectors.ant(path)); - } + swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path))); + // exclude-path处理 - // 当没有任何配置的时候,解析Spring Boot默认的异常处理路径/error - if(swaggerProperties.getExcludePath().isEmpty()){ + if (CollUtil.isEmpty(swaggerProperties.getExcludePath())) { swaggerProperties.getExcludePath().add(DEFAULT_EXCLUDE_PATH); } + List> excludePath = new ArrayList<>(); - for (String path : swaggerProperties.getExcludePath()) { - excludePath.add(PathSelectors.ant(path)); - } - return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() - .apis(RequestHandlerSelectors.any()).paths(Predicates.and( - Predicates.not(Predicates.or(excludePath)), - Predicates.or(basePath))) - .build().securitySchemes(Collections.singletonList(securitySchema())) - .securityContexts(Collections.singletonList(securityContext())).pathMapping("/"); + swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path))); + + return new Docket(DocumentationType.SWAGGER_2) + .apiInfo(apiInfo()).select() + .apis(RequestHandlerSelectors.any()) + .paths(Predicates.and(Predicates.not(Predicates.or(excludePath)), Predicates.or(basePath))) + .build() + .securitySchemes(Collections.singletonList(securitySchema())) + .securityContexts(Collections.singletonList(securityContext())) + .pathMapping("/"); } private SecurityContext securityContext() {