如何在springdoc-openapi-ui(OpenAPI 3.0 /swagger-ui.html
)中启用“授权”按钮以进行基本身份验证。
必须在Spring @Controller
和@Configuration
类中添加哪些注释?
使用@io.swagger.v3.oas.annotations.security.SecurityScheme
bean中的注释@Configuration
为OpenAPI 3.0定义全局安全性方案:
@Configuration
@OpenAPIDefinition(info = @Info(title = "My API", version = "v1"))
@SecurityScheme(
name = "basicAuth",
type = SecuritySchemeType.HTTP,
scheme = "basic"
)
public class OpenApi30Config {
}
使用参考定义的安全方案的@RestController
注释每个需要基本身份验证的@io.swagger.v3.oas.annotations.Operation
方法:
@Operation(summary = "My endpoint", security = @SecurityRequirement(name = "basicAuth"))