Description of the problem/issue
When a field is annotated with both a Bean Validation annotation (@NotEmpty or @NotBlank) and @Schema(requiredMode = ...), the validation constraints are not reflected in the generated OpenAPI schema:
@NotEmpty on collections should generate minItems: 1
@NotBlank on strings should generate minLength: 1
This works correctly when:
- Only the validation annotation is present (no
@Schema)
@Schema is present but without requiredMode (e.g., only description)
This is broken when:
@Schema(requiredMode = REQUIRED) is combined with the validation annotation
@Schema(requiredMode = NOT_REQUIRED) is combined with the validation annotation
Affected Version
- Broken in: 2.2.41 ❌
- Works in: 2.2.40 ✅
Steps to Reproduce
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import java.util.Set;
public class ParentDto {
// ❌ BUG: minItems is null (should be 1)
@NotEmpty
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
public Set<String> requiredItems;
// ✅ WORKS: minItems is 1
@NotEmpty
public Set<String> optionalItems;
// ❌ BUG: minItems is null (should be 1)
@NotEmpty
@Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
public Set<String> nonRequiredItems;
// ✅ WORKS: minItems is 1
@NotEmpty
@Schema(description = "Items with description only")
public Set<String> itemsWithDescription;
// ❌ BUG: minLength is null (should be 1)
@NotBlank
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
public String requiredString;
// ✅ WORKS: minLength is 1
@NotBlank
public String optionalString;
// ❌ BUG: minLength is null (should be 1)
@NotBlank
@Schema(requiredMode = Schema.RequiredMode.NOT_REQUIRED)
public String nonRequiredString;
// ✅ WORKS: minLength is 1
@NotBlank
@Schema(description = "String with description only")
public String stringWithDescription;
}
Expected Behavior
| Field |
Annotations |
Expected minItems/minLength |
requiredItems |
@NotEmpty + @Schema(requiredMode=REQUIRED) |
1 |
optionalItems |
@NotEmpty |
1 |
nonRequiredItems |
@NotEmpty + @Schema(requiredMode=NOT_REQUIRED) |
1 |
itemsWithDescription |
@NotEmpty + @Schema(description=...) |
1 |
requiredString |
@NotBlank + @Schema(requiredMode=REQUIRED) |
1 |
optionalString |
@NotBlank |
1 |
nonRequiredString |
@NotBlank + @Schema(requiredMode=NOT_REQUIRED) |
1 |
stringWithDescription |
@NotBlank + @Schema(description=...) |
1 |
Actual Behavior
| Field |
Annotations |
Actual minItems/minLength |
Status |
requiredItems |
@NotEmpty + @Schema(requiredMode=REQUIRED) |
null |
❌ |
optionalItems |
@NotEmpty |
1 |
✅ |
nonRequiredItems |
@NotEmpty + @Schema(requiredMode=NOT_REQUIRED) |
null |
❌ |
itemsWithDescription |
@NotEmpty + @Schema(description=...) |
1 |
✅ |
requiredString |
@NotBlank + @Schema(requiredMode=REQUIRED) |
null |
❌ |
optionalString |
@NotBlank |
1 |
✅ |
nonRequiredString |
@NotBlank + @Schema(requiredMode=NOT_REQUIRED) |
null |
❌ |
stringWithDescription |
@NotBlank + @Schema(description=...) |
1 |
✅ |
Additional Context
Checklist
Description of the problem/issue
When a field is annotated with both a Bean Validation annotation (
@NotEmptyor@NotBlank) and@Schema(requiredMode = ...), the validation constraints are not reflected in the generated OpenAPI schema:@NotEmptyon collections should generateminItems: 1@NotBlankon strings should generateminLength: 1This works correctly when:
@Schema)@Schemais present but withoutrequiredMode(e.g., onlydescription)This is broken when:
@Schema(requiredMode = REQUIRED)is combined with the validation annotation@Schema(requiredMode = NOT_REQUIRED)is combined with the validation annotationAffected Version
Steps to Reproduce
Expected Behavior
minItems/minLengthrequiredItems@NotEmpty+@Schema(requiredMode=REQUIRED)1optionalItems@NotEmpty1nonRequiredItems@NotEmpty+@Schema(requiredMode=NOT_REQUIRED)1itemsWithDescription@NotEmpty+@Schema(description=...)1requiredString@NotBlank+@Schema(requiredMode=REQUIRED)1optionalString@NotBlank1nonRequiredString@NotBlank+@Schema(requiredMode=NOT_REQUIRED)1stringWithDescription@NotBlank+@Schema(description=...)1Actual Behavior
minItems/minLengthrequiredItems@NotEmpty+@Schema(requiredMode=REQUIRED)nulloptionalItems@NotEmpty1nonRequiredItems@NotEmpty+@Schema(requiredMode=NOT_REQUIRED)nullitemsWithDescription@NotEmpty+@Schema(description=...)1requiredString@NotBlank+@Schema(requiredMode=REQUIRED)nulloptionalString@NotBlank1nonRequiredString@NotBlank+@Schema(requiredMode=NOT_REQUIRED)nullstringWithDescription@NotBlank+@Schema(description=...)1Additional Context
Checklist