@@ -196,7 +196,7 @@ private function initItemsReference():void
196
196
return ;
197
197
}
198
198
$ this ->refPointer = $ items ->getJsonReference ()->getJsonPointer ()->getPointer ();
199
- $ this ->uri = $ this -> property ->getJsonReference ()->getDocumentUri ();
199
+ $ this ->uri = $ items ->getJsonReference ()->getDocumentUri ();
200
200
if ($ this ->isRefPointerToSelf ()) {
201
201
$ this ->refSchema = $ this ->schema ;
202
202
} elseif ($ this ->isRefPointerToSchema ()) {
@@ -267,7 +267,9 @@ public function getSelfTargetProperty():?PropertySchema
267
267
268
268
public function isRefPointerToSchema ():bool
269
269
{
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 ' )));
271
273
}
272
274
273
275
public function isRefPointerToSelf ():bool
@@ -303,16 +305,14 @@ public function getRefSchemaName():string
303
305
$ pattern = strpos ($ this ->refPointer , '/properties/ ' ) !== false ?
304
306
'~^ ' .self ::REFERENCE_PATH .'(?<schemaName>.+)/properties/(?<propName>.+)$~ '
305
307
: '~^ ' .self ::REFERENCE_PATH .'(?<schemaName>.+)$~ ' ;
308
+ $ separateFilePattern = '/((\.\/)*)(?<schemaName>.+)(\.)(yml|yaml)(.*)/ ' ; # https://github.com/php-openapi/yii2-openapi/issues/74
306
309
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 )) {
312
311
throw new InvalidDefinitionException ('Invalid schema reference ' );
312
+ } else {
313
+ return $ separateFilePatternMatches ['schemaName ' ];
313
314
}
314
315
}
315
- var_dump ($ matches );
316
316
return $ matches ['schemaName ' ];
317
317
}
318
318
0 commit comments