Skip to content

Commit

Permalink
fixes #54 convert all numbers to decimal node for comparison in enum
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Nov 16, 2019
1 parent e83fc2e commit 08ca9e4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/networknt/schema/EnumValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.networknt.schema;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.DecimalNode;
import com.fasterxml.jackson.databind.node.NullNode;

import org.slf4j.Logger;
Expand Down Expand Up @@ -44,7 +45,12 @@ public EnumValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSc
String separator = "";

for (JsonNode n : schemaNode) {
nodes.add(n);
if(n.isNumber()) {
// convert to DecimalNode for number comparison
nodes.add(DecimalNode.valueOf(n.decimalValue()));
} else {
nodes.add(n);
}

sb.append(separator);
sb.append(n.asText());
Expand Down Expand Up @@ -77,7 +83,7 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
debug(logger, node, rootNode, at);

Set<ValidationMessage> errors = new LinkedHashSet<ValidationMessage>();

if(node.isNumber()) node = DecimalNode.valueOf(node.decimalValue());
if (!nodes.contains(node) && !(config.isTypeLoose() && isTypeLooseContainsInEnum(node))) {
errors.add(buildValidationMessage(at, error));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ public void testDependenciesValidator() throws Exception {
}

@Test
@Ignore
public void testEnumValidator() throws Exception {
runTestFile("draft2019-09/enum.json");
}
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/networknt/schema/V6JsonSchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public void testDependenciesValidator() throws Exception {
}

@Test
@Ignore
public void testEnumValidator() throws Exception {
runTestFile("draft6/enum.json");
}
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/networknt/schema/V7JsonSchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ public void testDependenciesValidator() throws Exception {
}

@Test
@Ignore
public void testEnumValidator() throws Exception {
runTestFile("draft7/enum.json");
}
Expand Down

0 comments on commit 08ca9e4

Please sign in to comment.