[BUG] [spring] Request Body is not parsed correctly when using oas3 option
Created by: WIStudent
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I am trying to use the new oas3 annotations introduced in https://github.com/OpenAPITools/openapi-generator/pull/9775 using the 5.3.1-SNAPSHOT version and the <oas3>true</oas3>
option. I ran into the issue that the request body is not getting parsed correctly, the fields of the LogEntry
object are all null. Adding the @org.springframework.web.bind.annotation.RequestBody
annotation to the generated code like this PR does fixes it.
The main goal of this issue is to raise awareness for this problem and the existing PR that fixes it.
openapi-generator version
5.3.1-SNAPSHOT
OpenAPI declaration file content or url
openapi: "3.0.2"
info:
title: title
description: description
version: "1.0"
paths:
"/app/log":
summary: Add a new log entry
post:
tags:
- log
operationId: log
requestBody:
$ref: '#/components/requestBodies/LogBody'
responses:
'200':
description: ok, the entry was NOT created because the level was too low
'201':
description: created
'401':
$ref: '#/components/responses/UnauthorizedError'
components:
responses:
UnauthorizedError:
description: Access token is missing or invalid
requestBodies:
LogBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/LogEntry'
schemas:
LogEntry:
type: object
properties:
level:
type: string
enum:
- debug
- info
- warning
- error
message:
type: string
required:
- level
- message
Generation Details
I am using the maven plugin, here is the configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>5.3.1-SNAPSHOT</version>
<executions>
<execution>
<id>openapi-generator-server</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>openapi-spec.yaml</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>com.example.openapi.api</apiPackage>
<modelPackage>com.example.openapi.model</modelPackage>
<supportingFilesToGenerate>
ApiUtil.java
</supportingFilesToGenerate>
<configOptions>
<delegatePattern>true</delegatePattern>
<dateLibrary>java8</dateLibrary>
<oas3>true</oas3>
<useSpringController>true</useSpringController>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/9775 https://github.com/OpenAPITools/openapi-generator/pull/10766
Suggest a fix
Merge https://github.com/OpenAPITools/openapi-generator/pull/10766