5001: Add support for @Nullable annotations in OpenAPI 3.1 schemas#5018
5001: Add support for @Nullable annotations in OpenAPI 3.1 schemas#5018ewaostrowska merged 2 commits intoswagger-api:masterfrom
Conversation
| return schema.nullable(); | ||
| } | ||
| if (annotations != null) { | ||
| for (Annotation ann : annotations) { |
There was a problem hiding this comment.
is this loop needed?
if (annotations != null) {
return Arrays.stream(annotations).anyMatch(annotation ->
NULLABLE_ANNOTATIONS.contains(annotation.annotationType().getSimpleName()));
}
There was a problem hiding this comment.
Yes, it is. Not sure how to write it more elegant than this. Feel free to correct it, please if you prefer
There was a problem hiding this comment.
This version here removes redundancy. The loop variable ann was never used - it was just a mechanism to trigger the stream operation
|
@ronodhirSoumik will this PR make its way to the release? If so any eta? |
cab731b to
b93e8be
Compare
|
@zdary thanks for providing PR for this issue. As @ronodhirSoumik was suggesting the loop and stream was not necessary effective there so I have introduced a small change. Otherwise this is great :) Solves as well #4555 which community especially seemed to waiting for. It will make it to the next release. |
| } | ||
| if (annotations != null) { | ||
| for (Annotation annotation : annotations) { | ||
| if (NULLABLE_ANNOTATIONS.contains(annotation.annotationType().getSimpleName())) { |
There was a problem hiding this comment.
NULLABLE_ANNOTATIONS should be a Set for efficient contains
|
this fix only worked for java native attributes (e.g. Strings). But if you are using objects and mark them with Nullable, the type "object" is somehow not being added, but being replaced by "null". I created a seperate bug ticket for it with #5077 , but mainly the issue is visible in the following code snippets For instance: instead of |
Pull Request
Thank you for contributing to swagger-core!
Please fill out the following information to help us review your PR efficiently.
Description
Enhanced schema generation by recognizing
Introduced a test case to validate the behavior and ensure backward compatibility with explicit @Schema annotations.
Fixes: #5001 , #4555
Type of Change
Checklist
Screenshots / Additional Context