Commit 4d35bcef65162f28904b219f1640987c0b91fe4a
1 parent
18c64458
feat: springdoc success
Showing
6 changed files
with
81 additions
and
37 deletions
yudao-dependencies/pom.xml
| ... | ... | @@ -18,7 +18,8 @@ |
| 18 | 18 | <!-- 统一依赖管理 --> |
| 19 | 19 | <spring.boot.version>2.7.7</spring.boot.version> |
| 20 | 20 | <!-- Web 相关 --> |
| 21 | - <knife4j.version>4.0.0</knife4j.version> | |
| 21 | + <springdoc.version>1.6.14</springdoc.version> | |
| 22 | + <!-- <knife4j.version>4.0.0</knife4j.version>--> | |
| 22 | 23 | <servlet.versoin>2.5</servlet.versoin> |
| 23 | 24 | <!-- DB 相关 --> |
| 24 | 25 | <druid.version>1.2.15</druid.version> |
| ... | ... | @@ -163,10 +164,15 @@ |
| 163 | 164 | <version>${revision}</version> |
| 164 | 165 | </dependency> |
| 165 | 166 | |
| 167 | + <!-- <dependency>--> | |
| 168 | + <!-- <groupId>com.github.xiaoymin</groupId>--> | |
| 169 | + <!-- <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>--> | |
| 170 | + <!-- <version>${knife4j.version}</version>--> | |
| 171 | + <!-- </dependency>--> | |
| 166 | 172 | <dependency> |
| 167 | - <groupId>com.github.xiaoymin</groupId> | |
| 168 | - <artifactId>knife4j-openapi3-spring-boot-starter</artifactId> | |
| 169 | - <version>${knife4j.version}</version> | |
| 173 | + <groupId>org.springdoc</groupId> | |
| 174 | + <artifactId>springdoc-openapi-ui</artifactId> | |
| 175 | + <version>${springdoc.version}</version> | |
| 170 | 176 | </dependency> |
| 171 | 177 | |
| 172 | 178 | <!-- DB 相关 --> |
| ... | ... | @@ -276,16 +282,16 @@ |
| 276 | 282 | <groupId>org.apache.skywalking</groupId> |
| 277 | 283 | <artifactId>apm-toolkit-opentracing</artifactId> |
| 278 | 284 | <version>${skywalking.version}</version> |
| 279 | -<!-- <exclusions>--> | |
| 280 | -<!-- <exclusion>--> | |
| 281 | -<!-- <artifactId>opentracing-api</artifactId>--> | |
| 282 | -<!-- <groupId>io.opentracing</groupId>--> | |
| 283 | -<!-- </exclusion>--> | |
| 284 | -<!-- <exclusion>--> | |
| 285 | -<!-- <artifactId>opentracing-util</artifactId>--> | |
| 286 | -<!-- <groupId>io.opentracing</groupId>--> | |
| 287 | -<!-- </exclusion>--> | |
| 288 | -<!-- </exclusions>--> | |
| 285 | + <!-- <exclusions>--> | |
| 286 | + <!-- <exclusion>--> | |
| 287 | + <!-- <artifactId>opentracing-api</artifactId>--> | |
| 288 | + <!-- <groupId>io.opentracing</groupId>--> | |
| 289 | + <!-- </exclusion>--> | |
| 290 | + <!-- <exclusion>--> | |
| 291 | + <!-- <artifactId>opentracing-util</artifactId>--> | |
| 292 | + <!-- <groupId>io.opentracing</groupId>--> | |
| 293 | + <!-- </exclusion>--> | |
| 294 | + <!-- </exclusions>--> | |
| 289 | 295 | </dependency> |
| 290 | 296 | <dependency> |
| 291 | 297 | <groupId>io.opentracing</groupId> |
| ... | ... | @@ -448,7 +454,7 @@ |
| 448 | 454 | <groupId>org.freemarker</groupId> |
| 449 | 455 | <artifactId>freemarker</artifactId> <!-- 移除 Freemarker 依赖,采用 Velocity 作为模板引擎 --> |
| 450 | 456 | </exclusion> |
| 451 | - <exclusion> | |
| 457 | + <exclusion> | |
| 452 | 458 | <groupId>com.alibaba</groupId> |
| 453 | 459 | <artifactId>fastjson</artifactId> <!-- 最新版screw-core1.0.5依赖fastjson1.2.73存在漏洞,移除。 --> |
| 454 | 460 | </exclusion> | ... | ... |
yudao-framework/yudao-common/pom.xml
| ... | ... | @@ -58,10 +58,16 @@ |
| 58 | 58 | <scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 --> |
| 59 | 59 | </dependency> |
| 60 | 60 | |
| 61 | +<!-- <dependency>--> | |
| 62 | +<!-- <groupId>com.github.xiaoymin</groupId>--> | |
| 63 | +<!-- <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>--> | |
| 64 | +<!-- </dependency>--> | |
| 61 | 65 | <dependency> |
| 62 | - <groupId>com.github.xiaoymin</groupId> | |
| 63 | - <artifactId>knife4j-openapi3-spring-boot-starter</artifactId> | |
| 66 | + <groupId>org.springdoc</groupId> | |
| 67 | + <artifactId>springdoc-openapi-ui</artifactId> | |
| 68 | + <scope>provided</scope> <!-- 设置为 provided,主要是 PageParam 使用到 --> | |
| 64 | 69 | </dependency> |
| 70 | + | |
| 65 | 71 | <!-- 监控相关 --> |
| 66 | 72 | <dependency> |
| 67 | 73 | <groupId>org.apache.skywalking</groupId> | ... | ... |
yudao-framework/yudao-spring-boot-starter-web/pom.xml
| ... | ... | @@ -33,9 +33,13 @@ |
| 33 | 33 | <optional>true</optional> |
| 34 | 34 | </dependency> |
| 35 | 35 | |
| 36 | +<!-- <dependency>--> | |
| 37 | +<!-- <groupId>com.github.xiaoymin</groupId>--> | |
| 38 | +<!-- <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>--> | |
| 39 | +<!-- </dependency>--> | |
| 36 | 40 | <dependency> |
| 37 | - <groupId>com.github.xiaoymin</groupId> | |
| 38 | - <artifactId>knife4j-openapi3-spring-boot-starter</artifactId> | |
| 41 | + <groupId>org.springdoc</groupId> | |
| 42 | + <artifactId>springdoc-openapi-ui</artifactId> | |
| 39 | 43 | </dependency> |
| 40 | 44 | |
| 41 | 45 | <dependency> | ... | ... |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java
| 1 | 1 | package cn.iocoder.yudao.framework.swagger.config; |
| 2 | 2 | |
| 3 | -import io.swagger.v3.oas.models.Components; | |
| 4 | 3 | import io.swagger.v3.oas.models.OpenAPI; |
| 4 | +import io.swagger.v3.oas.models.info.Contact; | |
| 5 | 5 | import io.swagger.v3.oas.models.info.Info; |
| 6 | 6 | import io.swagger.v3.oas.models.info.License; |
| 7 | +import io.swagger.v3.oas.models.media.IntegerSchema; | |
| 8 | +import io.swagger.v3.oas.models.parameters.Parameter; | |
| 9 | +import io.swagger.v3.oas.models.security.SecurityRequirement; | |
| 7 | 10 | import io.swagger.v3.oas.models.security.SecurityScheme; |
| 8 | 11 | import org.springdoc.core.GroupedOpenApi; |
| 9 | 12 | import org.springdoc.core.*; |
| ... | ... | @@ -17,10 +20,11 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties |
| 17 | 20 | import org.springframework.context.annotation.Bean; |
| 18 | 21 | import org.springframework.http.HttpHeaders; |
| 19 | 22 | |
| 20 | -import java.util.Arrays; | |
| 21 | 23 | import java.util.List; |
| 22 | 24 | import java.util.Optional; |
| 23 | 25 | |
| 26 | +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.HEADER_TENANT_ID; | |
| 27 | + | |
| 24 | 28 | /** |
| 25 | 29 | * Swagger3 自动配置类 |
| 26 | 30 | * |
| ... | ... | @@ -40,20 +44,23 @@ public class YudaoSwaggerAutoConfiguration { |
| 40 | 44 | .title(properties.getTitle()) |
| 41 | 45 | .description(properties.getDescription()) |
| 42 | 46 | .version(properties.getVersion()) |
| 47 | + .contact(new Contact().name("xingyuv").url("xingyuv.com").email("xingyu4j@vip.qq.com")) | |
| 43 | 48 | .license(new License().name("MIT").url("https://gitee.com/zhijiantianya/ruoyi-vue-pro/blob/master/LICENSE")); |
| 44 | - //鉴权组件(随便起名的) | |
| 45 | - SecurityScheme securityScheme = new SecurityScheme() | |
| 46 | - .type(SecurityScheme.Type.APIKEY) | |
| 47 | - .scheme("Bearer")//固定写法 | |
| 48 | - .bearerFormat("JWT") | |
| 49 | - .in(SecurityScheme.In.HEADER) | |
| 50 | - .name(HttpHeaders.AUTHORIZATION); | |
| 51 | - Components components = new Components() | |
| 52 | - .addSecuritySchemes("bearer", securityScheme); | |
| 53 | - | |
| 54 | 49 | return new OpenAPI() |
| 55 | 50 | .info(info) |
| 56 | - .components(components); | |
| 51 | + .schemaRequirement(HttpHeaders.AUTHORIZATION, securityScheme()) | |
| 52 | + .addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION)); | |
| 53 | + } | |
| 54 | + | |
| 55 | + private SecurityScheme securityScheme() { | |
| 56 | + SecurityScheme securityScheme = new SecurityScheme(); | |
| 57 | + //类型 | |
| 58 | + securityScheme.setType(SecurityScheme.Type.APIKEY); | |
| 59 | + //请求头的name | |
| 60 | + securityScheme.setName(HttpHeaders.AUTHORIZATION); | |
| 61 | + //token所在未知 | |
| 62 | + securityScheme.setIn(SecurityScheme.In.HEADER); | |
| 63 | + return securityScheme; | |
| 57 | 64 | } |
| 58 | 65 | |
| 59 | 66 | /** |
| ... | ... | @@ -74,6 +81,9 @@ public class YudaoSwaggerAutoConfiguration { |
| 74 | 81 | public GroupedOpenApi appApi() { |
| 75 | 82 | return GroupedOpenApi.builder() |
| 76 | 83 | .group("app") |
| 84 | + .addOperationCustomizer((operation, handlerMethod) -> | |
| 85 | + operation.addParametersItem(globalHeaderParameter()) | |
| 86 | + ) | |
| 77 | 87 | .pathsToMatch("/app-api/**") |
| 78 | 88 | .build(); |
| 79 | 89 | } |
| ... | ... | @@ -82,9 +92,24 @@ public class YudaoSwaggerAutoConfiguration { |
| 82 | 92 | public GroupedOpenApi adminApi() { |
| 83 | 93 | return GroupedOpenApi.builder() |
| 84 | 94 | .group("admin") |
| 95 | + .addOperationCustomizer((operation, handlerMethod) -> | |
| 96 | + operation.addParametersItem(globalHeaderParameter()) | |
| 97 | + ) | |
| 85 | 98 | .pathsToMatch("/admin-api/**") |
| 86 | 99 | .build(); |
| 87 | 100 | } |
| 88 | 101 | |
| 102 | + private static Parameter globalHeaderParameter() { | |
| 103 | + return new Parameter() | |
| 104 | + .name(HEADER_TENANT_ID) | |
| 105 | + .description("租户编号") | |
| 106 | + .in(String.valueOf(SecurityScheme.In.HEADER)) | |
| 107 | + .schema(new IntegerSchema() | |
| 108 | + ._default(1L) | |
| 109 | + .name(HEADER_TENANT_ID) | |
| 110 | + .description("租户编号") | |
| 111 | + ); | |
| 112 | + } | |
| 113 | + | |
| 89 | 114 | } |
| 90 | 115 | ... | ... |
yudao-server/src/main/resources/application.yaml
| ... | ... | @@ -37,14 +37,17 @@ spring: |
| 37 | 37 | springdoc: |
| 38 | 38 | show-actuator: true |
| 39 | 39 | swagger-ui: |
| 40 | + enabled: true | |
| 40 | 41 | path: /swagger-ui |
| 41 | 42 | api-docs: |
| 43 | + enabled: true | |
| 42 | 44 | path: /v3/api-docs |
| 43 | 45 | |
| 44 | -knife4j: | |
| 45 | - enable: true | |
| 46 | - setting: | |
| 47 | - language: zh_cn | |
| 46 | + | |
| 47 | +#knife4j: | |
| 48 | +# enable: true | |
| 49 | +# setting: | |
| 50 | +# language: zh_cn | |
| 48 | 51 | |
| 49 | 52 | # 工作流 Flowable 配置 |
| 50 | 53 | flowable: | ... | ... |
yudao-ui-admin-vue3/src/views/infra/swagger/index.vue