200 Responses Not Overwritten at the Class Level
| Q | 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.
I'm getting a permission denied message when trying to push my branch. Do I need to get permission to push my branch or is there something wrong on my end?
Thanks for the fix! to open a PR, please fork the repo and push the branch to your own repo, and open the PR from there targeting the main repo.
For PRs do we have to assign someone to them ourselves?
@PeaceInColour - no, we monitor and review the PRs as we can.
see also this comment in PR #2713
Closing this issue as part of our https://github.com/swagger-api/swagger-core/issues/5074. This issue is outdated and/or inactive for a long time, and we’re not able to revisit it meaningfully.
If this problem is still relevant, please open a new issue and reference this one for context. Thank you for your understanding!