我正在尝试使用swagger&swagger-akka-http记录akka-http API . This blog post给了我一个良好的开端,但现在我陷入困境,试图记录API使用基本身份验证的事实 .
我拥有的是:
@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 {...
这会生成一个json,我可以在swagger UI中查看 . 但是,我无法使用生成的示例,因为缺少auth选项 .
我没有找到任何使用swagger-akka-http的例子,只有一些使用 yaml
config
在 yaml
中,这可能如下所示:
securityDefinitions:
basicAuth:
type: basic
description: HTTP Basic Authentication.
但是,我没有 yaml
. 除了通过注释,我也无法控制生成的 .json
.
IIUC,提及auth方法的正确位置是 Api
或 ApiOperation
注释的 authorizations
参数 . 该参数应包含 Authorization
注释数组 .
每个 Authorization
注释的 value
属性应该引用SecurityDefinitionObject
但我不知道如何使用注释定义这个 SecurityDefinitionObject
.
Authorization注释不应该单独使用,如果是,则被忽略 .
有没有我错过的东西?我是否需要额外的 yaml
或 json
文件以及其他声明?如果我这样做,我该把它放在哪里?还有什么呢?
谢谢
EDIT
使用0.7.2-SNAPSHOT,生成basicAuth数组是这样的:
paths: {
/foos: {
get: {
security: [
{
basicAuth: [ ]
}
],
现在唯一的问题是让Swagger UI正确解释它并在示例中使用auth . AFAIK,如果你需要在UI中使用基本身份验证,你必须自己添加它,就像它描述的那样here
1 回答
我目前维持swagger-akka-http .
代码几乎是swagger.io代码库的一个薄包装 .
@Api和@ApiOperation注释支持授权参数 .
https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-annotations/src/main/java/io/swagger/annotations/Api.java
我从未使用过这个功能,但也许你可以尝试一下 .