Skip to content

5001: Add support for @Nullable annotations in OpenAPI 3.1 schemas#5018

Merged
ewaostrowska merged 2 commits intoswagger-api:masterfrom
zdary:5001
Feb 20, 2026
Merged

5001: Add support for @Nullable annotations in OpenAPI 3.1 schemas#5018
ewaostrowska merged 2 commits intoswagger-api:masterfrom
zdary:5001

Conversation

@zdary
Copy link
Contributor

@zdary zdary commented Nov 17, 2025

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

  • @nullable annotations as nullable and adding "null" to the type array in OpenAPI 3.1.
  • nullable = true in schema and adding "null" to the type array in OpenAPI 3.1.

Introduced a test case to validate the behavior and ensure backward compatibility with explicit @Schema annotations.

Fixes: #5001 , #4555

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

return schema.nullable();
}
if (annotations != null) {
for (Annotation ann : annotations) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this loop needed?

if (annotations != null) {
    return Arrays.stream(annotations).anyMatch(annotation ->
                NULLABLE_ANNOTATIONS.contains(annotation.annotationType().getSimpleName()));
 }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is. Not sure how to write it more elegant than this. Feel free to correct it, please if you prefer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version here removes redundancy. The loop variable ann was never used - it was just a mechanism to trigger the stream operation

@zdary zdary changed the base branch from master to backslashes-issue January 31, 2026 03:26
@zdary
Copy link
Contributor Author

zdary commented Feb 15, 2026

@ronodhirSoumik will this PR make its way to the release? If so any eta?

@ewaostrowska ewaostrowska changed the base branch from backslashes-issue to master February 19, 2026 14:20
@ewaostrowska ewaostrowska changed the base branch from master to backslashes-issue February 19, 2026 14:22
@ewaostrowska ewaostrowska changed the base branch from backslashes-issue to master February 19, 2026 14:23
Enhanced schema generation by recognizing @nullable annotations as nullable and adding "null" to the type array in OpenAPI 3.1. Introduced a test case to validate the behavior and ensured backward compatibility with explicit @Schema annotations.
@ewaostrowska ewaostrowska force-pushed the 5001 branch 2 times, most recently from cab731b to b93e8be Compare February 20, 2026 07:45
@ewaostrowska ewaostrowska merged commit ddb11b1 into swagger-api:master Feb 20, 2026
7 checks passed
@ewaostrowska
Copy link
Contributor

ewaostrowska commented Feb 20, 2026

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants