如何在spring boot中为swagger ui指定请求主体?

du7egjpx  于 2021-07-08  发布在  Java
关注(0)|答案(1)|浏览(353)

我有以下带注解的swagger控制器:

@PostMapping("/getMediaDataProduct/V2")
    @ResponseBody
    @ApiOperation(value = "get media data product v2")
    @ApiResponses({@ApiResponse(code = 200, message = "Successful", response = MediaDataProductResponseV2.class)})

    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "xxxxx", value = "xxxx", paramType = "header", required = true),
            @ApiImplicitParam(name = "xxxx", value = "xxxx", paramType = "header", required = true),
            @ApiImplicitParam(name = "xxxx", value = "xxxx", paramType = "header"),
            @ApiImplicitParam(name = "xxxx", value = "xxxx", paramType = "header", required = true),
            //  @ApiImplicitParam(name = "xxxxxx", value = "xxx", paramType = "header" ,required = true),
            @ApiImplicitParam(name = "xxxxxx", value = "xxxxx", paramType = "header"),
            @ApiImplicitParam(name = "xxxxxxx", value = "xxxxxxxx", paramType = "header", required = true)})

    public ResponseEntity getMediaDataProductV2(@RequestBody final String request, @RequestHeader final HttpHeaders headers) {
        Slogger.get().debug("/getMediaDataProduct/V2: this.mediaDataService: " + this.mediaDataService);

        MediaDataProductResponseV2 response = mediaDataService.getMediaDataProductV2(request);
        HttpStatus status = getHttpStatus(response.getStatusMessages(), response.getSystemErrors());
        List<StatusMessage> statusMessages = appendSuccessStatusMessage(response.getStatusMessages(), status);
        if(statusMessages !=null) {
            response.setStatusMessages(statusMessages);
        }
        return new ResponseEntity<>(response, new HttpHeaders(), status);
    }

如何指定请求主体以使其显示在swagger ui中?
最新消息:我曾在许多论坛上对此进行过研究,但似乎没有找到答案。”如何使用swagger注解来指定请求体类,就像我对apiresponses所做的那样?”。在为body创建的swagger ui中有一个默认参数,但不知道如何通过引用request body类来指定它。

8ehkhllq

8ehkhllq1#

如果我正确理解了您的问题,那么您需要在swagger定义中显示一个响应类型。大多数时候,swagger会自动将方法返回类型Map为响应类型。
但是,当它是一个泛型类时,它就不能这样做,就像在您的例子中一样 ResponseEntity . 如果你能把你的返回类型改成 ResponseEntity<MediaDataProductResponseV2> ,应该有用。

相关问题