在 springdoc-openapi-ui 中启用授权按钮以进行基本身份验证

Enable Authorize button in springdoc-openapi-ui for Basic Authentication

如何在 springdoc-openapi-ui (OpenAPI 3.0 /swagger-ui.html) 中启用 "Authorize" 按钮进行基本身份验证。

Spring@Controller@Configuration类需要加什么注解?

@Configuration bean 中使用注释 @io.swagger.v3.oas.annotations.security.SecurityScheme 为 OpenAPI 3.0 定义全局安全方案:

@Configuration
@OpenAPIDefinition(info = @Info(title = "My API", version = "v1"))
@SecurityScheme(
    name = "basicAuth",
    type = SecuritySchemeType.HTTP,
    scheme = "basic"
)
public class OpenApi30Config {

}

@io.swagger.v3.oas.annotations.Operation 引用定义的安全方案来注释每个需要基本身份验证的 @RestController 方法:

@Operation(summary = "My endpoint", security = @SecurityRequirement(name = "basicAuth"))