I've encountered an issue with my API-first swagger client/server setup where POST request body parameters are not being transferred correctly. The Spring (4.3.14.RELEASE) server is receiving null values in the @RequestBody parameter of the POST request.
The discrepancy lies in how requests are sent over SwaggerUI versus a generated typescript client. SwaggerUI passes object fields as query parameters, which Spring handles properly, while the typescript client sends data over the json body resulting in null values on the server side.
It appears that the autogenerated client is sending parameters in the body, whereas the autogenerated server expects them in the query.
The snippet from the Swagger specifications:
/project:
post:
security:
- Bearer: []
tags:
- Project
summary: Create new project
operationId: createProject
consumes:
- "application/json"
- "text/json"
parameters:
- name: project
in: body
description: project value
schema:
$ref: '#/definitions/ProjectRequestDTO'
responses:
'200':
description: Successful response
schema:
$ref: '#/definitions/ProjectDTO'
default:
description: Bad requst
The resulting Spring MVC method is defined as follows:
ApiOperation(value = "Create new project", nickname = "createHachathon", notes = "", response = ProjectDTO.class, authorizations = {
@Authorization(value = "Bearer")
}, tags={ "Project", })
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successful response", response = ProjectDTO.class),
@ApiResponse(code = 200, message = "Bad requst") })
@RequestMapping(value = "/project",
consumes = { "application/json", "text/json" },
method = RequestMethod.POST)
default ResponseEntity<ProjectDTO> createHachathon(@ApiParam(value = "project value" ) @Valid @RequestBody ProjectRequestDTO project) {
When I send a request from typescript using a manually modified client (added title parameter for demonstration purposes), it looks like this:
return this.httpClient.post<ProjectDTO>(`${this.basePath}/project?title=hello`,
In the Chrome console, the resulting request is displayed as shown here: https://i.sstatic.net/ZzID4.png
Unfortunately, Spring only receives the values passed via query parameters and not those sent through the request body:
https://i.sstatic.net/EdY4F.png
Please assist me in resolving this issue to ensure that my swagger-codegen-maven-plugin 2.3.1 generates a client/server swagger API that transfers data seamlessly.