给定以下带有springfox-swagger2注释的REST方法:
@GetMapping(value = "/access", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "check access allowed")
@ApiResponses({
@ApiResponse(code = 200, message = "okay, there you go", response = AccessResponse.class),
@ApiResponse(code = 204, message = "I got nothing for you", response = Void.class)
})
public ResponseEntity<AccessResponse> access() {
if (!isAccessEnabled()) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
AccessResponse response = new AccessResponse("some data");
return ResponseEntity.ok(response);
}
请注意,此方法可以返回两种状态:
我想生成一个反映不同响应模型(AccessResponse vs. Void)的swagger api文档。在@ApiResponse注释中,我明确告诉springfox-swagger2为每个状态使用不同的模型。不幸的是,生成的swagger api doc json仅指http 200和204的AccessResponse模型:
"responses":{
"200":{
"description":"okay, there you go",
"schema":{"$ref":"#/definitions/AccessResponse"}
},
"204":{
"description":"I got nothing for you",
"schema":{"$ref":"#/definitions/AccessResponse"}
}
}
我错过了什么吗?有没有办法告诉swagger为每个HTTP / ok状态代码渲染两个不同的模型?