Skip to content

Commit

Permalink
Merge pull request nelmio#780 from damienalexandre/fixArrayToString
Browse files Browse the repository at this point in the history
Fix Array to string conversion error on array requirements
  • Loading branch information
willdurand committed Jan 8, 2016
2 parents 1ae2cfa + 306f2c4 commit 5d9c47b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Extractor/Handler/FosRestHandler.php
Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions Tests/Extractor/Handler/FosRestHandlerTest.php
Expand Up @@ -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']);
}
}
8 changes: 8 additions & 0 deletions Tests/Fixtures/Controller/TestController.php
Expand Up @@ -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()
{
}
}
5 changes: 5 additions & 0 deletions Tests/Fixtures/app/config/routing.yml
Expand Up @@ -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 }

0 comments on commit 5d9c47b

Please sign in to comment.