【发布时间】:2017-01-10 18:06:56
【问题描述】:
我在 Spring-Boot RestController 中有一个 rest 方法的方法签名,如下所示:
@RequestMapping(
value = "/path",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiImplicitParams({
@ApiImplicitParam(
name = "message",
value = "Message that is sent to the method",
required = true,
dataType = "string",
paramType = "body"
)
})
public @ResponseBody String receiveMessage(@RequestBody String message) {
// ...
return "{\"success\": true}";
}
我想为 message 参数提供一个“样本”值,它是一个 JSON 字符串(例如 {"key" : "value"})。有人知道我如何使用 Swagger 注释来做到这一点吗?我试过了
@ApiImplicitParams({
@ApiImplicitParam(
// ...
example = "...JSON value..."
)
})
但它没有用。我想要的是文档中的“示例值”,读者可以单击以使文档中的参数值字段填充给定的示例值。这可能吗?
这是它的外观截图:
只是为了防止“无用”的答案:由于我的业务逻辑,我无法将参数的类型从 String 更改为某些类类型。
【问题讨论】:
-
为什么不使用
@ApiModelProperty将数据类作为参数和文档?
标签: java rest spring-boot swagger