@@ -136,15 +136,20 @@ public function testResolveCyclicReferenceInDocument()
136
136
$ this ->assertSame ($ openapi ->components ->examples ['frog-example ' ], $ refExample );
137
137
}
138
138
139
- public function testResolveFile ( )
139
+ private function createFileUri ( $ file )
140
140
{
141
- $ file = __DIR__ . '/data/reference/base.yaml ' ;
142
141
if (stripos (PHP_OS , 'WIN ' ) === 0 ) {
143
- $ yaml = str_replace ('##ABSOLUTEPATH## ' , 'file:/// ' . strtr (dirname ($ file ), [' ' => '%20 ' , '\\' => '/ ' ]), file_get_contents ($ file ));
144
- throw new \Exception ($ yaml );
142
+ return 'file:/// ' . strtr ($ file , [' ' => '%20 ' , '\\' => '/ ' ]);
145
143
} else {
146
- $ yaml = str_replace ( ' ##ABSOLUTEPATH## ' , ' file:// ' . dirname ( $ file), file_get_contents ( $ file )) ;
144
+ return ' file:// ' . $ file ;
147
145
}
146
+ }
147
+
148
+ public function testResolveFile ()
149
+ {
150
+ $ file = __DIR__ . '/data/reference/base.yaml ' ;
151
+ $ yaml = str_replace ('##ABSOLUTEPATH## ' , $ this ->createFileUri (dirname ($ file )), file_get_contents ($ file ));
152
+
148
153
/** @var $openapi OpenApi */
149
154
$ openapi = Reader::readFromYaml ($ yaml );
150
155
@@ -296,7 +301,7 @@ enum:
296
301
297
302
YAML;
298
303
$ openapi = Reader::readFromYaml ($ schema );
299
- $ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , ' file:// ' . __DIR__ . '/data/reference/definitions.yaml ' ));
304
+ $ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , $ this -> createFileUri ( __DIR__ . '/data/reference/definitions.yaml ' ) ));
300
305
301
306
$ this ->assertTrue (isset ($ openapi ->components ->schemas ['Pet ' ]));
302
307
$ this ->assertEquals (['One ' , 'Two ' ], $ openapi ->components ->schemas ['Pet ' ]->properties ['typeA ' ]->enum );
@@ -377,7 +382,7 @@ public function testTransitiveReferenceToFile()
377
382
YAML;
378
383
379
384
$ openapi = Reader::readFromYaml ($ schema );
380
- $ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , ' file:// ' . __DIR__ . '/data/reference/definitions.yaml ' ));
385
+ $ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , $ this -> createFileUri ( __DIR__ . '/data/reference/definitions.yaml ' ) ));
381
386
382
387
$ this ->assertTrue (isset ($ openapi ->components ->schemas ['Dog ' ]));
383
388
$ this ->assertEquals ('object ' , $ openapi ->components ->schemas ['Dog ' ]->type );
0 commit comments