Forum Discussion

gurunathkumar79's avatar
New Contributor
6 years ago

Swagger UI- Swagger UI is Sending Blank RequestBody Even though it is specified as optional

Hi All,
I have written a post request which is accepting requestbody as false.

@PostMapping(value = "/testPost")
@ApiOperation(value = "Testing post",
notes = "")
public void testPost(@RequestBody(required = false) @Valid Pojo pojo,
		     @RequestHeader(value = "type") String type) {



When iam trying to hit the endpoint using swagger-ui,swagger is sending an empty request body as shown below

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'type: test' -d '{}' 'http://localhost:8080/testpost'

 Seems like there is issue with swagger UI while handling if requestbody is false.

Any inputs or have faced similar kind of issue?

7 Replies