Skip to content

Conversation

@burneyy
Copy link
Contributor

@burneyy burneyy commented Jan 6, 2026

Pull Request

Description

When @NotEmpty or @NotBlank annotations are combined with @Schema(requiredMode = REQUIRED) or @Schema(requiredMode = NOT_REQUIRED), the minItems and minLength constraints are not being generated in the OpenAPI schema.

Root cause: The applyNotNullAnnotations flag was incorrectly gating the entire @NotEmpty/@NotBlank processing block. This flag is true only when requiredMode == AUTO, so when users explicitly set requiredMode to REQUIRED or NOT_REQUIRED, the validation constraints were completely skipped.

The fix: Separates the concerns:

  • minItems/minLength are always applied when @NotEmpty/@NotBlank are present
  • updateRequiredItem() is only called when applyNotNullAnnotations is true

This is a regression introduced between 2.2.40 and 2.2.41.

Fixes: #5032

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

See #5032

Daniel Berninghoff added 2 commits January 6, 2026 16:46
…requiredMode

When @notempty or @notblank annotations were combined with
@Schema(requiredMode = REQUIRED) or @Schema(requiredMode = NOT_REQUIRED),
the minItems and minLength constraints were not being generated in the
OpenAPI schema.

This was caused by the applyNotNullAnnotations flag incorrectly gating
the entire @NotEmpty/@notblank processing block. The flag should only
control whether the field is added to the required list, not whether
minItems/minLength are set.

The fix separates these concerns:
- minItems/minLength are always applied when @NotEmpty/@notblank are present
- updateRequiredItem() is only called when applyNotNullAnnotations is true

Fixes regression introduced between 2.2.40 and 2.2.41.
@burneyy burneyy changed the title Bug/notempty notblank with required fix: apply minItems/minLength from @NotEmpty/@NotBlank regardless of requiredMode Jan 6, 2026
@daniel-kmiecik
Copy link
Collaborator

@burneyy thanks for your contribution. Great work!

@daniel-kmiecik daniel-kmiecik merged commit 1dafa44 into swagger-api:master Jan 8, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: @NotEmpty and @NotBlank validation annotations ignored when combined with @Schema(requiredMode = ...)

2 participants