19
19
import com .fasterxml .jackson .databind .JsonNode ;
20
20
import com .networknt .schema .CollectorContext .Scope ;
21
21
import com .networknt .schema .uri .URIFactory ;
22
+ import com .networknt .schema .uri .URNURIFactory ;
22
23
import com .networknt .schema .urn .URNFactory ;
23
24
import org .slf4j .Logger ;
24
25
import org .slf4j .LoggerFactory ;
@@ -35,6 +36,7 @@ public class RefValidator extends BaseJsonValidator {
35
36
private JsonSchema parentSchema ;
36
37
37
38
private static final String REF_CURRENT = "#" ;
39
+ private static final String URN_SCHEME = URNURIFactory .SCHEME ;
38
40
39
41
public RefValidator (String schemaPath , JsonNode schemaNode , JsonSchema parentSchema , ValidationContext validationContext ) {
40
42
super (schemaPath , schemaNode , parentSchema , ValidatorTypeCode .REF , validationContext );
@@ -78,6 +80,12 @@ static JsonSchemaRef getRefSchema(JsonSchema parentSchema, ValidationContext val
78
80
if (schemaUri == null ) {
79
81
return null ;
80
82
}
83
+ } else if (URN_SCHEME .equals (schemaUri .getScheme ())) {
84
+ // Try to resolve URN schema as a JsonSchemaRef to some sub-schema of the parent
85
+ JsonSchemaRef ref = getJsonSchemaRef (parent , validationContext , schemaUri .toString (), refValueOriginal );
86
+ if (ref != null ) {
87
+ return ref ;
88
+ }
81
89
}
82
90
83
91
// This should retrieve schemas regardless of the protocol that is in the uri.
@@ -91,6 +99,13 @@ static JsonSchemaRef getRefSchema(JsonSchema parentSchema, ValidationContext val
91
99
if (refValue .equals (REF_CURRENT )) {
92
100
return new JsonSchemaRef (parent .findAncestor ());
93
101
}
102
+ return getJsonSchemaRef (parent , validationContext , refValue , refValueOriginal );
103
+ }
104
+
105
+ private static JsonSchemaRef getJsonSchemaRef (JsonSchema parent ,
106
+ ValidationContext validationContext ,
107
+ String refValue ,
108
+ String refValueOriginal ) {
94
109
JsonNode node = parent .getRefSchemaNode (refValue );
95
110
if (node != null ) {
96
111
JsonSchemaRef ref = validationContext .getReferenceParsingInProgress (refValueOriginal );
0 commit comments