Skip to content
Merged
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 @@ -349,7 +349,7 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context
model = openapi31 ? primitiveType.createProperty31() : primitiveType.createProperty();
isPrimitive = true;
}
}
}

if (model == null) {
PrimitiveType primitiveType = PrimitiveType.fromType(type);
Expand Down Expand Up @@ -1841,7 +1841,7 @@ protected boolean applyBeanValidatorAnnotations(Schema property, Annotation[] an
}
}

if (annos.containsKey("javax.validation.constraints.NotEmpty") && applyNotNullAnnotations ) {
if (annos.containsKey("javax.validation.constraints.NotEmpty")) {
NotEmpty anno = (NotEmpty) annos.get("javax.validation.constraints.NotEmpty");
boolean apply = checkGroupValidation(anno.groups(), invocationGroups, acceptNoGroups);
if (apply) {
Expand All @@ -1863,11 +1863,13 @@ protected boolean applyBeanValidatorAnnotations(Schema property, Annotation[] an
modified = true;
}
}
modified = updateRequiredItem(parent, property.getName()) || modified;
if (applyNotNullAnnotations) {
modified = updateRequiredItem(parent, property.getName()) || modified;
}
}
}

if (annos.containsKey("javax.validation.constraints.NotBlank") && applyNotNullAnnotations ) {
if (annos.containsKey("javax.validation.constraints.NotBlank")) {
NotBlank anno = (NotBlank) annos.get("javax.validation.constraints.NotBlank");
boolean apply = checkGroupValidation(anno.groups(), invocationGroups, acceptNoGroups);
if (apply) {
Expand All @@ -1878,7 +1880,9 @@ protected boolean applyBeanValidatorAnnotations(Schema property, Annotation[] an
modified = true;
}
}
modified = updateRequiredItem(parent, property.getName()) || modified;
if (applyNotNullAnnotations) {
modified = updateRequiredItem(parent, property.getName()) || modified;
}
}
}
if (annos.containsKey("javax.validation.constraints.Min")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ public void testNotBlankNotEmptyWithRequiredModeNotRequired() {
assertFalse(model.getRequired() != null && model.getRequired().contains("notBlankNotRequired"));
assertFalse(model.getRequired() != null && model.getRequired().contains("notEmptyListNotRequired"));
assertFalse(model.getRequired() != null && model.getRequired().contains("notEmptySetNotRequired"));

// @NotBlank should generate minLength: 1
Schema notBlankSchema = (Schema) model.getProperties().get("notBlankNotRequired");
assertNotNull(notBlankSchema);
assertEquals(notBlankSchema.getMinLength(), Integer.valueOf(1));

// @NotEmpty should generate minItems: 1
ArraySchema listSchema = (ArraySchema) model.getProperties().get("notEmptyListNotRequired");
assertNotNull(listSchema);
assertEquals(listSchema.getMinItems(), Integer.valueOf(1));

ArraySchema setSchema = (ArraySchema) model.getProperties().get("notEmptySetNotRequired");
assertNotNull(setSchema);
assertEquals(setSchema.getMinItems(), Integer.valueOf(1));
}

@Test
Expand All @@ -193,6 +207,20 @@ public void testNotBlankNotEmptyWithRequiredModeRequired() {
assertTrue(model.getRequired().contains("notBlankRequired"));
assertTrue(model.getRequired().contains("notEmptyListRequired"));
assertTrue(model.getRequired().contains("notEmptySetRequired"));

// @NotBlank should generate minLength: 1
Schema notBlankSchema = (Schema) model.getProperties().get("notBlankRequired");
assertNotNull(notBlankSchema);
assertEquals(notBlankSchema.getMinLength(), Integer.valueOf(1));

// @NotEmpty should generate minItems: 1
ArraySchema listSchema = (ArraySchema) model.getProperties().get("notEmptyListRequired");
assertNotNull(listSchema);
assertEquals(listSchema.getMinItems(), Integer.valueOf(1));

ArraySchema setSchema = (ArraySchema) model.getProperties().get("notEmptySetRequired");
assertNotNull(setSchema);
assertEquals(setSchema.getMinItems(), Integer.valueOf(1));
}

class Family {
Expand Down
Loading