Skip to content

Commit bf65073

Browse files
authored
Merge pull request #95 from networknt/fix/minmax-validator-errors
Fixing min/max int validation to not output decimal constraints.
2 parents 0251e2a + af97444 commit bf65073

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/main/java/com/networknt/schema/BaseJsonValidator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,12 @@ protected void debug(Logger logger, JsonNode node, JsonNode rootNode, String at)
125125
protected ValidatorTypeCode getValidatorType() {
126126
return validatorType;
127127
}
128+
129+
protected String getNodeFieldType() {
130+
JsonNode typeField = this.getParentSchema().getSchemaNode().get("type");
131+
if (typeField != null) {
132+
return typeField.asText();
133+
}
134+
return null;
135+
}
128136
}

src/main/java/com/networknt/schema/MaximumValidator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
5555
return Collections.emptySet();
5656
}
5757

58+
String fieldType = this.getNodeFieldType();
59+
5860
double value = node.doubleValue();
5961
if (greaterThan(value, maximum) || (excludeEqual && equals(value, maximum))) {
62+
if (JsonType.INTEGER.toString().equals(fieldType)) {
63+
return Collections.singleton(buildValidationMessage(at, "" + (int)maximum));
64+
}
6065
return Collections.singleton(buildValidationMessage(at, "" + maximum));
6166
}
6267
return Collections.emptySet();

src/main/java/com/networknt/schema/MinimumValidator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
5353
// minimum only applies to numbers
5454
return Collections.emptySet();
5555
}
56+
String fieldType = this.getNodeFieldType();
5657

5758
double value = node.doubleValue();
5859
if (lessThan(value, minimum) || (excluded && equals(value, minimum))) {
60+
if (JsonType.INTEGER.toString().equals(fieldType)) {
61+
return Collections.singleton(buildValidationMessage(at, "" + (int) minimum));
62+
}
5963
return Collections.singleton(buildValidationMessage(at, "" + minimum));
6064
}
6165
return Collections.emptySet();

0 commit comments

Comments
 (0)