2015-03-03 62 views
5

我试图使用Swagger来记录我的REST API。在此之后example,我批注REST端点是这样的:隐式参数与播放框架中的Swagger数据类型模型

case class CreateItemRequest(title: String, body: String) 

@ApiOperation(value = "Create a new item", httpMethod = "POST", response = classOf[Item]) 
@ApiImplicitParams(Array(new ApiImplicitParam(dataType = "CreateItemRequest", paramType = "body", name = "body", required = true, allowMultiple = false, value = "The item object to create"))) 
def create(
      @ApiParam(value = "Hash of the user", required = true) 
      @QueryParam("userhash") userhash: String 
     ) 

而且我期待得到“模型”像this但我只得到了字符串“CreateItemRequest”作为数据类型。不是案例类CreateItemRequest的属性。

问候, 丹尼尔

+0

您是否找到解决方案?我面临同样的问题:\ – Sudh 2015-03-25 13:49:03

回答

0

尝试用招摇的注释来注释的模型,以及像所示:

https://github.com/swagger-api/swagger-core/blob/master/samples/scala-play2/app/models/Pet.scala

您的注释ApiModel(NAME = “CreateItemRequest”)相匹配的注解@ApiImplicitParam(dataType =“CreateItemRequest”)

Cheers,Johannes

+1

我已经尝试过,但不幸的是不工作:( – 2015-03-04 13:36:00

+1

您是否找到解决方案?我有同样的问题。 – 2015-03-19 10:58:42

0

在课前试用此注释@JsonAutoDetect@JsonIgnoreProperties(ignoreUnknown = true),然后为要显示的每个属性添加@JsonPropety

确保在你的路由定义你打电话给你的方法,如:

GET url controllers.foo.YourMethod(param: type) 

更多例子here

希望这会帮助你。

9

您应该在dataType属性中使用完整的名称空间。例如: @ApiImplicitParam(dataType = "org.test.CreateItemRequest")

+1

它解决了我的问题。 – chabeee 2015-08-25 11:59:35