Closed
Description
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 tofalse
,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 therequired
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.