File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -258,6 +258,14 @@ private function buildOpenapi(array $resource): bool|OpenApiOperation|null
258258 if (\array_key_exists ('parameters ' , $ resource ['openapi ' ]) && \is_array ($ openapiParameters = $ resource ['openapi ' ]['parameters ' ] ?? [])) {
259259 $ parameters = [];
260260 foreach ($ openapiParameters as $ parameter ) {
261+ if (!isset ($ parameter ['name ' ])) {
262+ throw new InvalidArgumentException ('OpenAPI parameter is missing the required "name" key. ' );
263+ }
264+
265+ if (!isset ($ parameter ['in ' ])) {
266+ throw new InvalidArgumentException (\sprintf ('OpenAPI parameter "%s" is missing the required "in" key. ' , $ parameter ['name ' ]));
267+ }
268+
261269 $ parameters [] = new Parameter (
262270 name: $ parameter ['name ' ],
263271 in: $ parameter ['in ' ],
Original file line number Diff line number Diff line change @@ -518,6 +518,14 @@ public function testOpenApiParameters(): void
518518 $ this ->assertEquals ('john-doe ' , $ operation ->getParameters ()[0 ]->getExample ());
519519 }
520520
521+ public function testOpenApiParameterWithoutNameThrowsClearException (): void
522+ {
523+ $ this ->expectException (InvalidArgumentException::class);
524+ $ this ->expectExceptionMessage ('OpenAPI parameter is missing the required "name" key ' );
525+
526+ (new YamlResourceExtractor ([__DIR__ .'/yaml/openapi-parameter-without-name.yaml ' ]))->getResources ();
527+ }
528+
521529 public function testInputAndOutputAreBooleans (): void
522530 {
523531 $ extractor = new YamlResourceExtractor ([__DIR__ .'/yaml/input-and-output-are-booleans.yaml ' ]);
Original file line number Diff line number Diff line change 1+ resources :
2+ ApiPlatform\Metadata\Tests\Fixtures\ApiResource\Program :
3+ - uriTemplate : /programs.{_format}
4+ operations :
5+ ApiPlatform\Metadata\GetCollection :
6+ openapi :
7+ parameters :
8+ - in : query
9+ description : A parameter without a name
You can’t perform that action at this time.
0 commit comments