-
- Notifications
You must be signed in to change notification settings - Fork 548
Description
Description
Springdoc-openapi does not support the annotation @jakarta.annotation.Nonnull
.
There are a lot of NotNull
and NonNull
annotations (mind letter case) from different issuers, but @jakarta.annotation.Nonnull
is the late arrived but official Java solution to mark non null fields.
What is the actual result using OpenAPI
When using a java record with NonNull/NotNull Annotations, springdoc-openapi will not generate a required field for @jakarta.annotation.Nonnull String jakartaAnnotationNonnull
public record HelloWorldJson( String message, @jakarta.annotation.Nonnull String jakartaAnnotationNonnull, @jakarta.validation.constraints.NotNull String jakartaValidationConstraintsNotNull, @org.springframework.lang.NonNull String orgSpringframeworkLangNonNull ) { }
api-docs.json:
{ [...] "components": { "schemas": { "HelloWorldJson": { "type": "object", "properties": { "message": { "type": "string" }, "jakartaAnnotationNonnull": { "type": "string" }, "jakartaValidationConstraintsNotNull": { "type": "string" }, "orgSpringframeworkLangNonNull": { "type": "string" } }, "required": [ "jakartaValidationConstraintsNotNull", "orgSpringframeworkLangNonNull" ] } } } }
Description of the solution
Springdoc-openapi should create a required field for the annotation @jakarta.annotation.Nonnull
As fare as I understand in SchemaUtils.java Line 56 the String "Nonnull"
should be added.
Old Line
public static final List<String> ANNOTATIONS_FOR_REQUIRED = Arrays.asList("NotNull", "NonNull", "NotBlank", "NotEmpty")
New Line
public static final List<String> ANNOTATIONS_FOR_REQUIRED = Arrays.asList("NotNull", "NonNull", "Nonnull", "NotBlank", "NotEmpty")
Please unterstand, that it is not possible for me to test my solution. I never worked this deep with Gradle Plugins.
Expected result using OpenAPI
{ [...] "components": { "schemas": { "HelloWorldJson": { "type": "object", "properties": { "message": { "type": "string" }, "jakartaAnnotationNonnull": { "type": "string" }, "jakartaValidationConstraintsNotNull": { "type": "string" }, "orgSpringframeworkLangNonNull": { "type": "string" } }, "required": [ "jakartaAnnotationNonnull", "jakartaValidationConstraintsNotNull", "orgSpringframeworkLangNonNull" ] } } } }