Scala上的Swagger,类型uuid和long是未定义的

时间:2017-01-03 13:02:28

标签: scala akka swagger akka-http swagger-akka-http

我尝试使用akka-http 10.0.0和swagger-akka-http 0.8.2在我的路线上实施招摇。它运行良好,但查询参数类型为:UUID和Long被视为未定义。

我应该使用格式吗?

如何使用它?

这是我的路线之一:

  @GET @Path("/{publisher_id}/{app_id}")
    @ApiOperation(
        value = "get a app Installation stat for an app ID",
        notes = "Returns a session based on ID",
        httpMethod = "GET"
    )
    @ApiImplicitParams(Array(
        new ApiImplicitParam(name = "app_id", value = "ID of app that needs to be fetched, format com.totot.plop ", required = true, dataType = "string", paramType = "path"),
        new ApiImplicitParam(name = "publisher_id", value = "publisher id : publisher_id ", required = true, dataType = "UUID?",  paramType = "path"),
        new ApiImplicitParam(name = "date_start", value = "Timestamp start date ", required = true, dataType = "LONG???" , paramType = "query"),
        new ApiImplicitParam(name = "date_end", value = "Timestamp end date", required = true, dataType = "LONG???", paramType = "query"),
        new ApiImplicitParam(name = "access_token", value = "session token of the user ", required = true, dataType = "UUID????", paramType = "query")
    ))
    @ApiResponses(Array(
        new ApiResponse(code = 404, message = "App not found"),
        new ApiResponse(code = 400, message = "Invalid ID supplied"),
        new ApiResponse(code = 401, message = "access token invalid")
    ))

2 个答案:

答案 0 :(得分:1)

对于Long,请使用@ApiImplicitParam(... dataType="long" ...)。为参数生成的swagger json:

{
   "name" : "name",
   "in" : "query",
   "description" : "param desc",
   "required" : true/false,
   "type" : "int",
   "format" : "int64"
}

https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X有一个示例参数。

对于java.util.UUID类型的params,我知道UUID的swagger.io代码中没有特殊处理。所以我建议dataType =“string”。作为一般指针,@ApiImplicitParam dataType记录为:

/**
 * The data type of the parameter.
 * <p>
 * This can be the class name or a primitive.
 */

原始值似乎是java原始类型名称,例如int,long等。string也受支持。

答案 1 :(得分:1)

首先,您可以按照文档中的说明指定一个类:

  

dataType可以是基元名称或类名。

https://github.com/swagger-api/swagger-core/wiki/Annotations-1.5.X#apiimplicitparam-apiimplicitparams

通过班级名称,这意味着您必须包含完整类名称,即&#34; java.util.UUID&#34;或 {UUID.class} ,如文件中所述。