Skip to content

Commit

Permalink
let's allow empty fragments for more compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
harrel56 committed Oct 13, 2023
1 parent 4a5acc4 commit f138725
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/java/dev/harrel/jsonschema/Validator.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public Result validate(URI schemaUri, JsonNode instanceNode) {
}

private Schema getRootSchema(URI uri) {
if (uri.getFragment() != null) {
throw new IllegalArgumentException(String.format("Root schema [%s] cannot contain fragments", uri));
if (uri.getFragment() != null && !uri.getFragment().isEmpty()) {
throw new IllegalArgumentException(String.format("Root schema [%s] cannot contain non-empty fragments", uri));
}
return OptionalUtil.firstPresent(
() -> Optional.ofNullable(schemaRegistry.get(uri.toString())),
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/dev/harrel/jsonschema/ValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ void failsForUriWithNonEmptyFragments() {
URI uri = URI.create("https://test.com/x#/$def/x");
assertThatThrownBy(() -> validator.validate(uri, "{}"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Root schema [https://test.com/x#/$def/x] cannot contain fragments");
.hasMessage("Root schema [https://test.com/x#/$def/x] cannot contain non-empty fragments");
}

@Test
void failsForUriWithEmptyFragments() {
void registersUriWithEmptyFragments() {
Validator validator = new ValidatorFactory().createValidator();
URI uri = URI.create("https://test.com/x#");
assertThatThrownBy(() -> validator.validate(uri, "{}"))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Root schema [https://test.com/x#] cannot contain fragments");
.isInstanceOf(SchemaNotFoundException.class)
.hasMessage("Couldn't find schema with uri [https://test.com/x#]");
}

@Test
Expand Down

0 comments on commit f138725

Please sign in to comment.