2

我的 Spring Boot 应用程序中有两种方法,RequestMapping一种返回JSON,另一种返回returns byte[]

public class UserApiController implements UserApi

@RequestMapping(value="/getUser/{userId}",
    produces = {"application/json"},
    consumes = {"application/json"},
    method = RequestMethod.GET)
    public ResponseEntity<UserModel> getUser(@PathVariable("userId")String userId){
    //returns UserModel JSON 
    }

@RequestMapping(value="/getUser/{userId}",
    produces = {"application/pdf"},
    consumes = {"application/pdf"},
    method = RequestMethod.GET)
    public ResponseEntity<byte[]> getUserPDF(@PathVariable("userId")String userId){
    //returns byte[] of pdf

    }

我通过OpenApiusing .yamlusing生成接口openapi-generator-cli-3.3.0.jar 当我生成接口时,我的接口生成这样的方法

 @RequestMapping(value="/getUser/{userId}",
        produces = {"application/json","application/pdf"},
        method = RequestMethod.GET)
        public ResponseEntity<UserModel> getUser(@PathVariable("userId")String userId);

我怎样才能强制它制作两种单独的方法而不是一种?

4

1 回答 1

1

根据我们在您的帖子下的评论,这是不可能的。

引用规范

OpenAPI 将唯一操作定义为路径和 HTTP 方法的组合。这意味着不允许对同一路径使用两个 GET 或两个 POST 方法

于 2019-04-08T22:24:58.310 回答