@@ -106,9 +106,10 @@ private function expandRefs(&$schema, ?string $parentId = null): void
106106 continue ;
107107 }
108108
109+ $ schemaId = $ this ->findSchemaIdInObject ($ schema );
109110 $ 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 );
112113 }
113114
114115 $ this ->expandRefs ($ member , $ childId );
@@ -196,17 +197,30 @@ private function scanForSubschemas($schema, string $parentId): void
196197 continue ;
197198 }
198199
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 ' )) {
200202 // Enum and const don't allow id as a keyword, see https://github.com/json-schema-org/JSON-Schema-Test-Suite/pull/471
201203 if (in_array ($ propertyName , ['enum ' , 'const ' ])) {
202204 continue ;
203205 }
204206
205207 // Found sub schema
206- $ this ->addSchema ($ this ->uriResolver ->resolve ($ potentialSubSchema -> id , $ parentId ), $ potentialSubSchema );
208+ $ this ->addSchema ($ this ->uriResolver ->resolve ($ potentialSubSchemaId , $ parentId ), $ potentialSubSchema );
207209 }
208210
209211 $ this ->scanForSubschemas ($ potentialSubSchema , $ parentId );
210212 }
211213 }
214+
215+ private function findSchemaIdInObject (object $ schema ): ?string
216+ {
217+ if (property_exists ($ schema , 'id ' )) {
218+ return $ schema ->id ;
219+ }
220+ if (property_exists ($ schema , '$id ' )) {
221+ return $ schema ->{'$id ' };
222+ }
223+
224+ return null ;
225+ }
212226}
0 commit comments