可以在swagger页面中给出一个默认的请求示例吗?现在在服务器端,它是这样定义的:
Response> statisticByGameAndDate(@RequestBody ReportUserRequest request);
现在我希望swagger ui有一个默认的请求示例,这样我每次都可以简单地发送一个请求,而不需要复合请求json:
我应该怎么做才能做到这一点?我已经尝试过了,但它似乎不起作用:
static final String appStatistic = "{\n" +
" \"roomType\":\"1\",\n" +
" \"startDate\":\"2021-2-15 0:0:0 000\",\n" +
" \"endDate\":\"2021-12-25 23:59:59 999\"\n" +
"}\n";
/**
* @return
*/
@PostMapping("/detail/app-date-statistic/")
Response> statisticByGameAndDate(@ApiParam(defaultValue = appStatistic) @RequestBody ReportUserRequest request);
发布于 2021-02-25 08:42:45
您可以使用swagger注释来注释您的请求对象ReportUserRequest,并在这些注释中指定示例以获取额外的规范详细信息。在您的情况下,请检查@ApiModelProperty,它可以为特定属性设置
例如:
@ApiModel(value="Your report user request description")
public class ReportUserRequest{
@ApiModelProperty(value="A description for the key", example="example value", required= true)
private String key;
}
发布于 2021-02-25 08:55:07
您可以使用@ApiModelProperty(example = "1111")
public class User{
@ApiModelProperty(example = "1111")
private String userName;
@ApiModelProperty(example = "Testing")
private String role;
}
它在swagger上显示为
https://stackoverflow.com/questions/66364907
复制相似问题