I am using openapi 3.0.3 and I am trying to write an API which accepts data in the form of 'application/x-www-form-urlencoded' by api specification looks something like this:
/path/to/api/v1/testApi:
post:
tags:
- Extract data
operationId: "testApi"
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
effectiveDate:
type: string
required: true
using the above specification when an api is generated automatically, the request is accepted by the api as @RequestParam.
ResponseEntity<String> testAPi(
@Parameter(name = "effectiveDate", description = "") @Valid @RequestParam(value = "effectiveDate", required = false) String effectiveDate
) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
Is there a possibility to make it accept @RequestBody instead of @RequestParam with the same x-www-form-urlencoded data?
It is not possible to force an open-api POST requestBody with application/x-www-form-urlencoded content to generate a Java Controller method that accepts a @RequestBody instead of @RequestParam.
The reason is that the The Servlet API requires ServletRequest.getParameter() methods to support form field access only for HTTP POST.- from spring-framework/docs