diff --git a/Extractor/Handler/FosRestHandler.php b/Extractor/Handler/FosRestHandler.php index 636e05f..1fe3659 100644 --- a/Extractor/Handler/FosRestHandler.php +++ b/Extractor/Handler/FosRestHandler.php @@ -33,7 +33,7 @@ class FosRestHandler implements HandlerInterface $requirements = $this->handleRequirements($annot->requirements); $data = array( 'required' => $annot->strict && $annot->nullable === false && $annot->default === null, - 'dataType' => $requirements, + 'dataType' => $requirements.($annot->array ? '[]' : ''), 'actualType' => $this->inferType($requirements), 'subType' => null, 'description' => $annot->description, @@ -46,19 +46,19 @@ class FosRestHandler implements HandlerInterface } elseif ($annot instanceof QueryParam) { if ($annot->strict && $annot->nullable === false && $annot->default === null) { $annotation->addRequirement($annot->name, array( - 'requirement' => $this->handleRequirements($annot->requirements), + 'requirement' => $this->handleRequirements($annot->requirements).($annot->array ? '[]' : ''), 'dataType' => '', 'description' => $annot->description, )); } elseif ($annot->default !== null) { $annotation->addFilter($annot->name, array( - 'requirement' => $this->handleRequirements($annot->requirements), + 'requirement' => $this->handleRequirements($annot->requirements).($annot->array ? '[]' : ''), 'description' => $annot->description, 'default' => $annot->default, )); } else { $annotation->addFilter($annot->name, array( - 'requirement' => $this->handleRequirements($annot->requirements), + 'requirement' => $this->handleRequirements($annot->requirements).($annot->array ? '[]' : ''), 'description' => $annot->description, )); } diff --git a/Tests/Extractor/Handler/FosRestHandlerTest.php b/Tests/Extractor/Handler/FosRestHandlerTest.php index 87e31e0..0614a03 100644 --- a/Tests/Extractor/Handler/FosRestHandlerTest.php +++ b/Tests/Extractor/Handler/FosRestHandlerTest.php @@ -156,4 +156,22 @@ class FosRestHandlerTest extends WebTestCase $this->assertArrayNotHasKey('default', $parameter); } + + public function testPostWithArrayRequestParam() + { + $container = $this->getContainer(); + $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor'); + $annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zActionWithArrayRequestParamAction', 'test_route_26'); + + $this->assertNotNull($annotation); + + $parameters = $annotation->getParameters(); + $this->assertCount(1, $parameters); + $this->assertArrayHasKey('param1', $parameters); + + $parameter = $parameters['param1']; + + $this->assertArrayHasKey('dataType', $parameter); + $this->assertEquals('string[]', $parameter['dataType']); + } } diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index 516d204..149a8dc 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -189,6 +189,14 @@ class TestController { } + /** + * @ApiDoc() + * @RequestParam(name="param1", requirements="string", array=true) + */ + public function zActionWithArrayRequestParamAction() + { + } + /** * @ApiDoc() */ diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml index 09afa94..88e6b4f 100644 --- a/Tests/Fixtures/app/config/routing.yml +++ b/Tests/Fixtures/app/config/routing.yml @@ -239,3 +239,9 @@ test_route_25: defaults: { _controller: NelmioApiDocTestBundle:Test:withLinkAction } requirements: _method: GET + +test_route_26: + pattern: /z-action-with-array-request-param + defaults: { _controller: NelmioApiDocTestBundle:Test:zActionWithArrayRequestParamAction } + requirements: + _method: POST