From 683b49a8a49d6e1833b230431fddc5ef48acb1ed Mon Sep 17 00:00:00 2001 From: xingyu Date: Thu, 22 Dec 2022 00:49:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20springdoc=20=E5=BC=80=E5=90=AF=E8=AE=A4?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/YudaoSwaggerAutoConfiguration.java | 27 ++++++++++++++++--- .../src/main/resources/application.yaml | 1 + 2 files changed, 24 insertions(+), 4 deletions(-) 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 4bb2d77ac..9e05fe3a0 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 @@ -6,7 +6,10 @@ import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; import io.swagger.v3.oas.models.security.SecurityRequirement; import io.swagger.v3.oas.models.security.SecurityScheme; -import org.springdoc.core.GroupedOpenApi; +import org.springdoc.core.*; +import org.springdoc.core.customizers.OpenApiBuilderCustomizer; +import org.springdoc.core.customizers.ServerBaseUrlCustomizer; +import org.springdoc.core.providers.JavadocProvider; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -15,6 +18,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.http.HttpHeaders; import java.util.Arrays; +import java.util.List; +import java.util.Optional; /** * Swagger3 自动配置类 @@ -38,17 +43,17 @@ public class YudaoSwaggerAutoConfiguration { .license(new License().name("MIT").url("https://gitee.com/zhijiantianya/ruoyi-vue-pro/blob/master/LICENSE")); //鉴权组件(随便起名的) SecurityScheme securityScheme = new SecurityScheme() - .type(SecurityScheme.Type.OAUTH2) + .type(SecurityScheme.Type.APIKEY) .scheme("bearer")//固定写法 .bearerFormat("JWT") .in(SecurityScheme.In.HEADER) .name(HttpHeaders.AUTHORIZATION); Components components = new Components() - .addSecuritySchemes("bearer", securityScheme); + .addSecuritySchemes("Bearer", securityScheme); //鉴权限制要求(随便起名的) SecurityRequirement securityRequirement = new SecurityRequirement() - .addList("bearer", Arrays.asList("read", "write")); + .addList(HttpHeaders.AUTHORIZATION, Arrays.asList("read", "write")); return new OpenAPI() .info(info) @@ -56,6 +61,20 @@ public class YudaoSwaggerAutoConfiguration { .addSecurityItem(securityRequirement); } + /** + * 自定义 openapi 处理器 + */ + @Bean + public OpenAPIService openApiBuilder(Optional openAPI, + SecurityService securityParser, + SpringDocConfigProperties springDocConfigProperties, + PropertyResolverUtils propertyResolverUtils, + Optional> openApiBuilderCustomisers, + Optional> serverBaseUrlCustomisers, + Optional javadocProvider) { + return new OpenAPIService(openAPI, securityParser, springDocConfigProperties, propertyResolverUtils, openApiBuilderCustomisers, serverBaseUrlCustomisers, javadocProvider); + } + @Bean public GroupedOpenApi appApi() { return GroupedOpenApi.builder() diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 583a58563..22e32d931 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -35,6 +35,7 @@ spring: time-to-live: 1h # 设置过期时间为 1 小时 springdoc: + show-actuator: true swagger-ui: path: /swagger-ui