Reputation: 11
I use springboot with swagger in my project.I have created a post method like this:
@RequestMapping("/ufile")
@Api(value = "文件服务", tags = {"文件服务"})
public class UfileController extends BaseApiController {
private static final Logger logger = LoggerFactory.getLogger(UfileController.class);
@ApiOperation(value = "文件上传", response = ApiResponse.class)
@PostMapping(value = "/upload", produces = "application/json;charset=utf-8")
public ApiResponse upload(@Valid @RequestBody UploadRequest uploadRequest, @ApiIgnore HttpServletResponse response
, @RequestParam(value = "protocol", defaultValue = "thrift", required = false) @ApiIgnore String protocol) {
.......
}
}
I have use @RequestBody in model UploadRequest in above code. And this is the model UploadRequest:
@Data
@ApiModel("文件上传请求")
public class UploadRequest extends BaseRequest {
@ApiModelProperty(value = "上传的文件", name = "上传的文件")
@NotEmpty
private MultipartFile[] multipartFiles;
@ApiModelProperty(value = "租户id", name = "租户id")
@NotBlank
private String tenantId;
@ApiModelProperty(value = "图片是否需要对应水印图片", name = "图片是否需要对应水印图片")
private boolean needWaterMark;
}
Swagger work well in this scene,it find ApiModel UploadRequest,and when I visit swagger-ui.html.I can see that:
But when I don't use @RequestBody in model UploadRequest,swagger can't find UploadRequest.When I visit swagger-ui,there is no UploadRequest in Model label.
What I want is when I change my code like this:
@RestController
@RequestMapping("/ufile")
@Api(value = "文件服务", tags = {"文件服务"})
public class UfileController extends BaseApiController {
private static final Logger logger = LoggerFactory.getLogger(UfileController.class);
@ApiOperation(value = "文件上传", response = ApiResponse.class)
@PostMapping(value = "/upload", produces = "application/json;charset=utf-8")
public ApiResponse upload(@Valid UploadRequest uploadRequest, @ApiIgnore HttpServletResponse response
, @RequestParam(value = "protocol", defaultValue = "thrift", required = false) @ApiIgnore String protocol) {
}
}
swagger can still find ApiModel UploadRequest.when I visit swagger-ui.html,the label Model contains UploadRequest.
Who can help me,please.
Upvotes: 1
Views: 1041
Reputation: 2028
Your requirement sounds kinda vague to me.
Btw, when you use @RequestBody
annotation it simply binds your Http
Request's body to your model object. So simply put, when you avoid that annotation, you are going to miss any http
request's body content sent by a request, hence, you are not seeing that in swagger. That's it.
If you need more clarification or anything, please mention it.
Upvotes: 1