I am trying to document an akka-http API using swagger & swagger-akka-http. This blog post gave me a good start, but now I am stuck, trying to document the fact that the API is using basic auth.
what I have is:
@Path("/foo")
@Api(value = "/foo", produces = "application/json")
class FooService ...
@ApiOperation(value = "Get list of all foos", nickname = "getAllFoos", httpMethod = "GET",
response = classOf[Foo], responseContainer = "Set")
def getAll: Route = get {...
This generates a json which I can view in the swagger UI. However, I cannot use the generated examples, as the auth option is missing.
I have not found any examples using swagger-akka-http, only some using yaml
config
In a yaml
, this could look like this:
securityDefinitions:
basicAuth:
type: basic
description: HTTP Basic Authentication.
however, I do not have a yaml
. Nor do I have control over the generated .json
except through the annotations.
IIUC, the correct place to mention the auth method is the authorizations
parameter of the Api
or ApiOperation
annotations. This param should contain an array of Authorization
annotations.
The value
attribute of each Authorization
annotation is supposed to reference a SecurityDefinitionObject
But I have no idea how to define this SecurityDefinitionObject
using annotations.
The Authorization
annotation is not supposed to be used standalone and is ignored if it is.
Is there something I have missed? Do I need an extra yaml
or json
file with additional declarations and where do I put it if I do? Something much more else?
Thank you
EDIT
With the 0.7.2-SNAPSHOT, the basicAuth array is being generated lie this:
paths: {
/foos: {
get: {
security: [
{
basicAuth: [ ]
}
],
Now the only issue is to get the Swagger UI to interpret it correctly and use the auth in the examples. AFAIK, if you need basic auth in the UI, you have to add it yourself, like it is described here