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 @@ -65,7 +65,7 @@
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.media.UUIDSchema;
import io.swagger.v3.oas.models.media.XML;
import javax.validation.constraints.Email;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
Expand All @@ -80,6 +80,11 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import javax.validation.constraints.Email;
import javax.validation.constraints.Positive;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Negative;
import javax.validation.constraints.NegativeOrZero;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
Expand Down Expand Up @@ -1901,6 +1906,40 @@ protected boolean applyBeanValidatorAnnotations(Schema property, Annotation[] an
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.Positive")) {
Positive anno = (Positive) annos.get("javax.validation.constraints.Positive");
boolean apply = checkGroupValidation(anno.groups(), invocationGroups, acceptNoGroups);
if (apply && isNumberSchema(property)) {
property.setMinimum(BigDecimal.ZERO);
property.setExclusiveMinimum(true);
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.PositiveOrZero")) {
PositiveOrZero anno = (PositiveOrZero) annos.get("javax.validation.constraints.PositiveOrZero");
boolean apply = checkGroupValidation(anno.groups(), invocationGroups, acceptNoGroups);
if (apply && isNumberSchema(property)) {
property.setMinimum(BigDecimal.ZERO);
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.Negative")) {
Negative anno = (Negative) annos.get("javax.validation.constraints.Negative");
boolean apply = checkGroupValidation(anno.groups(), invocationGroups, acceptNoGroups);
if (apply && isNumberSchema(property)) {
property.setMaximum(BigDecimal.ZERO);
property.setExclusiveMaximum(true);
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.NegativeOrZero")) {
NegativeOrZero anno = (NegativeOrZero) annos.get("javax.validation.constraints.NegativeOrZero");
boolean apply = checkGroupValidation(anno.groups(), invocationGroups, acceptNoGroups);
if (apply && isNumberSchema(property)) {
property.setMaximum(BigDecimal.ZERO);
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.Size")) {
Size anno = (Size) annos.get("javax.validation.constraints.Size");
boolean apply = checkGroupValidation(anno.groups(), invocationGroups, acceptNoGroups);
Expand Down Expand Up @@ -2017,6 +2056,32 @@ protected boolean applyBeanValidatorAnnotationsNoGroups(Schema property, Annotat
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.Positive")) {
if (isNumberSchema(property)) {
property.setMinimum(BigDecimal.ZERO);
property.setExclusiveMinimum(true);
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.PositiveOrZero")) {
if (isNumberSchema(property)) {
property.setMinimum(BigDecimal.ZERO);
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.Negative")) {
if (isNumberSchema(property)) {
property.setMaximum(BigDecimal.ZERO);
property.setExclusiveMaximum(true);
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.NegativeOrZero")) {
if (isNumberSchema(property)) {
property.setMaximum(BigDecimal.ZERO);
modified = true;
}
}
if (annos.containsKey("javax.validation.constraints.Size")) {
Size size = (Size) annos.get("javax.validation.constraints.Size");
if (isNumberSchema(property)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import javax.validation.constraints.Positive;
import javax.validation.constraints.PositiveOrZero;
import javax.validation.constraints.Negative;
import javax.validation.constraints.NegativeOrZero;
import java.util.List;
import java.util.Optional;

Expand All @@ -20,6 +24,18 @@ public class BeanValidationsModel {
@Max(99)
protected Integer age;

@Positive
private Double positiveValue;

@PositiveOrZero
private Double positiveOrZeroValue;

@Negative
private Double negativeValue;

@NegativeOrZero
private Double negativeOrZeroValue;

@Pattern(regexp = "(?![-._])[-._a-zA-Z0-9]{3,32}")
@Nonnull
protected String username;
Expand Down Expand Up @@ -133,4 +149,35 @@ public void setOptionalValue(Optional<String> optionalValue) {
this.optionalValue = optionalValue;
}

public Double getPositiveValue() {
return positiveValue;
}

public void setPositiveValue(Double positiveValue) {
this.positiveValue = positiveValue;
}

public Double getPositiveOrZeroValue() {
return positiveOrZeroValue;
}

public void setPositiveOrZeroValue(Double positiveOrZeroValue) {
this.positiveOrZeroValue = positiveOrZeroValue;
}

public Double getNegativeValue() {
return negativeValue;
}

public void setNegativeValue(Double negativeValue) {
this.negativeValue = negativeValue;
}

public Double getNegativeOrZeroValue() {
return negativeOrZeroValue;
}

public void setNegativeOrZeroValue(Double negativeOrZeroValue) {
this.negativeOrZeroValue = negativeOrZeroValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,20 @@ public void readBeanValidatorTest() {
final StringSchema optionalValue = (StringSchema) properties.get("optionalValue");
assertEquals((int) optionalValue.getMinLength(), 1);
assertEquals((int) optionalValue.getMaxLength(), 10);

final NumberSchema positiveValue = (NumberSchema) properties.get("positiveValue");
assertEquals(positiveValue.getMinimum(), BigDecimal.ZERO);
assertTrue(positiveValue.getExclusiveMinimum());

final NumberSchema positiveOrZeroValue = (NumberSchema) properties.get("positiveOrZeroValue");
assertEquals(positiveOrZeroValue.getMinimum(), BigDecimal.ZERO);

final NumberSchema negativeValue = (NumberSchema) properties.get("negativeValue");
assertEquals(negativeValue.getMaximum(), BigDecimal.ZERO);
assertTrue(negativeValue.getExclusiveMaximum());

final NumberSchema negativeOrZeroValue = (NumberSchema) properties.get("negativeOrZeroValue");
assertEquals(negativeOrZeroValue.getMaximum(), BigDecimal.ZERO);

}
}