Reputation: 39055
Is it possbile to give a default request example in swagger page? Now on the server side, it define like this:
Response<PageBeanExt<ReportUserAppDateStatisticResponse, ReportUserAppDateStatisticResponse>> statisticByGameAndDate(@RequestBody ReportUserRequest request);
now I want the swagger ui have a default request example so that I can simple send a request without composite request json every time:
what should I do to make it? I have already tried this but it seems not work:
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<PageBeanExt<ReportUserAppDateStatisticResponse, ReportUserAppDateStatisticResponse>> statisticByGameAndDate(@ApiParam(defaultValue = appStatistic) @RequestBody ReportUserRequest request);
Upvotes: 0
Views: 4272
Reputation: 3766
You can use @ApiModelProperty(example = "1111")
public class User{
@ApiModelProperty(example = "1111")
private String userName;
@ApiModelProperty(example = "Testing")
private String role;
}
It shows on swagger as
Upvotes: 2
Reputation: 1207
You can annotate your request object, ReportUserRequest with swagger annotations and specify examples in those annotations for additional spec details. In your case check the @ApiModelProperty which can be set for a specific property
For e.g:
@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;
}
Upvotes: 1