Klue
Klue

Reputation: 1357

Update a response object of the end-point

I generated automatically SpringMVC API using swagger. Now I want to update some end-points manually. I have the folloiwng end-point:

  @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);
  }

Instead of response = Similarity.class, I want to return HashMap<String,Double> result. How should I update the above-given code to be able to return this object?

Upvotes: 1

Views: 282

Answers (1)

Balajee
Balajee

Reputation: 191

Try modifying the ApiOperations Response container.

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

Upvotes: 1

Related Questions