You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2019/04/23 03:01:19 UTC

[GitHub] [servicecomb-java-chassis] zhangzc0419 commented on issue #905: 原有项目是springmvc改造成rest api的,swagger生成报错

zhangzc0419 commented on issue #905: 原有项目是springmvc改造成rest api的,swagger生成报错
URL: https://github.com/apache/servicecomb-java-chassis/issues/905#issuecomment-485624886
 
 
   > 参数列表不支持HttpServletResponse,当前只支持HttpServletRequest,异常返回可以通过抛异常的方式
   > 
   > ```
   > throw new InvocationException(400, "Request Error", "An error!");
   > ```
   > 或者使用
   > 
   > ```
   >     @RequestMapping(value = "/test", produces = {"application/json"}, method = RequestMethod.GET)
   >     @ApiResponses({
   >             @ApiResponse(code = 500, message = "Internal error", response = User.class),
   >             @ApiResponse(code = 200, message = "normal", response = Test.class),
   >             @ApiResponse(code = 302, message = "normal")
   >     })
   >     public ResponseEntity<Object> getTest(@RequestParam(value = "name") String name) {
   >         if (name == null) {
   >             User u = new User();
   >             u.setName("test");
   >             return ResponseEntity.status(302)
   >                     .header("Location", "www.baidu.com")
   >                     .body(new InvocationException(Status.FOUND, ""));
   >         }
   >         Test test = new Test();
   >         test.setName("bb");
   >         ResponseEntity<Object> resp = ResponseEntity.ok(test);
   >         return resp;
   >     }
   > ```
   
   支持HttpServletRequest但不支持HttpServletResponse的原因是?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services