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

BeanValidation @NotNull on a request body parameter should mark the body parameter as a required parameter #1920

Open
xfh opened this issue Jul 17, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@xfh
Copy link

xfh commented Jul 17, 2024

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.

@MikeEdgar MikeEdgar added the enhancement New feature or request label Jul 18, 2024
@cristalp
Copy link
Contributor

The following worked for me:

@POST
public Response create(@Nonnull @NotNull @Valid @RequestBody Payload payload) {
    return Response.ok().build();
}

@cristalp
Copy link
Contributor

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.

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

3 participants