From f0095a2c312653a6b7afe9f3a142a5142453537f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 3 Jul 2022 17:25:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20YudaoSwaggerAutoConfigurat?= =?UTF-8?q?ion=20=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/ServiceErrorCodeRange.java | 6 +++++- .../config/YudaoSwaggerAutoConfiguration.java | 21 +++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/enums/ServiceErrorCodeRange.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/enums/ServiceErrorCodeRange.java index 0b66179ad7..e3cfc453f1 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/enums/ServiceErrorCodeRange.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/exception/enums/ServiceErrorCodeRange.java @@ -29,6 +29,10 @@ package cn.iocoder.yudao.framework.common.exception.enums; */ public class ServiceErrorCodeRange { - // 模块 system 错误码区间 [1-000-001-000 ~ 1-000-002-000] + // 模块 infra 错误码区间 [1-001-000-000 ~ 1-002-000-000) + // 模块 system 错误码区间 [1-002-000-000 ~ 1-003-000-000) + // 模块 member 错误码区间 [1-004-000-000 ~ 1-005-000-000) + // 模块 pay 错误码区间 [1-007-000-000 ~ 1-008-000-000) + // 模块 bpm 错误码区间 [1-009-000-000 ~ 1-010-000-000) } 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 f2fc32a8c5..b4b29974c6 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 @@ -3,7 +3,6 @@ package cn.iocoder.yudao.framework.swagger.config; import cn.iocoder.yudao.framework.swagger.core.SpringFoxHandlerProviderBeanPostProcessor; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; @@ -45,27 +44,22 @@ public class YudaoSwaggerAutoConfiguration { } @Bean - @ConditionalOnMissingBean - public SwaggerProperties swaggerProperties() { - return new SwaggerProperties(); - } - - @Bean - public Docket createRestApi() { - SwaggerProperties properties = swaggerProperties(); + public Docket createRestApi(SwaggerProperties properties) { // 创建 Docket 对象 return new Docket(DocumentationType.SWAGGER_2) - // 用来创建该 API 的基本信息,展示在文档的页面中(自定义展示的信息) + // ① 用来创建该 API 的基本信息,展示在文档的页面中(自定义展示的信息) .apiInfo(apiInfo(properties)) - // 设置扫描指定 package 包下的 + // ② 设置扫描指定 package 包下的 .select() .apis(basePackage(properties.getBasePackage())) // .apis(basePackage("cn.iocoder.yudao.module.system")) // 可用于 swagger 无法展示时使用 .paths(PathSelectors.any()) .build() + // ③ 安全上下文(认证) .securitySchemes(securitySchemes()) - .globalRequestParameters(globalRequestParameters()) - .securityContexts(securityContexts()); + .securityContexts(securityContexts()) + // ④ 全局参数(多租户 header) + .globalRequestParameters(globalRequestParameters()); } // ========== apiInfo ========== @@ -100,6 +94,7 @@ public class YudaoSwaggerAutoConfiguration { private static List securityContexts() { return Collections.singletonList(SecurityContext.builder() .securityReferences(securityReferences()) + // 通过 PathSelectors.regex("^(?!auth).*$"),排除包含 "auth" 的接口不需要使用securitySchemes .forPaths(PathSelectors.regex("^(?!auth).*$")) .build()); }