给出以下带有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与Void)的详尽的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状态代码呈现两个不同的模型?