带有Play框架的ImplicitParam中的Swagger数据类型模型

时间:2015-03-03 13:51:47

标签: scala playframework swagger swagger-ui swagger-play2

我正在尝试使用Swagger来记录我的REST API。在example之后,我按如下方式注释REST端点:

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的属性。

问候, 丹尼尔

3 个答案:

答案 0 :(得分:9)

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

答案 1 :(得分:0)

尝试使用swagger注释来注释模型,如下所示:

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

你的注释ApiModel(name =" CreateItemRequest")匹配注释@ApiImplicitParam(dataType =" CreateItemRequest")

干杯,约翰内斯

答案 2 :(得分:0)

尝试在课程前使用此注释@JsonAutoDetect@JsonIgnoreProperties(ignoreUnknown = true),然后为要展示的每个媒体添加@JsonPropety

确保在路线定义中将您的方法称为:

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

更多示例here

希望这会对你有所帮助。