13

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

@ControllerSpring和@Configuration类需要添加哪些注解?

授权按钮

基本认证的授权表格

4

1 回答 1

21

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

@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"))
于 2020-01-24T14:48:29.007 回答