BeanValidation @NotNull on a request body parameter should mark the body parameter as a required parameter
BeanValidation's @NotNull annotation integrates seamlessly into openapi schema generation - I much appreciated feature.
Unfortunately, there is an inconsistency regarding @NotNull and method parameters.
The following endpoint doesn't mark the input parameter Payload as required:
@POST
public Response create(@Nonnull @NotNull @Valid Payload payload) {
return Response.ok().build();
}
generated schema:
post:
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Payload"
Manually adding @RequestBody(required = true) the the create method yields in the desired output:
post:
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Payload"
required: true
It would be really nice, if a @NotNull annotation on a body parameter automatically added the required: true flag.
The following worked for me:
@POST
public Response create(@Nonnull @NotNull @Valid @RequestBody Payload payload) {
return Response.ok().build();
}
I'm sorry, I was wrong (probably issues with dependencies). It doesn't work the way I wrote, the request body is not generated as required.
@xfh , @cristalp - this should no longer be an issue as of version 4.0. Request bodies are marked as required: true by default (not due to the not-null constraint).
Thanks, works as described.
Since version 4.0 makes request bodies required: true by default, it no longer would make sense to set it as a result of @NotNull. I will go ahead and close this issue, but please comment or re-open if you think I'm overlooking something.