mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Added support for Security annotation
This commit is contained in:
parent
72a1418b7d
commit
16b104edec
@ -15,6 +15,7 @@ use Nelmio\ApiDocBundle\Extractor\HandlerInterface;
|
||||
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
|
||||
class SensioFrameworkExtraHandler implements HandlerInterface
|
||||
{
|
||||
@ -23,6 +24,8 @@ class SensioFrameworkExtraHandler implements HandlerInterface
|
||||
foreach ($annotations as $annot) {
|
||||
if ($annot instanceof Cache) {
|
||||
$annotation->setCache($annot->getMaxAge());
|
||||
} elseif ($annot instanceof Security) {
|
||||
$annotation->setAuthentication(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
||||
|
||||
class ApiDocExtractorTest extends WebTestCase
|
||||
{
|
||||
const ROUTES_QUANTITY = 31;
|
||||
const ROUTES_QUANTITY = 33;
|
||||
|
||||
public function testAll()
|
||||
{
|
||||
@ -199,7 +199,7 @@ class ApiDocExtractorTest extends WebTestCase
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::CachedAction', 'test_route_14');
|
||||
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zCachedAction', 'test_route_23');
|
||||
|
||||
$this->assertNotNull($annotation);
|
||||
$this->assertEquals(
|
||||
|
38
Tests/Extractor/Handler/SensioFrameworkExtraHandlerTest.php
Normal file
38
Tests/Extractor/Handler/SensioFrameworkExtraHandlerTest.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the NelmioApiDocBundle.
|
||||
*
|
||||
* (c) Nelmio <hello@nelm.io>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Extractor;
|
||||
|
||||
use Nelmio\ApiDocBundle\Tests\WebTestCase;
|
||||
|
||||
class SensioFrameworkExtraHandlerTest extends WebTestCase
|
||||
{
|
||||
public function testCacheAnnotation()
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zCachedAction', 'test_route_23');
|
||||
|
||||
$this->assertNotNull($annotation);
|
||||
|
||||
$this->assertSame(60, $annotation->getCache());
|
||||
}
|
||||
|
||||
public function testSecurityAnnotation()
|
||||
{
|
||||
$container = $this->getContainer();
|
||||
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
|
||||
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::zSecuredAction', 'test_route_24');
|
||||
|
||||
$this->assertNotNull($annotation);
|
||||
|
||||
$this->assertTrue($annotation->getAuthentication());
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ use Nelmio\ApiDocBundle\Annotation\ApiDoc;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Constraints\Email;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
|
||||
class TestController
|
||||
{
|
||||
@ -196,7 +197,15 @@ class TestController
|
||||
* @ApiDoc()
|
||||
* @Cache(maxage=60, public=1)
|
||||
*/
|
||||
public function cachedAction()
|
||||
public function zCachedAction()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @ApiDoc()
|
||||
* @Security("has_role('ROLE_USER')")
|
||||
*/
|
||||
public function zSecuredAction()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -206,4 +206,16 @@ test_route_update_another_resource:
|
||||
|
||||
swagger_doc:
|
||||
resource: @NelmioApiDocBundle/Resources/config/swagger_routing.yml
|
||||
prefix: /api-docs
|
||||
prefix: /api-docs
|
||||
|
||||
test_route_23:
|
||||
pattern: /zcached
|
||||
defaults: { _controller: NelmioApiDocTestBundle:Test:zCached }
|
||||
requirements:
|
||||
_method: POST
|
||||
|
||||
test_route_24:
|
||||
pattern: /zsecured
|
||||
defaults: { _controller: NelmioApiDocTestBundle:Test:zSecured }
|
||||
requirements:
|
||||
_method: POST
|
||||
|
@ -835,6 +835,13 @@ related[a]:
|
||||
related[b]:
|
||||
|
||||
* type: DateTime
|
||||
|
||||
|
||||
### `POST` /zcached ###
|
||||
|
||||
|
||||
|
||||
### `POST` /zsecured ###
|
||||
MARKDOWN;
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -1237,6 +1237,25 @@ With multiple lines.',
|
||||
)
|
||||
),
|
||||
'authenticationRoles' => array(),
|
||||
),
|
||||
19 =>
|
||||
array(
|
||||
'cache' => 60,
|
||||
'method' => 'POST',
|
||||
'uri' => '/zcached',
|
||||
'https' => false,
|
||||
'authentication' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false
|
||||
),
|
||||
20 =>
|
||||
array(
|
||||
'authentication' => true,
|
||||
'method' => 'POST',
|
||||
'uri' => '/zsecured',
|
||||
'https' => false,
|
||||
'authenticationRoles' => array(),
|
||||
'deprecated' => false
|
||||
)
|
||||
),
|
||||
'/tests2' =>
|
||||
|
@ -32,7 +32,7 @@
|
||||
"symfony/form": "~2.1",
|
||||
"friendsofsymfony/rest-bundle": "~1.0",
|
||||
"jms/serializer-bundle": ">=0.11",
|
||||
"sensio/framework-extra-bundle": "~2.1"
|
||||
"sensio/framework-extra-bundle": "~3.0"
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/form": "For using form definitions as input.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user