Scala Play Swagger:嵌套的@ApiImplicitParam定义

时间:2016-07-21 16:42:55

标签: json scala playframework annotations swagger

我在我的项目中使用了play-swagger + swagger-ui,但我已向json机构请求了这样的内容:

{"country":{"title": "Germany"}}'

当我用以下方法注释我的方法时:

ApiImplicitParam(name = "country[title]", value = "Country's title", required = true, dataType = "String", paramType = "body")

它在swagger UI中不起作用,如何在title命名空间中告诉我的country名称?

1 个答案:

答案 0 :(得分:1)

最好的方法是定义一个CountryRequest类(也带有注释),作为请求对象的模型。然后,在定义ApiImplicitParam时,您将引用此类。例如,

@ApiModel(value = "CountryRequest")
case class CountryRequest(
  @(ApiModelProperty @field)(dataType = "String", readOnly = false, required = true) title: String,
)

顺便提一下,您可能希望将此参数定义为body参数,因此它应如下所示:

@ApiImplicitParams(Array(
  @ApiImplicitParam(name = "body", value = "Country", required = true, dataType = "com.example.CountryRequest", paramType = "body")
))
def postCountry = ...