如果使用对象描述请求正文,则可以使用@ApiModelProperty,例如:
data class RequestBody(
@ApiModelProperty(example = "John Doe")
val name: String,
@ApiModelProperty(example = "Coolstreet 1")
val address: String
)
替代方法是使用@Example和@ExampleProperties,但我发现它们更加混乱。在官方参考文档中有一些有关如何使用它们的示例:http : //springfox.github.io/springfox/docs/current/#example-application
提供的示例:
@RequestMapping(value = "/2031", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "/2031")
@ApiImplicitParams({
@ApiImplicitParam(
name = "contents",
dataType = "CustomTypeFor2031",
examples = @io.swagger.annotations.Example(
value = {
@ExampleProperty(value = "{'property': 'test'}", mediaType = "application/json")
}))
})
public void save(@PathVariable("keyId") String keyId,
@PathVariable("id") String id,
@RequestBody String contents
) {
}
public static class CustomTypeFor2031 {
private String property;
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句