[Springdoc OpenAPI] 给请求携带 Authentication
file:[SwaggerConfig.java]
/**
* @description:
* @package: com.bleuon.config
* @author: zheng
* @date: 2023/10/13
*/
@Configuration
public class SwaggerConfig {
@Bean
public OpenAPI customize() {
Components components = new Components();
SecurityScheme scheme = new SecurityScheme()
.name("bearerAuth")
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT");
components.addSecuritySchemes("bearerAuth", scheme);
return new OpenAPI().
components(components)
.addSecurityItem(new SecurityRequirement().addList("bearerAuth"))
.info(new Info()
.title("SpringDoc API")
.description("SpringDoc 接口测试")
.version("1.0.0"));
}
}
在点击 Swagger UI 右上角的 Authorize 按钮填入 Token 值,但是记得不要连同写上 Beare。