Skip to content

Commit

Permalink
Fix explicit disabling of format assertions (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-tay authored Jan 17, 2025
1 parent 4e8a2b8 commit 77c91a2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ public static class Builder {
private String errorMessageKeyword = null;
private ExecutionContextCustomizer executionContextCustomizer = null;
private boolean failFast = false;
private Boolean formatAssertionsEnabled = false;
private Boolean formatAssertionsEnabled = null;
private boolean nullableKeywordEnabled = false;
private List<JsonSchemaWalkListener> itemWalkListeners = new ArrayList<>();
private boolean javaSemantics = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ protected boolean isFormatAssertionVocabularyEnabled(VersionFlag specification,
protected boolean isAssertionsEnabled(ExecutionContext executionContext) {
if (Boolean.TRUE.equals(executionContext.getExecutionConfig().getFormatAssertionsEnabled())) {
return true;
} else if (Boolean.FALSE.equals(executionContext.getExecutionConfig().getFormatAssertionsEnabled())) {
return false;
}
return this.assertionsEnabled;
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/networknt/schema/FormatValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,16 @@ void shouldAllowNumberFormat() {
assertTrue(messages.isEmpty());

}

@Test
void draft7DisableFormat() {
String schemaData = "{\r\n"
+ " \"format\":\"uri\"\r\n"
+ "}";
JsonSchema schema = JsonSchemaFactory.getInstance(VersionFlag.V7).getSchema(schemaData);
Set<ValidationMessage> messages = schema.validate("\"hello\"", InputFormat.JSON, executionContext -> {
executionContext.getExecutionConfig().setFormatAssertionsEnabled(false);
});
assertEquals(0, messages.size());
}
}

0 comments on commit 77c91a2

Please # to comment.