swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

200 Responses Not Overwritten at the Class Level

Open PeaceInColour opened this issue 8 years ago • 6 comments

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.

PeaceInColour avatar Mar 14 '18 15:03 PeaceInColour

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?

PeaceInColour avatar Mar 15 '18 18:03 PeaceInColour

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.

frantuma avatar Mar 16 '18 14:03 frantuma

For PRs do we have to assign someone to them ourselves?

PeaceInColour avatar Apr 02 '18 15:04 PeaceInColour

@PeaceInColour - no, we monitor and review the PRs as we can.

webron avatar Apr 03 '18 17:04 webron

see also this comment in PR #2713

frantuma avatar May 04 '18 12:05 frantuma

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!

MichakrawSB avatar Mar 08 '26 19:03 MichakrawSB