Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default response code added #2854

Closed
2 tasks done
StefanSchubert opened this issue Jan 8, 2019 · 3 comments
Closed
2 tasks done

default response code added #2854

StefanSchubert opened this issue Jan 8, 2019 · 3 comments

Comments

@StefanSchubert
Copy link

Please take the time to search the repository, if your question has already been asked or answered.

  • What version of the library are you using? Is it the latest version?

         <dependency>
              <groupId>io.springfox</groupId>
              <artifactId>springfox-swagger-ui</artifactId>
              <version>2.9.2</version>
              <scope>compile</scope>
          </dependency>
    
          <dependency>
              <groupId>io.springfox</groupId>
              <artifactId>springfox-swagger2</artifactId>
              <version>2.9.2</version>
              <scope>compile</scope>
          </dependency>
    

What kind of issue is this?

  • Bug report. If you’ve found a bug, spend the time to write a failing test. Bugs with tests or
    steps to reproduce get fixed faster. Here’s an example:

This one here will also list an HTTP 200 as possible result in the generated swaggerdoc

    @ApiOperation("/register")
    @ApiResponses({
            @ApiResponse(code = 201, message = "Created - extract user Token from header for further requests.", response = UserRegConfirmationTo.class),
            @ApiResponse(code = 412, message = "Captcha Validation code was invalid. Registration failed.", response = HttpStatus.class),
            @ApiResponse(code = 503, message = "Backend-Service not available, please try again later.", response = HttpStatus.class),
            @ApiResponse(code = 415, message = "Wrong media type - Did you used a http header with MediaType=APPLICATION_JSON_VALUE ?", response = HttpStatus.class),
            @ApiResponse(code = 409, message = "Conflict - username and/or emailaddress already exists.", response = NewRegistrationTO.class),
            @ApiResponse(code = 400, message = "JSON Syntax invalid. Please check your paylod.", response = HttpStatus.class)
    })
    @RequestMapping(value = {"/register"}, method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResponseEntity<UserRegConfirmationTo> createUser(@RequestBody NewRegistrationTO pRegistrationUserTo) {

- [x] spring xml/java config that is relevant

Though I do suppress the generation of default codes:

    @Bean
    public Docket documentation() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    .build()
                .pathMapping("/")
                // Suppress generation of default return codes, but have in mind, that you need to take care
                // of @APIResponses(...) on your controller then.
                .useDefaultResponseMessages(false)
                .apiInfo(metadata());
    }

- [x] if you have a repo that demonstrates the issue for bonus points! 

See sabi

@StefanSchubert
Copy link
Author

In my case I could solve the issue by adding also a
@ResponseStatus(HttpStatus.ACCEPTED)
for instance.

However I would have expected that:
.useDefaultResponseMessages(false)
would do the same trick. So this toogle seems to be inactive.

@Tristan107
Copy link

Could you just tell us how "adding @ResponseStatus(HttpStatus.ACCEPTED)" solves the issue for you ? Where do you add it ? and how adding a "HTTP 202" status code removes the "HTTP 200" which bothers you ?

@StefanSchubert
Copy link
Author

StefanSchubert commented Sep 12, 2019

This is long ago, but given my examples I had the default code, which was not explicitly listed within the @ApiResponses.

It just happened that after adding the @ResponseStatus(HttpStatus.ACCEPTED)
swaggerdoc no longer showed the 200 as default response code, which was bothering me.

For the place where I added it you just need to follow the referenced sabi ticket 37 above and the commit point which closed it.

And yes one might think that HTTP-200 as default response code should be expected in APIs.
But I liked it to be more specific to answer with a 201 (created) code - for the creation use-case.
And I guess that the reason, why the
.useDefaultResponseMessages(false)
switch was thought for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants