@@ -20,7 +20,7 @@ class ReferenceKnot {
20
20
21
21
private Schema referredSchema ;
22
22
23
- private List <ReferenceSchema .Builder > refs = new ArrayList <>(1 );
23
+ private final List <ReferenceSchema .Builder > refs = new ArrayList <>(1 );
24
24
25
25
ReferenceSchema .Builder initReference (String refValue ) {
26
26
ReferenceSchema .Builder builder = new ReferenceSchema .Builder ().refValue (refValue );
@@ -67,21 +67,32 @@ static Map<String, Object> extend(Map<String, Object> additional, Map<String, Ob
67
67
return rawObj ;
68
68
}
69
69
70
- private LoadingState ls ;
71
-
72
- private SchemaClient schemaClient ;
73
-
74
- public ReferenceLookup (LoadingState ls ) {
75
- this .ls = requireNonNull (ls , "ls cannot be null" );
76
- this .schemaClient = ls .config .schemaClient ;
77
- }
78
-
79
- private Map <String , Object > doExtend (Map <String , Object > additional , Map <String , Object > original ) {
80
- if (ls .specVersion () == SpecificationVersion .DRAFT_4 ) {
81
- return extend (additional , original );
82
- } else {
83
- return original ;
70
+ static JsonObject lookupObjById (JsonValue val , String idAttrVal ) {
71
+ String idKeyword = val .ls .specVersion ().idKeyword ();
72
+ if (val instanceof JsonObject ) {
73
+ JsonObject obj = (JsonObject ) val ;
74
+ if (obj .containsKey (idKeyword )
75
+ && obj .require (idKeyword ).typeOfValue () == String .class
76
+ && obj .require (idKeyword ).requireString ().equals (idAttrVal )) {
77
+ return obj ;
78
+ }
79
+ for (String key : obj .keySet ()) {
80
+ JsonObject maybeFound = lookupObjById (obj .require (key ), idAttrVal );
81
+ if (maybeFound != null ) {
82
+ return maybeFound ;
83
+ }
84
+ }
85
+ } else if (val instanceof JsonArray ) {
86
+ JsonArray arr = (JsonArray ) val ;
87
+ for (int i = 0 ; i < arr .length (); ++i ) {
88
+ JsonObject maybeFound = lookupObjById (arr .at (i ), idAttrVal );
89
+ if (maybeFound != null ) {
90
+ return maybeFound ;
91
+ }
92
+ }
84
93
}
94
+
95
+ return null ;
85
96
}
86
97
87
98
/**
@@ -106,6 +117,23 @@ static URI withoutFragment(final String fullUri) {
106
117
}
107
118
}
108
119
120
+ private final LoadingState ls ;
121
+
122
+ private final SchemaClient schemaClient ;
123
+
124
+ public ReferenceLookup (LoadingState ls ) {
125
+ this .ls = requireNonNull (ls , "ls cannot be null" );
126
+ this .schemaClient = ls .config .schemaClient ;
127
+ }
128
+
129
+ private Map <String , Object > doExtend (Map <String , Object > additional , Map <String , Object > original ) {
130
+ if (ls .specVersion () == SpecificationVersion .DRAFT_4 ) {
131
+ return extend (additional , original );
132
+ } else {
133
+ return original ;
134
+ }
135
+ }
136
+
109
137
Map <String , Object > withoutRef (JsonObject original ) {
110
138
Map <String , Object > rawObj = new HashMap <>();
111
139
original .keySet ().stream ()
@@ -114,34 +142,6 @@ Map<String, Object> withoutRef(JsonObject original) {
114
142
return rawObj ;
115
143
}
116
144
117
- private JsonObject lookupObjById (JsonValue val , String idAttrVal ) {
118
- String idKeyword = val .ls .specVersion ().idKeyword ();
119
- if (val instanceof JsonObject ) {
120
- JsonObject obj = (JsonObject ) val ;
121
- if (obj .containsKey (idKeyword )
122
- && obj .require (idKeyword ).typeOfValue () == String .class
123
- && obj .require (idKeyword ).requireString ().equals (idAttrVal )) {
124
- return obj ;
125
- }
126
- for (String key : obj .keySet ()) {
127
- JsonObject maybeFound = lookupObjById (obj .require (key ), idAttrVal );
128
- if (maybeFound != null ) {
129
- return maybeFound ;
130
- }
131
- }
132
- } else if (val instanceof JsonArray ) {
133
- JsonArray arr = (JsonArray ) val ;
134
- for (int i = 0 ; i < arr .length (); ++i ) {
135
- JsonObject maybeFound = lookupObjById (arr .at (i ), idAttrVal );
136
- if (maybeFound != null ) {
137
- return maybeFound ;
138
- }
139
- }
140
- }
141
-
142
- return null ;
143
- }
144
-
145
145
private Schema .Builder <?> performQueryEvaluation (String mapKey , JsonPointerEvaluator pointerEvaluator ) {
146
146
String absolutePointer = ReferenceResolver .resolve (ls .id , mapKey ).toString ();
147
147
if (ls .pointerSchemas .containsKey (absolutePointer )) {
@@ -174,13 +174,14 @@ Schema.Builder<?> lookup(String relPointerString, JsonObject ctx) {
174
174
175
175
URI resolutionScope = !isSameDocumentRef (absPointerString ) ? withoutFragment (absPointerString ) : ls .id ;
176
176
JsonObject containingDocument = result .getContainingDocument ();
177
+ SchemaLocation resultLocation = result .getQueryResult ().ls .pointerToCurrentObj ;
177
178
SchemaLoader childLoader = ls .initNewDocumentLoader ()
178
- .pointerToCurrentObj (SchemaLocation . parseURI ( absPointerString ) )
179
+ .pointerToCurrentObj (resultLocation )
179
180
.resolutionScope (resolutionScope )
180
181
.schemaJson (result .getQueryResult ())
181
182
.rootSchemaJson (containingDocument ).build ();
182
183
Schema referredSchema = childLoader .load ().build ();
183
- refBuilder .schemaLocation (SchemaLocation . parseURI ( absPointerString ) );
184
+ refBuilder .schemaLocation (resultLocation );
184
185
knot .resolveWith (referredSchema );
185
186
return refBuilder ;
186
187
}
0 commit comments