I have a swagger spec
/authentication-service/authorize:
post:
tags:
- Auth
summary: Authorize
requestBody:
content:
application/x-www-form-urlencoded:
schema:
properties:
redirect_uri:
type: string
example: http://localhost
client_id:
type: string
example: asdf
encoding:
redirect_uri:
allowReserved: true
client_id:
allowReserved: true
parameters:
- name: Content-Type
in: header
schema:
type: string
example: application/x-www-form-urlencoded
responses:
'200':
description: Successful response
content:
application/json: {}
as you can see it is a post
with content type of x-www-form-urlencoded
with a requestBody
.
This is what org.openapitools:openapi-generator-maven-plugin:6.0.1
generates out of that:
@Operation(
operationId = "authenticationServiceAuthorizeGet",
summary = "API-AS02 Authorize",
tags = { "Auth" },
responses = {
@ApiResponse(responseCode = "200", description = "Successful response")
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/authentication-service/authorize",
produces = "application/json",
consumes = "application/x-www-form-urlencoded"
)
ResponseEntity<Void> authenticationServiceAuthorizePost(
@Parameter(name = "Content-Type", description = "") @RequestHeader(value = "Content-Type", required = false) String contentType,
@Parameter(name = "redirect_uri", description = "") @Valid @RequestParam(value = "redirect_uri", required = false) String redirectUri,
@Parameter(name = "client_id", description = "") @Valid @RequestParam(value = "client_id", required = false) String clientId,
...more params generated...
);
Now when I finally try to use this feign client, it compiles following request for me:
[POST] to [https://api-us-dev<obfuscatedURL>/authentication-service/authorize?redirect_uri=http%3A//localhost&client_id=oidc_pkce....
So as you can see the compiled feign client calls POST request with encoded query params that were delcared as requestBody
in the spec above.
This request is being rejected from the server. The server is avaiting those params to be encoded in the body of the request.
However that's how openapi generator & feign client does it for me.
2 questions on that:
- Is it generated correctly?
- Regardless of it being correct or not, I need to send payload in the body as per server impl. Can you point out to me how to change swagged spec for it to be encoded as body k=v pairs?
How to POST form-url-encoded data with Spring Cloud Feign
does not do it for me, the parameters are still encoded in the query instead of body