5

我正在尝试使用 Swagger 来记录我的 REST API。按照这个例子,我像这样注释 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
          ) 

我期待得到“模型”,这个但我只得到字符串“CreateItemRequest”作为数据类型。不是案例类 CreateItemRequest 的属性。

问候,丹尼尔

4

3 回答 3

9

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

于 2015-08-06T08:34:56.577 回答
0

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

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

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

干杯,约翰内斯

于 2015-03-04T12:03:14.377 回答
0

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

确保在您的路由定义中调用您的方法,例如:

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

更多示例在这里

希望这会帮助你。

于 2015-04-29T13:14:38.583 回答