更新端点的响应对象

时间:2016-07-04 14:06:38

标签: java spring spring-mvc

我使用swagger自动生成SpringMVC API。现在我想手动更新一些端点。 我有一个完整的终点:

  @ApiOperation(value = "Estimation of ...", notes = "...", response = Similarity.class, responseContainer = "List")
  @io.swagger.annotations.ApiResponses(value = { 
    @io.swagger.annotations.ApiResponse(code = 200, message = "Similarity metrics", response = Similarity.class),
    @io.swagger.annotations.ApiResponse(code = 200, message = "Unexpected error", response = Similarity.class) })
  @RequestMapping(value = "/estimateSimilarity",
    produces = { "application/json" },
    method = RequestMethod.GET)
  public ResponseEntity<HashMap<String,Double>> estimateSimilarity(
          @ApiParam(value = "...", required = true)
          @RequestParam(value = "term1", required = true) String term,
          @ApiParam(value = "...", required = true)
          @RequestParam(value = "terms", required = true) List<String> concepts)
      throws NotFoundException {
      Similarity similarity = new Similarity();
      HashMap<String,Double> result = similarity.getEstimates(term1, terms);
      return new ResponseEntity<HashMap<String,Double>>(HttpStatus.OK);
  }

我想要返回response = Similarity.class而不是HashMap<String,Double> result。我应该如何更新上面给出的代码才能返回这个对象?

1 个答案:

答案 0 :(得分:1)

尝试修改ApiOperations Response容器。

@ApiOperation(value = "Estimation of ...", notes = "...", response = Double.class, responseContainer = "Map")