使用Swagger我可以使用
注释响应对象 @ApiOperation(value = "save a user", response = User.class)
@POST
public Response saveUser(String message){...}
然后生成json响应结构,例如
User {
id (integer, optional),
email (string, optional)
}
如何在不更改saveUser方法的方法参数类型的情况下指定POST消息的结构?
我正在寻找类似的东西:
@ApiOperation(value = "save a user", response = User.class, request = User.class)
有办法吗?
答案 0 :(得分:3)
是的,有办法做到这一点。您应该查看annotating your models的文档。在您的示例中,我将您的模型注释为:
@ApiModel(value = "An individual model details")
User {
@ApiModelProperty(value = "description", required=true)
id,
@ApiModelProperty(value = "description", required=true)
email
}
然后你的资源看起来像:
@POST
@ApiOperation(value = "short description", notes = "long description", response = User.class)
Response create(@ApiParam(value = "description", required = true) String message) {
//do stuff
}
注意传入消息上的ApiParam注释,而ApiOperation注释描述传出模型。