mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-12 21:49:01 +08:00
♻️ swagger排除路径默认排除监控端点和Spring Boot错误处理
This commit is contained in:
1 parent
d4cca9d47f
commit
c305d9c205
2 files changed
+21
-21
No files matched your search
+8
-5
@@ -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)));
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user