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 @@ -47,7 +47,7 @@ public void validate(ExecutionContext executionContext, JsonNode node, JsonNode
if (dividend.divideAndRemainder(this.divisor)[1].abs().compareTo(BigDecimal.ZERO) > 0) {
executionContext.addError(error().instanceNode(node).instanceLocation(instanceLocation)
.evaluationPath(executionContext.getEvaluationPath()).locale(executionContext.getExecutionConfig().getLocale())
.arguments(this.divisor)
.arguments(this.divisor.toString()) // String is used as the MessageFormat NumberFormat considers 3 fractional digits by default
.build());
}
}
Expand All @@ -66,7 +66,7 @@ protected BigDecimal getDivisor(JsonNode schemaNode) {
if (divisor != 0) {
// convert to BigDecimal since double type is not accurate enough to do the
// division and multiple
return schemaNode.isBigDecimal() ? schemaNode.decimalValue() : BigDecimal.valueOf(divisor);
return schemaNode.isBigDecimal() ? schemaNode.decimalValue().stripTrailingZeros() : BigDecimal.valueOf(divisor).stripTrailingZeros();
}
}
return null;
Expand Down
11 changes: 11 additions & 0 deletions src/test/java/com/networknt/schema/MultipleOfValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,15 @@ void testTypeLoose() {
messages = typeLoose.validate(validTypeLooseInputData, InputFormat.JSON);
assertEquals(0, messages.size());
}

@Test
void messageFormatPrecision() {
String schemaData = "{ \"type\": \"object\", \"properties\": { \"value1\": { \"type\": \"number\", \"multipleOf\": 0.00001 } } }";
SchemaRegistry factory = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12);
Schema schema = factory.getSchema(schemaData);
String inputData = "{\"value1\":123.000001}";

List<Error> messages = schema.validate(inputData, InputFormat.JSON);
assertEquals("must be multiple of 0.00001", messages.get(0).getMessage());
}
}