@@ -192,4 +192,71 @@ public function testPathItemReference()
192
192
$ this ->assertEquals ('A bar ' , $ barPath ->get ->responses ['200 ' ]->description );
193
193
$ this ->assertEquals ('non-existing resource ' , $ barPath ->get ->responses ['404 ' ]->description );
194
194
}
195
+
196
+ public function testPathParametersAreArrays ()
197
+ {
198
+ $ file = __DIR__ . '/data/path-params/openapi.yaml ' ;
199
+ /** @var $openapi \cebe\openapi\spec\OpenApi */
200
+ $ openapi = Reader::readFromYamlFile ($ file , \cebe \openapi \spec \OpenApi::class, true );
201
+
202
+ $ result = $ openapi ->validate ();
203
+ $ this ->assertEquals ([], $ openapi ->getErrors (), print_r ($ openapi ->getErrors (), true ));
204
+ $ this ->assertTrue ($ result );
205
+
206
+ $ this ->assertInstanceOf (Paths::class, $ openapi ->paths );
207
+ $ this ->assertSame (gettype ($ openapi ->paths ->getPaths ()), 'array ' );
208
+ $ this ->assertInstanceOf (PathItem::class, $ usersPath = $ openapi ->paths ['/v1/organizations/{organizationId}/user ' ]);
209
+ $ this ->assertInstanceOf (PathItem::class, $ userIdPath = $ openapi ->paths ['/v1/organizations/{organizationId}/user/{id} ' ]);
210
+
211
+ $ result = $ usersPath ->validate ();
212
+ $ this ->assertTrue ($ result );
213
+ $ this ->assertSame (gettype ($ usersPath ->parameters ), 'array ' );
214
+ $ this ->assertInstanceOf (\cebe \openapi \spec \Parameter::class, $ usersPath ->parameters [0 ]);
215
+ $ this ->assertInstanceOf (\cebe \openapi \spec \Parameter::class, $ usersPath ->parameters [1 ]);
216
+ $ this ->assertEquals ('api-version ' , $ usersPath ->parameters [0 ]->name );
217
+
218
+ $ result = $ userIdPath ->validate ();
219
+ $ this ->assertTrue ($ result );
220
+ $ this ->assertSame (gettype ($ userIdPath ->parameters ), 'array ' );
221
+ $ this ->assertInstanceOf (\cebe \openapi \spec \Parameter::class, $ userIdPath ->parameters [0 ]);
222
+ $ this ->assertInstanceOf (\cebe \openapi \spec \Parameter::class, $ userIdPath ->parameters [1 ]);
223
+ $ this ->assertEquals ('id ' , $ userIdPath ->parameters [2 ]->name );
224
+
225
+ $ dirSep = DIRECTORY_SEPARATOR ;
226
+ $ output = dirname (__DIR__ ) . $ dirSep . 'compiled.yml ' ;
227
+ shell_exec ('php ' . dirname (__DIR__ , 2 ) . "{$ dirSep }bin {$ dirSep }php-openapi inline " . $ file . ' ' . $ output );
228
+
229
+ $ baseExpected = dirname (__DIR__ )."{$ dirSep }data {$ dirSep }issue {$ dirSep }155 {$ dirSep }" ;
230
+ $ expected = $ baseExpected .'compiled-symfony-7.yml ' ;
231
+ $ version = static ::symfonyYamlVersion ();
232
+ $ majorVersion = explode ('. ' , $ version )[0 ];
233
+
234
+ if ($ majorVersion == 6 ) {
235
+ $ expected = $ baseExpected ."compiled-symfony-6.yml " ;
236
+ if (version_compare (PHP_VERSION , '8.1 ' , '>= ' ) && version_compare ($ version , '6.0.0 ' , '!= ' )) {
237
+ $ expected = $ baseExpected ."compiled-symfony-7.yml " ;
238
+ }
239
+ } elseif ($ majorVersion == 5 ) {
240
+ $ expected = $ baseExpected ."compiled-symfony-6.yml " ;
241
+ }
242
+ if (stripos (PHP_OS , 'WIN ' ) === 0 ) { # fixes https://github.com/cebe/php-openapi/actions/runs/14808968938/job/41581244210
243
+ file_put_contents ($ expected , preg_replace ('~\R~ ' , "\n" , file_get_contents ($ expected ))); # not an ideal solution, can be refactored
244
+ }
245
+
246
+ $ this ->assertFileEquals ($ output , $ expected );
247
+ unlink ($ output );
248
+ }
249
+
250
+ protected static function symfonyYamlVersion ()
251
+ {
252
+ $ package = 'symfony/yaml ' ;
253
+ $ installed = json_decode (file_get_contents (__DIR__ . '/../../composer.lock ' ), true );
254
+
255
+ foreach ($ installed ['packages ' ] as $ pkg ) {
256
+ if ($ pkg ['name ' ] === $ package ) {
257
+ return str_replace ('v ' , '' , $ pkg ['version ' ]);
258
+ }
259
+ }
260
+ return '7.0.0 ' ;
261
+ }
195
262
}
0 commit comments