Bladeren bron

:recycle: swagger排除路径默认排除监控端点和Spring Boot错误处理

lishangbu 7 jaren geleden
bovenliggende
commit
c305d9c205

+ 8 - 5
pigx-common/pigx-common-swagger/src/main/java/com/pig4cloud/pigx/common/swagger/config/SwaggerAutoConfiguration.java

@@ -17,7 +17,6 @@
 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;
@@ -34,6 +33,7 @@ import springfox.documentation.spring.web.plugins.Docket;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -46,7 +46,10 @@ import java.util.List;
 @EnableAutoConfiguration
 public class SwaggerAutoConfiguration {
 
-	private static final String DEFAULT_EXCLUDE_PATH = "/error";
+	/**
+	 * 	默认的排除路径,排除Spring Boot默认的错误处理路径和端点
+	 */
+	private static final List<String> DEFAULT_EXCLUDE_PATH = Arrays.asList("/error","/actuator/**");
 	private static final String BASE_PATH = "/**";
 
 	@Bean
@@ -58,7 +61,7 @@ public class SwaggerAutoConfiguration {
 	@Bean
 	public Docket api(SwaggerProperties swaggerProperties) {
 		// base-path处理
-		if (CollUtil.isEmpty(swaggerProperties.getBasePath())) {
+		if (swaggerProperties.getBasePath().isEmpty()) {
 			swaggerProperties.getBasePath().add(BASE_PATH);
 		}
 		//noinspection unchecked
@@ -66,8 +69,8 @@ public class SwaggerAutoConfiguration {
 		swaggerProperties.getBasePath().forEach(path -> basePath.add(PathSelectors.ant(path)));
 
 		// exclude-path处理
-		if (CollUtil.isEmpty(swaggerProperties.getExcludePath())) {
-			swaggerProperties.getExcludePath().add(DEFAULT_EXCLUDE_PATH);
+		if (swaggerProperties.getExcludePath().isEmpty()) {
+			swaggerProperties.getExcludePath().addAll(DEFAULT_EXCLUDE_PATH);
 		}
 		List<Predicate<String>> excludePath = new ArrayList<>();
 		swaggerProperties.getExcludePath().forEach(path -> excludePath.add(PathSelectors.ant(path)));

+ 13 - 16
pigx-config/src/main/resources/config/application-dev.yml

@@ -72,25 +72,22 @@ mybatis-plus:
 
 #swagger公共信息
 swagger:
-  title: 'PigX Swagger API'
-  description: '全宇宙最牛逼的Spring Cloud微服务开发脚手架'
-  version: '1.4.0'
-  license: 'Powered By PigX'
-  licenseUrl: 'https://gitee.com/log4j/pig/wikis'
-  terms-of-service-url: 'https://gitee.wang/pig/pigx'
-  exclude-path:
-    - /actuator/**
-    - /error
+  title: PigX Swagger API
+  description: 全宇宙最牛逼的Spring Cloud微服务开发脚手架
+  version: 1.6.2
+  license: Powered By PigX
+  licenseUrl: https://pig4cloud.com/
+  terms-of-service-url: https://pig4cloud.com/
   contact:
-    name: '冷冷'
-    email: 'wangiegie@gmail.com'
-    url: 'https://gitee.wang/pig/pigx'
+    name: 冷冷
+    email: wangiegie@gmail.com
+    url: https://pig4cloud.com/about.html
   authorization:
-    name: 'pigX OAuth'
-    auth-regex: '^.*$'
+    name: pigX OAuth
+    auth-regex: ^.*$
     authorization-scope-list:
-      - scope: 'server'
-        description: 'server all'
+      - scope: server
+        description: server all
     token-url-list:
       - ${security.auth.server}/token