diff --git a/Extractor/Handler/FosRestHandler.php b/Extractor/Handler/FosRestHandler.php index 7c22694d2..056230c1e 100644 --- a/Extractor/Handler/FosRestHandler.php +++ b/Extractor/Handler/FosRestHandler.php @@ -83,6 +83,10 @@ private function handleRequirements($requirements) return substr($class, strrpos($class, '\\')+1); } + if (is_array($requirements) && isset($requirements['rule'])) { + return (string) $requirements['rule']; + } + return (string) $requirements; } diff --git a/Tests/Extractor/Handler/FosRestHandlerTest.php b/Tests/Extractor/Handler/FosRestHandlerTest.php index 500cc3153..ea6d25242 100644 --- a/Tests/Extractor/Handler/FosRestHandlerTest.php +++ b/Tests/Extractor/Handler/FosRestHandlerTest.php @@ -175,4 +175,18 @@ public function testPostWithArrayRequestParam() $this->assertArrayHasKey('dataType', $parameter); $this->assertEquals('string[]', $parameter['dataType']); } + + public function testWithRequestParamArrayRequirements() + { + $container = $this->getContainer(); + $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor'); + $annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithQueryParamArrayRequirementsAction', 'test_route_29'); + + $this->assertNotNull($annotation); + $filters = $annotation->getFilters(); + + $this->assertArrayHasKey('param1', $filters); + $this->assertArrayHasKey('requirement', $filters['param1']); + $this->assertEquals('regexp', $filters['param1']['requirement']); + } } diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index d316dd091..a60ecc91a 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -398,4 +398,12 @@ public function defaultJmsAnnotations() public function routeWithHostAction() { } + + /** + * @ApiDoc() + * @QueryParam(name="param1", requirements={"rule": "regexp", "error_message": "warning"}, description="Param1 description.") + */ + public function routeWithQueryParamArrayRequirementsAction() + { + } } diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml index 6e8c47943..fe077c0d0 100644 --- a/Tests/Fixtures/app/config/routing.yml +++ b/Tests/Fixtures/app/config/routing.yml @@ -238,3 +238,8 @@ test_route_28: requirements: domain: "%domain_dev%|%domain_prod%" defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithHost, domain: "%domain_dev%", _format: json } + +test_route_29: + path: /z-query-param-array-requirements + methods: [GET] + defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithQueryParamArrayRequirementsAction }