简体   繁体   中英

Quarkus: how to test secured API endpoints with swagger-ui

We have a Quarkus application with some secured endpoints. For development and easy testing without much effort, we would like to use Swagger UI as described at https://quarkus.io/guides/openapi-swaggerui . But this seems to only work for unprotected endpoints.

Is there a way to also make request to protected endpoints in Swagger UI?

You need to add a security scheme to your specification:

One way to do it is by using annotations:

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

After you enable security scheme, authorize button will appear on swagger ui. Securirty scheme can be basic, bearer etc..

授权按钮

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM