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,7 +18,8 @@ | ||
| 18 | <!-- 统一依赖管理 --> | 18 | <!-- 统一依赖管理 --> |
| 19 | <spring.boot.version>2.7.7</spring.boot.version> | 19 | <spring.boot.version>2.7.7</spring.boot.version> |
| 20 | <!-- Web 相关 --> | 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 | <servlet.versoin>2.5</servlet.versoin> | 23 | <servlet.versoin>2.5</servlet.versoin> |
| 23 | <!-- DB 相关 --> | 24 | <!-- DB 相关 --> |
| 24 | <druid.version>1.2.15</druid.version> | 25 | <druid.version>1.2.15</druid.version> |
| @@ -163,10 +164,15 @@ | @@ -163,10 +164,15 @@ | ||
| 163 | <version>${revision}</version> | 164 | <version>${revision}</version> |
| 164 | </dependency> | 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 | <dependency> | 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 | </dependency> | 176 | </dependency> |
| 171 | 177 | ||
| 172 | <!-- DB 相关 --> | 178 | <!-- DB 相关 --> |
| @@ -276,16 +282,16 @@ | @@ -276,16 +282,16 @@ | ||
| 276 | <groupId>org.apache.skywalking</groupId> | 282 | <groupId>org.apache.skywalking</groupId> |
| 277 | <artifactId>apm-toolkit-opentracing</artifactId> | 283 | <artifactId>apm-toolkit-opentracing</artifactId> |
| 278 | <version>${skywalking.version}</version> | 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 | </dependency> | 295 | </dependency> |
| 290 | <dependency> | 296 | <dependency> |
| 291 | <groupId>io.opentracing</groupId> | 297 | <groupId>io.opentracing</groupId> |
| @@ -448,7 +454,7 @@ | @@ -448,7 +454,7 @@ | ||
| 448 | <groupId>org.freemarker</groupId> | 454 | <groupId>org.freemarker</groupId> |
| 449 | <artifactId>freemarker</artifactId> <!-- 移除 Freemarker 依赖,采用 Velocity 作为模板引擎 --> | 455 | <artifactId>freemarker</artifactId> <!-- 移除 Freemarker 依赖,采用 Velocity 作为模板引擎 --> |
| 450 | </exclusion> | 456 | </exclusion> |
| 451 | - <exclusion> | 457 | + <exclusion> |
| 452 | <groupId>com.alibaba</groupId> | 458 | <groupId>com.alibaba</groupId> |
| 453 | <artifactId>fastjson</artifactId> <!-- 最新版screw-core1.0.5依赖fastjson1.2.73存在漏洞,移除。 --> | 459 | <artifactId>fastjson</artifactId> <!-- 最新版screw-core1.0.5依赖fastjson1.2.73存在漏洞,移除。 --> |
| 454 | </exclusion> | 460 | </exclusion> |
yudao-framework/yudao-common/pom.xml
| @@ -58,10 +58,16 @@ | @@ -58,10 +58,16 @@ | ||
| 58 | <scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 --> | 58 | <scope>provided</scope> <!-- 设置为 provided,只有工具类需要使用到 --> |
| 59 | </dependency> | 59 | </dependency> |
| 60 | 60 | ||
| 61 | +<!-- <dependency>--> | ||
| 62 | +<!-- <groupId>com.github.xiaoymin</groupId>--> | ||
| 63 | +<!-- <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>--> | ||
| 64 | +<!-- </dependency>--> | ||
| 61 | <dependency> | 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 | </dependency> | 69 | </dependency> |
| 70 | + | ||
| 65 | <!-- 监控相关 --> | 71 | <!-- 监控相关 --> |
| 66 | <dependency> | 72 | <dependency> |
| 67 | <groupId>org.apache.skywalking</groupId> | 73 | <groupId>org.apache.skywalking</groupId> |
yudao-framework/yudao-spring-boot-starter-web/pom.xml
| @@ -33,9 +33,13 @@ | @@ -33,9 +33,13 @@ | ||
| 33 | <optional>true</optional> | 33 | <optional>true</optional> |
| 34 | </dependency> | 34 | </dependency> |
| 35 | 35 | ||
| 36 | +<!-- <dependency>--> | ||
| 37 | +<!-- <groupId>com.github.xiaoymin</groupId>--> | ||
| 38 | +<!-- <artifactId>knife4j-openapi3-spring-boot-starter</artifactId>--> | ||
| 39 | +<!-- </dependency>--> | ||
| 36 | <dependency> | 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 | </dependency> | 43 | </dependency> |
| 40 | 44 | ||
| 41 | <dependency> | 45 | <dependency> |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/swagger/config/YudaoSwaggerAutoConfiguration.java
| 1 | package cn.iocoder.yudao.framework.swagger.config; | 1 | package cn.iocoder.yudao.framework.swagger.config; |
| 2 | 2 | ||
| 3 | -import io.swagger.v3.oas.models.Components; | ||
| 4 | import io.swagger.v3.oas.models.OpenAPI; | 3 | import io.swagger.v3.oas.models.OpenAPI; |
| 4 | +import io.swagger.v3.oas.models.info.Contact; | ||
| 5 | import io.swagger.v3.oas.models.info.Info; | 5 | import io.swagger.v3.oas.models.info.Info; |
| 6 | import io.swagger.v3.oas.models.info.License; | 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 | import io.swagger.v3.oas.models.security.SecurityScheme; | 10 | import io.swagger.v3.oas.models.security.SecurityScheme; |
| 8 | import org.springdoc.core.GroupedOpenApi; | 11 | import org.springdoc.core.GroupedOpenApi; |
| 9 | import org.springdoc.core.*; | 12 | import org.springdoc.core.*; |
| @@ -17,10 +20,11 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties | @@ -17,10 +20,11 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
| 17 | import org.springframework.context.annotation.Bean; | 20 | import org.springframework.context.annotation.Bean; |
| 18 | import org.springframework.http.HttpHeaders; | 21 | import org.springframework.http.HttpHeaders; |
| 19 | 22 | ||
| 20 | -import java.util.Arrays; | ||
| 21 | import java.util.List; | 23 | import java.util.List; |
| 22 | import java.util.Optional; | 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 | * Swagger3 自动配置类 | 29 | * Swagger3 自动配置类 |
| 26 | * | 30 | * |
| @@ -40,20 +44,23 @@ public class YudaoSwaggerAutoConfiguration { | @@ -40,20 +44,23 @@ public class YudaoSwaggerAutoConfiguration { | ||
| 40 | .title(properties.getTitle()) | 44 | .title(properties.getTitle()) |
| 41 | .description(properties.getDescription()) | 45 | .description(properties.getDescription()) |
| 42 | .version(properties.getVersion()) | 46 | .version(properties.getVersion()) |
| 47 | + .contact(new Contact().name("xingyuv").url("xingyuv.com").email("xingyu4j@vip.qq.com")) | ||
| 43 | .license(new License().name("MIT").url("https://gitee.com/zhijiantianya/ruoyi-vue-pro/blob/master/LICENSE")); | 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 | return new OpenAPI() | 49 | return new OpenAPI() |
| 55 | .info(info) | 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,6 +81,9 @@ public class YudaoSwaggerAutoConfiguration { | ||
| 74 | public GroupedOpenApi appApi() { | 81 | public GroupedOpenApi appApi() { |
| 75 | return GroupedOpenApi.builder() | 82 | return GroupedOpenApi.builder() |
| 76 | .group("app") | 83 | .group("app") |
| 84 | + .addOperationCustomizer((operation, handlerMethod) -> | ||
| 85 | + operation.addParametersItem(globalHeaderParameter()) | ||
| 86 | + ) | ||
| 77 | .pathsToMatch("/app-api/**") | 87 | .pathsToMatch("/app-api/**") |
| 78 | .build(); | 88 | .build(); |
| 79 | } | 89 | } |
| @@ -82,9 +92,24 @@ public class YudaoSwaggerAutoConfiguration { | @@ -82,9 +92,24 @@ public class YudaoSwaggerAutoConfiguration { | ||
| 82 | public GroupedOpenApi adminApi() { | 92 | public GroupedOpenApi adminApi() { |
| 83 | return GroupedOpenApi.builder() | 93 | return GroupedOpenApi.builder() |
| 84 | .group("admin") | 94 | .group("admin") |
| 95 | + .addOperationCustomizer((operation, handlerMethod) -> | ||
| 96 | + operation.addParametersItem(globalHeaderParameter()) | ||
| 97 | + ) | ||
| 85 | .pathsToMatch("/admin-api/**") | 98 | .pathsToMatch("/admin-api/**") |
| 86 | .build(); | 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,14 +37,17 @@ spring: | ||
| 37 | springdoc: | 37 | springdoc: |
| 38 | show-actuator: true | 38 | show-actuator: true |
| 39 | swagger-ui: | 39 | swagger-ui: |
| 40 | + enabled: true | ||
| 40 | path: /swagger-ui | 41 | path: /swagger-ui |
| 41 | api-docs: | 42 | api-docs: |
| 43 | + enabled: true | ||
| 42 | path: /v3/api-docs | 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 | # 工作流 Flowable 配置 | 52 | # 工作流 Flowable 配置 |
| 50 | flowable: | 53 | flowable: |
yudao-ui-admin-vue3/src/views/infra/swagger/index.vue
| @@ -8,5 +8,5 @@ import { ref } from 'vue' | @@ -8,5 +8,5 @@ import { ref } from 'vue' | ||
| 8 | import { IFrame } from '@/components/IFrame' | 8 | import { IFrame } from '@/components/IFrame' |
| 9 | 9 | ||
| 10 | const BASE_URL = import.meta.env.VITE_BASE_URL | 10 | const BASE_URL = import.meta.env.VITE_BASE_URL |
| 11 | -const src = ref(BASE_URL + '/doc.html') | 11 | +const src = ref(BASE_URL + '/swagger-ui') |
| 12 | </script> | 12 | </script> |