我在我的项目中使用了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
名称?
答案 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 = ...