如何在springdoc-openapi-ui (OpenAPI 3.0 /swagger-ui.html
) 中启用“授权”按钮以进行基本身份验证。
@Controller
Spring和@Configuration
类需要添加哪些注解?
如何在springdoc-openapi-ui (OpenAPI 3.0 /swagger-ui.html
) 中启用“授权”按钮以进行基本身份验证。
@Controller
Spring和@Configuration
类需要添加哪些注解?
@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"))