Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix explicit disabling of format assertions #1145

Merged
merged 1 commit into from
Jan 17, 2025
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 @@ -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());
}
}
Loading