From 59c6963f7c65bfced467acea9cd95611c084112b Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 4 Mar 2023 15:05:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20Swagger=20=E7=9A=84?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E4=BE=9D=E8=B5=96=EF=BC=8C=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 47 +++++++++++++++---- yudao-framework/yudao-common/pom.xml | 6 +-- .../yudao-spring-boot-starter-web/pom.xml | 21 +++++---- .../bpm/config/BpmSecurityConfiguration.java | 28 ----------- .../config/SecurityConfiguration.java | 6 +-- .../src/main/resources/application.yaml | 15 ++++++ .../yudao-module-infra-api/pom.xml | 5 +- .../module/infra/InfraServerApplication.java | 2 - .../config/SecurityConfiguration.java | 6 +-- .../src/main/resources/application.yaml | 15 ++++++ .../config/SecurityConfiguration.java | 6 +-- .../src/main/resources/application.yaml | 15 ++++++ .../yudao-module-system-api/pom.xml | 5 +- .../module/system/api/user/AdminUserApi.java | 8 ++-- .../system/api/user/AdminUserApiImpl.java | 6 +-- .../config/SecurityConfiguration.java | 6 +-- .../src/main/resources/application.yaml | 15 ++++++ 17 files changed, 135 insertions(+), 77 deletions(-) delete mode 100644 yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/config/BpmSecurityConfiguration.java diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index a8e4ec365..0846e47c3 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -16,14 +16,14 @@ 1.6.6-snapshot - 2.7.7 + 2.7.8 2021.0.5 2021.0.4.0 - 4.0.0 - 1.6.8 2.5 + 2.2.8 1.6.14 + 4.0.0 1.2.15 3.5.3.1 @@ -199,15 +199,39 @@ - org.springdoc - springdoc-openapi-webflux-ui - 1.6.14 + io.swagger.core.v3 + swagger-annotations + ${swagger.version} - - org.springdoc + io.swagger.core.v3 + swagger-models + ${swagger.version} + + + org.springdoc + springdoc-openapi-common + ${springdoc.version} + + + org.springdoc springdoc-openapi-webmvc-core - 1.6.14 + ${springdoc.version} + + + org.springdoc + springdoc-openapi-webflux-core + ${springdoc.version} + + + org.springdoc + springdoc-openapi-ui + ${springdoc.version} + + + com.github.xiaoymin + knife4j-openapi3-spring-boot-starter + ${knife4j.version} @@ -216,6 +240,11 @@ yudao-spring-boot-starter-mybatis ${revision} + + org.springdoc + springdoc-openapi-webflux-ui + ${springdoc.version} + com.alibaba diff --git a/yudao-framework/yudao-common/pom.xml b/yudao-framework/yudao-common/pom.xml index 06a793ec8..7fb4c0ac2 100644 --- a/yudao-framework/yudao-common/pom.xml +++ b/yudao-framework/yudao-common/pom.xml @@ -59,9 +59,9 @@ - org.springdoc - springdoc-openapi-webmvc-core - compile + io.swagger.core.v3 + swagger-annotations + provided diff --git a/yudao-framework/yudao-spring-boot-starter-web/pom.xml b/yudao-framework/yudao-spring-boot-starter-web/pom.xml index d397a66c1..0ee38a2b3 100644 --- a/yudao-framework/yudao-spring-boot-starter-web/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-web/pom.xml @@ -21,9 +21,11 @@ yudao-common + - org.springdoc - springdoc-openapi-webmvc-core + org.springframework.boot + spring-boot-configuration-processor + true @@ -31,12 +33,6 @@ org.springframework.boot spring-boot-starter-web - - - org.springframework.boot - spring-boot-configuration-processor - true - org.springframework.boot @@ -49,6 +45,15 @@ provided + + com.github.xiaoymin + knife4j-openapi3-spring-boot-starter + + + org.springdoc + springdoc-openapi-ui + + cn.iocoder.cloud diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/config/BpmSecurityConfiguration.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/config/BpmSecurityConfiguration.java deleted file mode 100644 index 163ecc1db..000000000 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/bpm/config/BpmSecurityConfiguration.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.iocoder.yudao.module.bpm.framework.bpm.config; - -import cn.iocoder.yudao.framework.security.config.AuthorizeRequestsCustomizer; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer; - -/** - * @author kemengkai - * @create 2022-05-07 08:15 - */ -@Configuration(proxyBeanMethods = false, value = "bpmSecurityConfiguration") -public class BpmSecurityConfiguration { - - @Bean("bpmAuthorizeRequestsCustomizer") - public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { - return new AuthorizeRequestsCustomizer() { - - @Override - public void customize(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry) { - // 任务回退接口 - registry.antMatchers(buildAdminApi("/bpm/task/back")).permitAll(); - } - - }; - } -} diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/security/config/SecurityConfiguration.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/security/config/SecurityConfiguration.java index 3d4c643b9..b99be6373 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/security/config/SecurityConfiguration.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/security/config/SecurityConfiguration.java @@ -21,10 +21,8 @@ public class SecurityConfiguration { public void customize(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry) { // TODO 芋艿:这个每个项目都需要重复配置,得捉摸有没通用的方案 // Swagger 接口文档 - registry.antMatchers("/swagger-ui.html").anonymous() - .antMatchers("/swagger-resources/**").anonymous() - .antMatchers("/webjars/**").anonymous() - .antMatchers("/*/api-docs").anonymous(); + registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据 + .antMatchers("/swagger-ui.html").permitAll(); // Swagger UI // Druid 监控 registry.antMatchers("/druid/**").anonymous(); // Spring Boot Actuator 的安全配置 diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application.yaml b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application.yaml index a32bbab3d..b876259f5 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application.yaml +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/resources/application.yaml @@ -27,6 +27,21 @@ spring: redis: time-to-live: 1h # 设置过期时间为 1 小时 +--- #################### 接口文档配置 #################### + +springdoc: + api-docs: + enabled: true # 1. 是否开启 Swagger 接文档的元数据 + path: /v3/api-docs + swagger-ui: + enabled: true # 2.1 是否开启 Swagger 文档的官方 UI 界面 + path: /swagger-ui.html + +knife4j: + enable: true # 2.2 是否开启 Swagger 文档的 Knife4j UI 界面 + setting: + language: zh_cn + # 工作流 Flowable 配置 flowable: # 1. false: 默认值,Flowable 启动时,对比数据库表中保存的版本,如果不匹配。将抛出异常 diff --git a/yudao-module-infra/yudao-module-infra-api/pom.xml b/yudao-module-infra/yudao-module-infra-api/pom.xml index 2765503d8..fcaf87a02 100644 --- a/yudao-module-infra/yudao-module-infra-api/pom.xml +++ b/yudao-module-infra/yudao-module-infra-api/pom.xml @@ -24,8 +24,9 @@ - org.springdoc - springdoc-openapi-webmvc-core + io.swagger.core.v3 + swagger-annotations + provided diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/InfraServerApplication.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/InfraServerApplication.java index 17a1a4950..fe3eee495 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/InfraServerApplication.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/InfraServerApplication.java @@ -1,7 +1,5 @@ package cn.iocoder.yudao.module.infra; -import io.swagger.v3.oas.annotations.OpenAPIDefinition; -import io.swagger.v3.oas.annotations.info.Info; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java index 01ee55124..c5b947e11 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/security/config/SecurityConfiguration.java @@ -24,10 +24,8 @@ public class SecurityConfiguration { @Override public void customize(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry) { // Swagger 接口文档 - registry.antMatchers("/swagger-ui.html").anonymous() - .antMatchers("/swagger-resources/**").anonymous() - .antMatchers("/webjars/**").anonymous() - .antMatchers("/*/api-docs").anonymous(); + registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据 + .antMatchers("/swagger-ui.html").permitAll(); // Swagger UI // Spring Boot Actuator 的安全配置 registry.antMatchers("/actuator").anonymous() .antMatchers("/actuator/**").anonymous(); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml index a996095e7..3cd28d3f3 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application.yaml @@ -27,6 +27,21 @@ spring: redis: time-to-live: 1h # 设置过期时间为 1 小时 +--- #################### 接口文档配置 #################### + +springdoc: + api-docs: + enabled: true # 1. 是否开启 Swagger 接文档的元数据 + path: /v3/api-docs + swagger-ui: + enabled: true # 2.1 是否开启 Swagger 文档的官方 UI 界面 + path: /swagger-ui.html + +knife4j: + enable: true # 2.2 是否开启 Swagger 文档的 Knife4j UI 界面 + setting: + language: zh_cn + # MyBatis Plus 的配置项 mybatis-plus: configuration: diff --git a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java index e481133b8..05b009661 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java +++ b/yudao-module-report/yudao-module-report-biz/src/main/java/cn/iocoder/yudao/module/report/framework/security/config/SecurityConfiguration.java @@ -19,10 +19,8 @@ public class SecurityConfiguration { @Override public void customize(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry) { // Swagger 接口文档 - registry.antMatchers("/swagger-ui.html").anonymous() - .antMatchers("/swagger-resources/**").anonymous() - .antMatchers("/webjars/**").anonymous() - .antMatchers("/*/api-docs").anonymous(); + registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据 + .antMatchers("/swagger-ui.html").permitAll(); // Swagger UI // Spring Boot Actuator 的安全配置 registry.antMatchers("/actuator").anonymous() .antMatchers("/actuator/**").anonymous(); diff --git a/yudao-module-report/yudao-module-report-biz/src/main/resources/application.yaml b/yudao-module-report/yudao-module-report-biz/src/main/resources/application.yaml index ff1e97b31..5b1e86b0e 100644 --- a/yudao-module-report/yudao-module-report-biz/src/main/resources/application.yaml +++ b/yudao-module-report/yudao-module-report-biz/src/main/resources/application.yaml @@ -27,6 +27,21 @@ spring: redis: time-to-live: 1h # 设置过期时间为 1 小时 +--- #################### 接口文档配置 #################### + +springdoc: + api-docs: + enabled: true # 1. 是否开启 Swagger 接文档的元数据 + path: /v3/api-docs + swagger-ui: + enabled: true # 2.1 是否开启 Swagger 文档的官方 UI 界面 + path: /swagger-ui.html + +knife4j: + enable: true # 2.2 是否开启 Swagger 文档的 Knife4j UI 界面 + setting: + language: zh_cn + # MyBatis Plus 的配置项 mybatis-plus: configuration: diff --git a/yudao-module-system/yudao-module-system-api/pom.xml b/yudao-module-system/yudao-module-system-api/pom.xml index 1dab1e188..dcd4132ed 100644 --- a/yudao-module-system/yudao-module-system-api/pom.xml +++ b/yudao-module-system/yudao-module-system-api/pom.xml @@ -24,8 +24,9 @@ - org.springdoc - springdoc-openapi-webmvc-core + io.swagger.core.v3 + swagger-annotations + provided diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApi.java index 1f57c3929..f84773312 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApi.java @@ -35,12 +35,12 @@ public interface AdminUserApi { @GetMapping(PREFIX + "/list-by-dept-id") @Operation(summary = "获得指定部门的用户数组") @Parameter(name = "deptIds", description = "部门编号数组", example = "1,2", required = true) - CommonResult> getUsersByDeptIds(@RequestParam("deptIds") Collection deptIds); + CommonResult> getUserListByDeptIds(@RequestParam("deptIds") Collection deptIds); @GetMapping(PREFIX + "/list-by-post-id") @Operation(summary = "获得指定岗位的用户数组") @Parameter(name = "postIds", description = "岗位编号数组", example = "2,3", required = true) - CommonResult> getUsersByPostIds(@RequestParam("postIds") Collection postIds); + CommonResult> getUserListByPostIds(@RequestParam("postIds") Collection postIds); /** * 获得用户 Map @@ -55,6 +55,6 @@ public interface AdminUserApi { @GetMapping(PREFIX + "/valid") @Operation(summary = "校验用户们是否有效") @Parameter(name = "ids", description = "用户编号数组", example = "3,5", required = true) - CommonResult validUsers(@RequestParam("ids") Set ids); + CommonResult validUserList(@RequestParam("ids") Set ids); -} \ No newline at end of file +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java index 3745263c8..5691c682d 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/user/AdminUserApiImpl.java @@ -39,19 +39,19 @@ public class AdminUserApiImpl implements AdminUserApi { } @Override - public CommonResult> getUsersByDeptIds(Collection deptIds) { + public CommonResult> getUserListByDeptIds(Collection deptIds) { List users = userService.getUserListByDeptIds(deptIds); return success(UserConvert.INSTANCE.convertList4(users)); } @Override - public CommonResult> getUsersByPostIds(Collection postIds) { + public CommonResult> getUserListByPostIds(Collection postIds) { List users = userService.getUserListByPostIds(postIds); return success(UserConvert.INSTANCE.convertList4(users)); } @Override - public CommonResult validUsers(Set ids) { + public CommonResult validUserList(Set ids) { userService.validateUserList(ids); return success(true); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java index a3b01afc1..3f0a7ac31 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/security/config/SecurityConfiguration.java @@ -21,10 +21,8 @@ public class SecurityConfiguration { public void customize(ExpressionUrlAuthorizationConfigurer.ExpressionInterceptUrlRegistry registry) { // TODO 芋艿:这个每个项目都需要重复配置,得捉摸有没通用的方案 // Swagger 接口文档 - registry.antMatchers("/swagger-ui.html").anonymous() - .antMatchers("/swagger-resources/**").anonymous() - .antMatchers("/webjars/**").anonymous() - .antMatchers("/*/api-docs").anonymous(); + registry.antMatchers("/v3/api-docs/**").permitAll() // 元数据 + .antMatchers("/swagger-ui.html").permitAll(); // Swagger UI // Druid 监控 registry.antMatchers("/druid/**").anonymous(); // Spring Boot Actuator 的安全配置 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml index 647ab0c17..cac51c174 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml +++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml @@ -27,6 +27,21 @@ spring: redis: time-to-live: 1h # 设置过期时间为 1 小时 +--- #################### 接口文档配置 #################### + +springdoc: + api-docs: + enabled: true # 1. 是否开启 Swagger 接文档的元数据 + path: /v3/api-docs + swagger-ui: + enabled: true # 2.1 是否开启 Swagger 文档的官方 UI 界面 + path: /swagger-ui.html + +knife4j: + enable: true # 2.2 是否开启 Swagger 文档的 Knife4j UI 界面 + setting: + language: zh_cn + # MyBatis Plus 的配置项 mybatis-plus: configuration: