@@ -196,7 +196,7 @@ private function initItemsReference():void
196196 return ;
197197 }
198198 $ this ->refPointer = $ items ->getJsonReference ()->getJsonPointer ()->getPointer ();
199- $ this ->uri = $ this -> property ->getJsonReference ()->getDocumentUri ();
199+ $ this ->uri = $ items ->getJsonReference ()->getDocumentUri ();
200200 if ($ this ->isRefPointerToSelf ()) {
201201 $ this ->refSchema = $ this ->schema ;
202202 } elseif ($ this ->isRefPointerToSchema ()) {
@@ -267,7 +267,9 @@ public function getSelfTargetProperty():?PropertySchema
267267
268268 public function isRefPointerToSchema ():bool
269269 {
270- return $ this ->refPointer && strpos ($ this ->refPointer , self ::REFERENCE_PATH ) === 0 ;
270+ return $ this ->refPointer &&
271+ ((strpos ($ this ->refPointer , self ::REFERENCE_PATH ) === 0 ) ||
272+ (str_ends_with ($ this ->uri , '.yml ' )) || (str_ends_with ($ this ->uri , '.yaml ' )));
271273 }
272274
273275 public function isRefPointerToSelf ():bool
@@ -303,16 +305,14 @@ public function getRefSchemaName():string
303305 $ pattern = strpos ($ this ->refPointer , '/properties/ ' ) !== false ?
304306 '~^ ' .self ::REFERENCE_PATH .'(?<schemaName>.+)/properties/(?<propName>.+)$~ '
305307 : '~^ ' .self ::REFERENCE_PATH .'(?<schemaName>.+)$~ ' ;
308+ $ separateFilePattern = '/((\.\/)*)(?<schemaName>.+)(\.)(yml|yaml)(.*)/ ' ; # https://github.com/php-openapi/yii2-openapi/issues/74
306309 if (!\preg_match ($ pattern , $ this ->refPointer , $ matches )) {
307- $ pattern = '/((\.\/)*)(?<schemaName>.+)(\.)(yml|yaml)(.*)/ ' ;
308- // $pattern = '~^(?<schemaName>.+)(\.+)(yaml+)(.*)$~';
309- if (strpos ($ this ->uri , '# ' ) !== false && !\preg_match ($ pattern , $ this ->uri , $ matches )) {
310- // throw new InvalidDefinitionException('Invalid schema reference');
311- } else {
310+ if (!\preg_match ($ separateFilePattern , $ this ->uri , $ separateFilePatternMatches )) {
312311 throw new InvalidDefinitionException ('Invalid schema reference ' );
312+ } else {
313+ return $ separateFilePatternMatches ['schemaName ' ];
313314 }
314315 }
315- var_dump ($ matches );
316316 return $ matches ['schemaName ' ];
317317 }
318318
0 commit comments