@@ -106,9 +106,10 @@ private function expandRefs(&$schema, ?string $parentId = null): void
106
106
continue ;
107
107
}
108
108
109
+ $ schemaId = $ this ->findSchemaIdInObject ($ schema );
109
110
$ childId = $ parentId ;
110
- if (property_exists ( $ schema , ' id ' ) && is_string ($ schema -> id ) && $ childId !== $ schema -> id ) {
111
- $ childId = $ this ->uriResolver ->resolve ($ schema -> id , $ childId );
111
+ if (is_string ($ schemaId ) && $ childId !== $ schemaId ) {
112
+ $ childId = $ this ->uriResolver ->resolve ($ schemaId , $ childId );
112
113
}
113
114
114
115
$ this ->expandRefs ($ member , $ childId );
@@ -196,17 +197,30 @@ private function scanForSubschemas($schema, string $parentId): void
196
197
continue ;
197
198
}
198
199
199
- if (property_exists ($ potentialSubSchema , 'id ' ) && is_string ($ potentialSubSchema ->id ) && property_exists ($ potentialSubSchema , 'type ' )) {
200
+ $ potentialSubSchemaId = $ this ->findSchemaIdInObject ($ potentialSubSchema );
201
+ if (is_string ($ potentialSubSchemaId ) && property_exists ($ potentialSubSchema , 'type ' )) {
200
202
// Enum and const don't allow id as a keyword, see https://github.com/json-schema-org/JSON-Schema-Test-Suite/pull/471
201
203
if (in_array ($ propertyName , ['enum ' , 'const ' ])) {
202
204
continue ;
203
205
}
204
206
205
207
// Found sub schema
206
- $ this ->addSchema ($ this ->uriResolver ->resolve ($ potentialSubSchema -> id , $ parentId ), $ potentialSubSchema );
208
+ $ this ->addSchema ($ this ->uriResolver ->resolve ($ potentialSubSchemaId , $ parentId ), $ potentialSubSchema );
207
209
}
208
210
209
211
$ this ->scanForSubschemas ($ potentialSubSchema , $ parentId );
210
212
}
211
213
}
214
+
215
+ private function findSchemaIdInObject (object $ schema ): ?string
216
+ {
217
+ if (property_exists ($ schema , 'id ' ) && is_string ($ schema ->id )) {
218
+ return $ schema ->id ;
219
+ }
220
+ if (property_exists ($ schema , '$id ' ) && is_string ($ schema ->{'$id ' })) {
221
+ return $ schema ->{'$id ' };
222
+ }
223
+
224
+ return null ;
225
+ }
212
226
}
0 commit comments