Apicurio / apicurio-codegen

Repository to hold some code generation utilities.
Apache License 2.0
4 stars 13 forks source link

Request body without required = true should not have the @NotNull annotation #293

Open danilopiazza opened 1 month ago

danilopiazza commented 1 month ago

Given a [request body(https://spec.openapis.org/oas/v3.0.3#request-body-object) with "required": false:

   "paths": {
      "/request-body/optional": {
         "post": {
            "requestBody": {
               ...
               "required": false
            },
            ...
         }
      }

when generating JAX-RS code with OpenApi2JaxRs, method parameters representing the request body have the @NotNull annotation, as if they were required:

  @Path("/optional")
  @POST
  @Consumes("application/json")
  void optionalRequestBody(@NotNull Content data);

I believe the @NotNull annotation should only be present when the request body has the "required": true property.

danilopiazza commented 1 month ago

I don't know whether the code generator should add a @Nullable annotation when required is false (or missing), or no annotation at all.