0
我正在使用Springfox和Swagger生成swagger文件。現在我正在使用@ModelAttribute
從對象中提取變量(NetworkCmd
)以在swagger文檔中顯示爲查詢參數。使用@ModelAttribute時未顯示自定義域對象
目前,我有以下控制器:
@RequestMapping(value = "/{product_id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseHeader()
public ResponseEntity<?> networkResponse(
@RequestHeader HttpHeaders headers,
@PathVariable("product_id")String productId,
@Valid @ModelAttribute NetworkCmd cmd,
BindingResult result)
throws Exception {
...
}
這裏是NetworkCmd
樣本:
@ItemId
@NotNull(message = "product cannot be null")
@ApiModelProperty(
value = "testing")
private String product_id;
@ApiModelProperty(
value = "key",
private String key;
@ApiModelProperty(
value = "parent")
private Boolean is_parent_id;
@Min(0)
@ApiModelProperty(
value = "radius")
private double radius = 10d;
一個在這個類的變量是一個自定義的域對象Nearby
。
private Nearby nearby = null;
public Nearby getNearby() {
return nearby;
}
public void setNearby(String nearby) throws ParseException {
this.nearby = Nearby.parse(nearby);
}
這是怎樣的一個特殊變量,因爲它接受一個字符串,然後解析這個字符串,並把它變成了Nearby
對象。
我的問題是,這個Nearby
變量沒有顯示在生成的swagger文檔中,通過@ModelAttribute
。我很樂意提供更多信息。
感謝您的回答!不幸的是,這不起作用。我也試過: '.directModelSubstitute(Nearby.class,Object.class)' – ahatzz11