mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
parent
5d9c47bbad
commit
f2fc6b47c0
@ -87,6 +87,34 @@ class FosRestHandler implements HandlerInterface
|
|||||||
return (string) $requirements['rule'];
|
return (string) $requirements['rule'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_array($requirements) && array_key_exists(0, $requirements)) {
|
||||||
|
|
||||||
|
$output = array();
|
||||||
|
|
||||||
|
foreach ($requirements as $req) {
|
||||||
|
|
||||||
|
if (is_object($req) && $req instanceof Constraint) {
|
||||||
|
if ($req instanceof Regex) {
|
||||||
|
$output[] = $req->getHtmlPattern();
|
||||||
|
} else {
|
||||||
|
$class = get_class($req);
|
||||||
|
$output[] = substr($class, strrpos($class, '\\')+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_array($req)) {
|
||||||
|
if (array_key_exists('_format', $req)) {
|
||||||
|
$output[] = 'Format: '.$req['_format'];
|
||||||
|
} else if (isset($req['rule'])) {
|
||||||
|
$output[] = $req['rule'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(', ', $output);
|
||||||
|
}
|
||||||
|
|
||||||
return (string) $requirements;
|
return (string) $requirements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,4 +189,18 @@ class FosRestHandlerTest extends WebTestCase
|
|||||||
$this->assertArrayHasKey('requirement', $filters['param1']);
|
$this->assertArrayHasKey('requirement', $filters['param1']);
|
||||||
$this->assertEquals('regexp', $filters['param1']['requirement']);
|
$this->assertEquals('regexp', $filters['param1']['requirement']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWithRequestParamPlainArrayRequirements()
|
||||||
|
{
|
||||||
|
$container = $this->getContainer();
|
||||||
|
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||||
|
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::routeWithQueryParamPlainArrayRequirementsAction', 'test_route_30');
|
||||||
|
|
||||||
|
$this->assertNotNull($annotation);
|
||||||
|
$filters = $annotation->getFilters();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('param1', $filters);
|
||||||
|
$this->assertArrayHasKey('requirement', $filters['param1']);
|
||||||
|
$this->assertEquals('NotNull, NotBlank', $filters['param1']['requirement']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ use Nelmio\ApiDocBundle\Tests\Fixtures\DependencyTypePath;
|
|||||||
use Nelmio\ApiDocBundle\Tests\Fixtures\RequestParamHelper;
|
use Nelmio\ApiDocBundle\Tests\Fixtures\RequestParamHelper;
|
||||||
use Nelmio\ApiDocBundle\Util\LegacyFormHelper;
|
use Nelmio\ApiDocBundle\Util\LegacyFormHelper;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Validator\Constraints\Email;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ class TestController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @ApiDoc()
|
* @ApiDoc()
|
||||||
* @QueryParam(name="mail", requirements=@Email, description="Email of someone.")
|
* @QueryParam(name="mail", requirements=@Assert\Email, description="Email of someone.")
|
||||||
*/
|
*/
|
||||||
public function zActionWithConstraintAsRequirements()
|
public function zActionWithConstraintAsRequirements()
|
||||||
{
|
{
|
||||||
@ -406,4 +406,12 @@ class TestController
|
|||||||
public function routeWithQueryParamArrayRequirementsAction()
|
public function routeWithQueryParamArrayRequirementsAction()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ApiDoc()
|
||||||
|
* @QueryParam(name="param1", requirements={@Assert\NotNull(), @Assert\NotBlank()}, description="Param1 description.")
|
||||||
|
*/
|
||||||
|
public function routeWithQueryParamPlainArrayRequirementsAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,3 +243,8 @@ test_route_29:
|
|||||||
path: /z-query-param-array-requirements
|
path: /z-query-param-array-requirements
|
||||||
methods: [GET]
|
methods: [GET]
|
||||||
defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithQueryParamArrayRequirementsAction }
|
defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithQueryParamArrayRequirementsAction }
|
||||||
|
|
||||||
|
test_route_30:
|
||||||
|
path: /z-query-param-plain-array-requirements
|
||||||
|
methods: [GET]
|
||||||
|
defaults: { _controller: NelmioApiDocTestBundle:Test:routeWithQueryParamPlainArrayRequirementsAction }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user