File tree Expand file tree Collapse file tree 5 files changed +24
-1
lines changed Expand file tree Collapse file tree 5 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,9 @@ public function getIterator()
192192 public function resolveReferences (ReferenceContext $ context )
193193 {
194194 foreach ($ this ->_paths as $ key => $ path ) {
195+ if ($ path === null ) {
196+ continue ;
197+ }
195198 $ path ->resolveReferences ($ context );
196199 }
197200 }
Original file line number Diff line number Diff line change @@ -102,7 +102,7 @@ public function resolve(ReferenceContext $context)
102102
103103 $ file = ($ pos === false ) ? $ this ->_ref : substr ($ this ->_ref , 0 , $ pos );
104104 $ file = $ context ->resolveRelativeUri ($ file );
105- $ jsonPointer = substr ($ this ->_ref , $ pos + 1 );
105+ $ jsonPointer = ( $ pos === false ) ? '' : substr ($ this ->_ref , $ pos + 1 );
106106
107107 // TODO could be a good idea to cache loaded files in current context to avoid loading the same files over and over again
108108 $ fileContent = $ this ->fetchReferencedFile ($ file );
Original file line number Diff line number Diff line change @@ -153,6 +153,18 @@ public function testResolveFile()
153153 $ this ->assertInstanceOf (Schema::class, $ petItems = $ openapi ->components ->schemas ['Dog ' ]);
154154 $ this ->assertArrayHasKey ('id ' , $ openapi ->components ->schemas ['Pet ' ]->properties );
155155 $ this ->assertArrayHasKey ('name ' , $ openapi ->components ->schemas ['Dog ' ]->properties );
156+
157+ // second level reference inside of definitions.yaml
158+ $ this ->assertArrayHasKey ('food ' , $ openapi ->components ->schemas ['Dog ' ]->properties );
159+ $ this ->assertInstanceOf (Reference::class, $ openapi ->components ->schemas ['Dog ' ]->properties ['food ' ]);
160+
161+ $ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , $ file ));
162+
163+ $ this ->assertArrayHasKey ('food ' , $ openapi ->components ->schemas ['Dog ' ]->properties );
164+ $ this ->assertInstanceOf (Schema::class, $ openapi ->components ->schemas ['Dog ' ]->properties ['food ' ]);
165+ $ this ->assertArrayHasKey ('id ' , $ openapi ->components ->schemas ['Dog ' ]->properties ['food ' ]->properties );
166+ $ this ->assertArrayHasKey ('name ' , $ openapi ->components ->schemas ['Dog ' ]->properties ['food ' ]->properties );
167+ $ this ->assertEquals (1 , $ openapi ->components ->schemas ['Dog ' ]->properties ['food ' ]->properties ['id ' ]->example );
156168 }
157169
158170 public function testResolveFileHttp ()
Original file line number Diff line number Diff line change 1+ properties :
2+ id :
3+ type : integer
4+ example : 1
5+ name :
6+ type : string
Original file line number Diff line number Diff line change 99 properties :
1010 name :
1111 type : string
12+ food :
13+ $ref : ' Food.yaml'
You can’t perform that action at this time.
0 commit comments