question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

200 Responses Not Overwritten at the Class Level

See original GitHub issue
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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
webroncommented, Apr 3, 2018

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

0reactions
frantumacommented, May 4, 2018

see also this comment in PR #2713

Read more comments on GitHub >

github_iconTop Results From Across the Web

arcpy - Output not overwritten despite "overwriteOutput = True"
1 Answer 1 · close any MXDs that are accessing the feature class · reboot your python editor · sometimes even rebooting your...
Read more >
Enable APIResponse auto-generation with annotations present
Auto generate default responses if the respective responseCode (200 for non-void methods, 201/204 for void methods) has not been explicitly defined. Although ...
Read more >
Is there a way to override class variables in Java?
In short, no, there is no way to override a class variable. You do not override class variables in Java you hide them....
Read more >
Top 10 Most Common Spring Framework Mistakes - Toptal
In case you are not very familiar with Spring Boot but would still like to try out some ... on higher level details–...
Read more >
Describing Responses - Swagger
paths: /ping: get: produces: - application/json; responses: 200: description: OK ... The global list can be overridden on the operation level.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found