200 Responses Not Overwritten at the Class Level
See original GitHub issueQ | A |
---|---|
Bug or feature request? | Bug |
Which Swagger-Core version? | 1.5.18 |
Which Java version? | 1.8u151 |
Which JAX-RS framework & version? | RESTEasy 3.0.19 with JAX-RS 2.0 |
I have a fix for this issue. I’m just creating this issue for the PR.
Any default 200 (or whatever the default responses are set to) responses cannot be overridden with @ApiResponse
at the class level. This isn’t an issue for method level @ApiResponse
annotations.
The bug occurs in Reader.java at lines 945 - 955:
for (ApiResponse apiResponse : apiResponses) {
addResponse(operation, apiResponse, jsonViewAnnotation);
}
// merge class level @ApiResponse
for (ApiResponse apiResponse : classApiResponses) {
String key = (apiResponse.code() == 0) ? "default" : String.valueOf(apiResponse.code());
if (operation.getResponses() != null && operation.getResponses().containsKey(key)) {
continue;
}
addResponse(operation, apiResponse, jsonViewAnnotation);
}
Here, method level @ApiResponse
annotations are added first, then class level @ApiResponse
annotations are added. This works in every other scenario since the class level for loop checks to see if the response code has already been included before adding the class level response to stop the class level responses from overwriting the method level responses. These for loops do not take into account that the default responses are added to operation earlier in the code which results in the bug.
To fix this bug I changed the order the responses are being added to operation to be: default->class level->method level. This way each time a response is found the response will always overwrite any response with the same response code.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@PeaceInColour - no, we monitor and review the PRs as we can.
see also this comment in PR #2713