Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1803,7 +1803,7 @@ protected boolean applyBeanValidatorAnnotations(Schema property, Annotation[] an
}
}

if (annos.containsKey("javax.validation.constraints.NotEmpty")) {
if (annos.containsKey("javax.validation.constraints.NotEmpty") && applyNotNullAnnotations ) {
NotEmpty anno = (NotEmpty) annos.get("javax.validation.constraints.NotEmpty");
boolean apply = checkGroupValidation(anno.groups(), invocationGroups, acceptNoGroups);
if (apply) {
Expand All @@ -1829,7 +1829,7 @@ protected boolean applyBeanValidatorAnnotations(Schema property, Annotation[] an
}
}

if (annos.containsKey("javax.validation.constraints.NotBlank")) {
if (annos.containsKey("javax.validation.constraints.NotBlank") && applyNotNullAnnotations ) {
NotBlank anno = (NotBlank) annos.get("javax.validation.constraints.NotBlank");
boolean apply = checkGroupValidation(anno.groups(), invocationGroups, acceptNoGroups);
if (apply) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public void testRequiredProperty() {
assertTrue(model.getRequired().contains("modeRequired"));
assertFalse(model.getRequired().contains("modeNotRequired"));
assertFalse(model.getRequired().contains("modeNotRequiredWithAnnotation"));
assertFalse(model.getRequired().contains("modeNotRequiredWithAnnotationForNotBlank"));
assertFalse(model.getRequired().contains("modeNotRequiredWithAnnotationForNotEmpty"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import io.swagger.v3.oas.annotations.media.Schema;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;

import java.util.List;
import java.util.Optional;

public class RequiredFields {
Expand Down Expand Up @@ -42,4 +46,12 @@ public class RequiredFields {
@Schema(description = "mode not required with annotation", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@NotNull
public Long modeNotRequiredWithAnnotation;

@Schema(description = "mode not required with annotation for NotBlank", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@AnderData Please also add the same cases with RequiredMode.REQUIRED to check if your change works as expected.

@NotBlank
public String modeNotRequiredWithAnnotationForNotBlank;

@Schema(description = "mode not required with annotation for NotEmpty", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
@NotEmpty
public List<String> modeNotRequiredWithAnnotationForNotEmpty;
}
Loading