Skip to content

Commit 77c91a2

Browse files
authored
Fix explicit disabling of format assertions (#1145)
1 parent 4e8a2b8 commit 77c91a2

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ public static class Builder {
817817
private String errorMessageKeyword = null;
818818
private ExecutionContextCustomizer executionContextCustomizer = null;
819819
private boolean failFast = false;
820-
private Boolean formatAssertionsEnabled = false;
820+
private Boolean formatAssertionsEnabled = null;
821821
private boolean nullableKeywordEnabled = false;
822822
private List<JsonSchemaWalkListener> itemWalkListeners = new ArrayList<>();
823823
private boolean javaSemantics = false;

src/main/java/com/networknt/schema/format/BaseFormatJsonValidator.java

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ protected boolean isFormatAssertionVocabularyEnabled(VersionFlag specification,
4949
protected boolean isAssertionsEnabled(ExecutionContext executionContext) {
5050
if (Boolean.TRUE.equals(executionContext.getExecutionConfig().getFormatAssertionsEnabled())) {
5151
return true;
52+
} else if (Boolean.FALSE.equals(executionContext.getExecutionConfig().getFormatAssertionsEnabled())) {
53+
return false;
5254
}
5355
return this.assertionsEnabled;
5456
}

src/test/java/com/networknt/schema/FormatValidatorTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,16 @@ void shouldAllowNumberFormat() {
233233
assertTrue(messages.isEmpty());
234234

235235
}
236+
237+
@Test
238+
void draft7DisableFormat() {
239+
String schemaData = "{\r\n"
240+
+ " \"format\":\"uri\"\r\n"
241+
+ "}";
242+
JsonSchema schema = JsonSchemaFactory.getInstance(VersionFlag.V7).getSchema(schemaData);
243+
Set<ValidationMessage> messages = schema.validate("\"hello\"", InputFormat.JSON, executionContext -> {
244+
executionContext.getExecutionConfig().setFormatAssertionsEnabled(false);
245+
});
246+
assertEquals(0, messages.size());
247+
}
236248
}

0 commit comments

Comments
 (0)