Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [spring] Request Body is not parsed correctly when using oas3 option #11007

Closed
4 of 6 tasks
WIStudent opened this issue Dec 1, 2021 · 1 comment
Closed
4 of 6 tasks

Comments

@WIStudent
Copy link

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 #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

#9775
#10766

Suggest a fix

Merge #10766

@wing328
Copy link
Member

wing328 commented Jan 2, 2022

Closed via #11181. Please pull the latest master to give it another try.

@wing328 wing328 closed this as completed Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants