I have integrated swagger
to my Spring Boot project using SpringFox build and it work for my GET API. However on my POST API which requires the request in application/json
format, the swagger-ui doesn't set the header.
My Code:
@PostMapping(value="/login", consumes="application/json", produces="application/json")
public WsResponse login(UserLoginRequest requestBody) throws Exception {
validateAuthToken(requestBody.getId(), requestBody.getToken());
return serviceWs.login(requestBody);
}
The command generated from swagger-ui:
curl -X POST "http://localhost:8080/api/login?token=2342343324&username=23434&password=123" -H "accept: application/json"
Note that the header "Content-Type" is not set and thus backend is giving an error when trying to call.
The issue is similar to this post but there's no resolution, any help is appreciated.
Try putting application/json
within the braces:
Note: Works for me for springfox-swagger2 and springfox-swagger-ui v2.8.0