cancel
Showing results for 
Search instead for 
Did you mean: 

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

New Contributor

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")
@ResponseStatus(ACCEPTED)
@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 7
Moderator

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

Which version of Swagger UI do you use?

New Contributor

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

Iam using 

2.4.0

 

Moderator

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

That sounds like it might be the version of Springfox (and it's an old one), which is not one of the projects we maintain. Without knowing the version of Swagger UI that you use, it'll be challenging for us to provide further assistance.

 

You can refer to https://github.com/swagger-api/swagger-ui/blob/master/docs/usage/version-detection.md for more details on how to find the version that you use.

New Contributor

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

Hi 

Below are the swagger versions that iam using in my spring boot application

"io.springfox:springfox-swagger2:2.4.0"
'io.springfox:springfox-swagger-ui:2.4.0'

 

Moderator

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

Springfox provides their own wrapped version of Swagger UI. It is not maintained by us, and we don't know which version is included with it. Please follow the instruction in the link previously shared to find out the actual version of Swagger UI you're using.

New Contributor

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

Hi @RonRatovsky 

 

Have gone through the link you provided and found the exact version of swagger-ui in js file.
Below is the version that is used

v2.2.6
Moderator

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

Thanks for the details.

 

Version 2.2.6 of Swagger UI is quite old, and we don't really support it. We understand you use it as provided from Springfox. If you can't update your Springfox version, you may still be able to update the Swagger UI webjar to the latest version. Since Springfox is not our project, we're not quite sure regarding compatibility.

 

If that doesn't work, you can use Swagger UI directly as part of your project and it should resolve the issue you're describing. You can take a look at our own samples to see how we integrate Swagger UI with the code. You can also run it through a docker image, or just clone it and open the index.html file.

New Here?
Join us and watch the welcome video:
Watch the new Interview
Top Kudoed Authors