I am trying to find out why my Spring server generated by OpenAPI generator properly accepts requests with "user=foo", "password=bar" in a Postman POST request with x-www-form-urlencoded body (as expected), but the Swagger page embedded in the server using springfox-swagger2 generates a
curl -X 'POST' \
'http://localhost:8080/v1.0/login?username=foo&password=bar' \
-H 'accept: */*' \
-d ''
request, which returns a 415 Unsupported Media Type. For the record, the generated Java client from the OpenAPI specification shows the same behavior. The generated Java method looks like:
@Operation(
operationId = "loginPost",
responses = {
@ApiResponse(responseCode = "200", description = "User successfully logged in."),
@ApiResponse(responseCode = "400", description = "User login failed."),
@ApiResponse(responseCode = "415", description = "Unsupported Media Type")
}
)
@RequestMapping(
method = RequestMethod.POST,
value = "/login",
consumes = { "application/x-www-form-urlencoded" }
)
default ResponseEntity<Void> loginPost(
@Parameter(name = "username", description = "", required = true) @Valid @RequestParam(value = "username", required = true) String username,
@Parameter(name = "password", description = "", required = true) @Valid @RequestParam(value = "password", required = true) String password
) {
return getDelegate().loginPost(username, password);
}
(automatically generated, my code is in the getDelegate() delegate).
My guess is that the attributes on the generated Java code is slightly off, so I would like to find out what needs to be fixed so I can report a bug to the OpenAPI generator project, hopefully with a patch.
What is the reason for what I see?