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

Request Body cannot be configured as optional #603

Closed
sobafuchs opened this issue Apr 23, 2020 · 0 comments
Closed

Request Body cannot be configured as optional #603

sobafuchs opened this issue Apr 23, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@sobafuchs
Copy link

Describe the bug

  • If you are reporting a bug, please help to speed up problem diagnosis by providing as much information as possible:
  • A clear and concise description of what the bug is: the title of an issue is not enough
    The current behavior seems to parse whether or not a request body is optional from one of several values, one of which is the spring boot @RequestBody annotation. The problem is, even if you set required to false, springdoc-openapi still registers it as required. I've looked at the code and I suspect the reason is that it simply checks if the @RequestBody annotation exists but doesn't check the required value.

To Reproduce
Steps to reproduce the behavior:

  • What version of spring-boot you are using?

2.2.6

  • What modules and versions of springdoc-openapi are you using?

org.springdoc:springdoc-openapi-ui:1.3.4
org.springdoc:springdoc-openapi-kotlin:1.3.4

  • What is the actual and the expected result using OpenAPI Description (yml or json)?

Sorry I don't understand the question

  • Provide with a sample code (HelloController) or Test that reproduces the problem

You can configure any POST endpoint and set the @RequestBody(required = false) and it will still display the request body as required.

@RestController
class TestController {
    @PostMapping("/lol")
    public void test(@RequestBody(required = false) Body body) { }

    public class Body {
        public String field;
    }
}

In the screenshots section, I've attached how the UI still displays the body as required, even though its set to false

Expected behavior
The UI should display the request body as not required.

  • What is the expected result using OpenAPI Description (yml or json)?
openapi: 3.0.1
paths:
  /lol:
    post:
      tags:
      - External Order Number API
      operationId: test
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Body'
        required: false

Screenshots
If applicable, add screenshots to help explain your problem.
Screenshot from 2020-04-23 13-40-05

@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants