Search code examples
spring-bootswaggerswagger-2.0springfoxassertj

void operation requires 'produces' swagger definition in assertj-swagger


I have the following Spring Boot (1.3.1) @RestController defined:

@RequestMapping(value = "/blah", method = DELETE)
@ResponseStatus(NO_CONTENT)
public void blah() {...}

and am using assertj-swagger to validate the above against the following swagger specification:

'/blah':
  delete:

Validation (assertion) of the implemented operation fails for the following reason:

[Checking 'produces' of 'DELETE' operation of path '/blah'] 
 Expecting null or empty but was:<["*/*"]>

But I can't understand why a produces MediaType.ALL is required when it's a void method we're attempting to describe with Swagger?

Any thoughts would be greatly appreciated, seems extraneous to have to add this to all of our documented APIs...

Thanks and regards.


Solution

  • Http is a request/response protocol. So even if your operation returns a void, there is still a http response; even if it has a Content-Length of 0 (void). Thats the reason its modeled as a MediaType.ALL (read any media type or no particular media type)