diff --git a/Extractor/Handler/FosRestHandler.php b/Extractor/Handler/FosRestHandler.php index 8bddabe33..4f958e5f0 100644 --- a/Extractor/Handler/FosRestHandler.php +++ b/Extractor/Handler/FosRestHandler.php @@ -56,11 +56,15 @@ public function handle(ApiDoc $annotation, array $annotations, Route $route, \Re 'description' => $annot->description, 'default' => $annot->default, )); - } else { + } elseif ($annot->requirements !== null) { $annotation->addFilter($annot->name, array( 'requirement' => $this->handleRequirements($annot->requirements).((property_exists($annot, 'map') ? $annot->map : $annot->array) ? '[]' : ''), 'description' => $annot->description, )); + } else { + $annotation->addFilter($annot->name, array( + 'description' => $annot->description, + )); } } } diff --git a/Tests/Extractor/Handler/FosRestHandlerTest.php b/Tests/Extractor/Handler/FosRestHandlerTest.php index 3fcac8731..616bb2e17 100644 --- a/Tests/Extractor/Handler/FosRestHandlerTest.php +++ b/Tests/Extractor/Handler/FosRestHandlerTest.php @@ -203,4 +203,22 @@ public function testWithRequestParamPlainArrayRequirements() $this->assertArrayHasKey('requirement', $filters['param1']); $this->assertEquals('NotNull, NotBlank', $filters['param1']['requirement']); } + + public function testWithRequirementParamNotSet() + { + $container = $this->getContainer(); + $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor'); + $annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithRequirementParamNotSet', 'test_route_31'); + + $this->assertNotNull($annotation); + + $filters = $annotation->getFilters(); + $this->assertCount(1, $filters); + $this->assertArrayHasKey('param1', $filters); + $filter = $filters['param1']; + + $this->assertArrayNotHasKey('requirement', $filter); + $this->assertArrayHasKey('description', $filter); + $this->assertEquals($filter['description'], 'Param1 description.'); + } } diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index 9bc4fd9ae..f4e4b163b 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -414,4 +414,12 @@ public function routeWithQueryParamArrayRequirementsAction() public function routeWithQueryParamPlainArrayRequirementsAction() { } + + /** + * @ApiDoc() + * @QueryParam(name="param1", description="Param1 description.") + */ + public function zActionWithRequirementParamNotSet() + { + } } diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml index 9cba5f659..338640bf9 100644 --- a/Tests/Fixtures/app/config/routing.yml +++ b/Tests/Fixtures/app/config/routing.yml @@ -248,3 +248,8 @@ test_route_30: path: /z-query-param-plain-array-requirements methods: [GET] defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithQueryParamPlainArrayRequirementsAction } + +test_route_31: + path: /z-query-requirement-param-not-set + methods: [GET] + defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithRequirementParamNotSet }