Skip to content

Commit

Permalink
Test and fix for #5
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblacklercorp committed Sep 25, 2021
1 parent 2982db5 commit 1ab1e46
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
26 changes: 11 additions & 15 deletions library/src/main/java/net/jimblackler/jsonschemafriend/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,23 +389,19 @@ public class Schema {

recursiveAnchor = getOrDefault(jsonObject, "$recursiveAnchor", false);

try {
URI schemaResource = new URI(uri.getScheme(), uri.getHost(), uri.getPath(), null);
Set<String> dynamicAnchorsInResource =
schemaStore.getDynamicAnchorsForSchemaResource(schemaResource);
if (dynamicAnchorsInResource != null) {
for (String anchor : dynamicAnchorsInResource) {
try {
URI uri1 = new URI(uri.getScheme(), uri.getHost(), uri.getPath(), anchor);
Schema schema = getSubSchema(schemaStore, uri1);
this.dynamicAnchorsInResource.put(anchor, schema);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
URI schemaResource = UriUtils.withoutFragment(uri);
Set<String> dynamicAnchorsInResource =
schemaStore.getDynamicAnchorsForSchemaResource(schemaResource);
if (dynamicAnchorsInResource != null) {
for (String anchor : dynamicAnchorsInResource) {
try {
URI uri1 = new URI(uri.getScheme(), uri.getHost(), uri.getPath(), anchor);
Schema schema = getSubSchema(schemaStore, uri1);
this.dynamicAnchorsInResource.put(anchor, schema);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}

Object dynamicRefObject = jsonObject.get("$dynamicRef");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.jimblackler.jsonschemafriend;

import java.net.URI;

public class UriUtils {
public static URI withoutFragment(URI uri) {
String s = uri.toString();
int i = s.indexOf('#');
if (i == -1) {
return uri;
}
return URI.create(s.substring(0, i));
}
}
35 changes: 35 additions & 0 deletions library/src/test/resources/suites/own/defs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
{
"description": "Defs issue",
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "urn:defs-test",
"title": "TEST",
"type": "object",
"properties": {
"testReference": {
"$ref": "#/$defs/reference"
}
},
"$defs": {
"reference": {
"type": "string"
}
}
},
"tests": [
{
"valid": true,
"data": {
"testReference": "a"
}
},
{
"valid": false,
"data": {
"testReference": 0
}
}
]
}
]

0 comments on commit 1ab1e46

Please sign in to comment.