21
21
import java .net .URLDecoder ;
22
22
import java .util .Collections ;
23
23
import java .util .Comparator ;
24
- import java .util .HashMap ;
25
24
import java .util .Iterator ;
26
25
import java .util .LinkedHashSet ;
27
26
import java .util .Map ;
46
45
public class JsonSchema extends BaseJsonValidator {
47
46
private static final Pattern intPattern = Pattern .compile ("^[0-9]+$" );
48
47
private Map <String , JsonValidator > validators ;
49
- private final String idKeyword ;
50
48
private final ValidationContext validationContext ;
49
+ private final JsonMetaSchema metaSchema ;
51
50
private boolean validatorsLoaded = false ;
52
51
53
52
/**
@@ -82,7 +81,7 @@ private JsonSchema(ValidationContext validationContext, String schemaPath, URI c
82
81
validationContext .getConfig () != null && validationContext .getConfig ().isFailFast (),
83
82
validationContext .getConfig () != null ? validationContext .getConfig ().getApplyDefaultsStrategy () : null );
84
83
this .validationContext = validationContext ;
85
- this .idKeyword = validationContext .getMetaSchema (). getIdKeyword ();
84
+ this .metaSchema = validationContext .getMetaSchema ();
86
85
this .currentUri = this .combineCurrentUriWithIds (currentUri , schemaNode );
87
86
if (validationContext .getConfig () != null ) {
88
87
if (validationContext .getConfig ().isOpenAPI3StyleDiscriminators ()) {
@@ -156,7 +155,7 @@ public JsonNode getRefSchemaNode(String ref) {
156
155
}
157
156
}
158
157
} else if (ref .startsWith ("#" ) && ref .length () > 1 ) {
159
- node = getNodeById (ref , node );
158
+ node = metaSchema . getNodeByFragmentRef (ref , node );
160
159
if (node == null ) {
161
160
node = handleNullNode (ref , schema );
162
161
}
@@ -180,29 +179,6 @@ private JsonNode handleNullNode(String ref, JsonSchema schema) {
180
179
return null ;
181
180
}
182
181
183
- private JsonNode getNodeById (String ref , JsonNode node ) {
184
- if (nodeContainsRef (ref , node )) {
185
- return node ;
186
- } else {
187
- Iterator <JsonNode > children = node .elements ();
188
- while (children .hasNext ()) {
189
- JsonNode refNode = getNodeById (ref , children .next ());
190
- if (refNode != null ) {
191
- return refNode ;
192
- }
193
- }
194
- }
195
- return null ;
196
- }
197
-
198
- private boolean nodeContainsRef (String ref , JsonNode node ) {
199
- JsonNode id = node .get (idKeyword );
200
- if (id != null ) {
201
- return ref .equals (id .asText ());
202
- }
203
- return false ;
204
- }
205
-
206
182
/**
207
183
* Please note that the key in {@link #validators} map is a schema path. It is
208
184
* used in {@link com.networknt.schema.walk.DefaultKeywordWalkListenerRunner} to derive the keyword.
0 commit comments