首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Scala上的Swagger,类型uuid和long未定义

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

Stack Overflow用户
提问于 2017-01-03 21:02:28
回答 2查看 795关注 0票数 1

我正在尝试使用akka-http 10.0.0和swagger-akka-http 0.8.2在我的路由上实现swagger。它工作得很好,但是类型为UUID和Long的查询参数被认为是未定义的。

我应该使用格式吗?

怎么用?

这是我的一条路线:

代码语言:javascript
复制
  @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")
    ))
EN

回答 2

Stack Overflow用户

发布于 2017-01-04 17:11:47

长久以来,请使用@ApiImplicitParam(... dataType="long" ...)。为参数生成的swagger json:

代码语言:javascript
复制
{
   "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类型的参数,在swagger.io代码中没有针对UUID的特殊处理。所以我推荐dataType="string“。作为通用指针,@ApiImplicitParam dataType的文档记录为:

代码语言:javascript
复制
/**
 * The data type of the parameter.
 * <p>
 * This can be the class name or a primitive.
 */

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

票数 1
EN

Stack Overflow用户

发布于 2017-01-04 20:44:41

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

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

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

对于类名,这意味着您必须包含文档中提到的完整类名"java.util.UUID“或{UUID.class}

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41444147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档