2017-01-04 32 views
1

我有以下API端點:從對象如何提取參數參數顯示在文檔

@ApiResponses(
    value = { 
     @ApiResponse(code = 200, message = "OK", 
      responseHeaders = { 
       @ResponseHeader(name = "X-RateLimit-Limit", description = "The defined maximum number of requests available to the consumer for this API.", response = Integer.class), 
       @ResponseHeader(name = "X-RateLimit-Remaining", description = "The number of calls remaining before the limit is enforced and requests are bounced.", response = Integer.class), 
       @ResponseHeader(name = "X-RateLimit-Reset", description = "The time, in seconds, until the limit expires and another request will be allowed in. This header will only be present if the limit is being enforced.", response = Integer.class) 
      } 
     ) 
    } 
) 
@ApiOperation(httpMethod = "GET", hidden = false, nickname = "Get Network Availability in JSON", value = "Get network availability for a product", response = AvailableToPromise.class, position = 1) 
@RequestMapping(value = "/{product_id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) 
public ResponseEntity<?> networkAvailabilityJsonResponse(
    @RequestHeader HttpHeaders headers, 
    @PathVariable("product_id") String productId, 
    @Valid NetworkAvailabilityCmd cmd,     //query params 
    BindingResult result) 
    throws Exception {} 
} 

某些參數,如key從查詢中取出和映射到該對象由Spring MVC。

然而,在我招搖的UI端點的參數部分,它顯示了我一些奇怪的事情:

是在NetworkAvailabilityCmd顯示在此參數列表中的變量都沒有,而cmd本身顯示爲位於請求體中(它實際上位於查詢中)。有沒有辦法隱藏cmd並提取此對象內的參數以顯示在參數列表中?我想在PARAMS列表看起來像這樣(有更多的PARAMS):

我能夠做到這一點,如果我的方法端點使用@ApiImplicitParams,並寫出每個PARAMS的。但是,這個NetworkAvailabilityCmd用於許多端點,並且在每個端點上有參數列表非常混亂。能夠從對象中提取變量將更加清晰,並且可以防止人們忘記將整個列表添加到新端點。

我想它需要NetworkAvailabilityCmd cmd上的註釋,並且可能有關於該類中的變量的某些內容,但我似乎無法在文檔中找到我要查找的內容。

謝謝!

回答

0

我發現添加@ModelAttribute神奇地工作。這個註釋來自Spring。