elide
elide copied to clipboard
Authorization on Swagger UI
The bundled Swagger UI does not give an option to authorize requests. Usually, Swagger presents an Authorize
button when any request is sequred (as shown in the screenshot below).
When I use Elide Spring Boot starter, and I secure my endpoints, the Swagger UI doesn't present any option to add JWT token.

I've also tried adding the 'Authorization' header for every path as follows:
HeaderParameter oauthParam = new HeaderParameter()
.name("Authorization")
.type("string")
.description("OAuth bearer token")
.required(true);
SwaggerBuilder builder = new SwaggerBuilder(dictionary, info)
.withGlobalParameter(oauthParam);
return builder.build()
.basePath(settings.getJsonApi().getPath());
Nothing works.
I believe this is covered in the docs here:
https://elide.io/pages/guide/v4/13-swagger.html#supporting-oauth
Thanks.
What was lacking in the documentation was that we needed to define a bean of type SwaggerController.SwaggerRegistrations
.
Now after adding the code as per the docs, the Authorize button is now enabled but all my JSON api endpoints disappear. See the "No operations in Spec!" part in the screenshot.
My code:
@Bean
public SwaggerController.SwaggerRegistrations buildSwagger2(EntityDictionary dictionary, ElideConfigProperties settings) {
Info info = new Info()
.title(settings.getSwagger().getName())
.version(settings.getSwagger().getVersion());
SwaggerBuilder builder = new SwaggerBuilder(dictionary, info);
Swagger swagger = builder.build()
.basePath(settings.getJsonApi().getPath())
.securityDefinition("JWT Token", new ApiKeyAuthDefinition("Authorization", In.HEADER))
.scheme(Scheme.HTTP);
return new SwaggerController.SwaggerRegistrations(swagger);
}
