From 0aa1619c5fc3609755b0e40bf552da6907aa5cbb Mon Sep 17 00:00:00 2001 From: fvilpoix Date: Wed, 26 Dec 2012 12:23:28 +0100 Subject: [PATCH] adding 'authentication' attribute --- Annotation/ApiDoc.php | 26 +++++++++++++++++++ Resources/public/css/screen.css | 2 +- Resources/public/image/man.png | Bin 0 -> 1341 bytes Resources/views/method.html.twig | 5 +++- Tests/Annotation/ApiDocTest.php | 13 ++++++++++ Tests/Extractor/ApiDocExtratorTest.php | 12 +++++++++ Tests/Fixtures/Controller/TestController.php | 8 ++++++ Tests/Fixtures/app/config/routing.yml | 4 +++ Tests/Formatter/SimpleFormatterTest.php | 1 + 9 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 Resources/public/image/man.png diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php index aac6f38..ccecc15 100644 --- a/Annotation/ApiDoc.php +++ b/Annotation/ApiDoc.php @@ -93,6 +93,11 @@ class ApiDoc */ private $https = false; + /** + * @var boolean + */ + private $authentication = false; + /** * @var array */ @@ -128,6 +133,10 @@ class ApiDoc if (isset($data['statusCodes'])) { $this->statusCodes = $data['statusCodes']; } + + if (isset($data['authentication'])) { + $this->setAuthentication((bool) $data['authentication']); + } } /** @@ -265,6 +274,22 @@ class ApiDoc $this->https = $https; } + /** + * @return boolean + */ + public function getAuthentication() + { + return $this->authentication; + } + + /** + * @param boolean $secured + */ + public function setAuthentication($authentication) + { + $this->authentication = $authentication; + } + /** * @return array */ @@ -304,6 +329,7 @@ class ApiDoc } $data['https'] = $this->https; + $data['authentication'] = $this->authentication; return $data; } diff --git a/Resources/public/css/screen.css b/Resources/public/css/screen.css index 47843ca..fcf1848 100644 --- a/Resources/public/css/screen.css +++ b/Resources/public/css/screen.css @@ -538,7 +538,7 @@ form .request-content { margin-bottom: 10px; } -.padlock { +.icon { height: 12px; margin-left: 3px; } \ No newline at end of file diff --git a/Resources/public/image/man.png b/Resources/public/image/man.png new file mode 100644 index 0000000000000000000000000000000000000000..567fb4130c301ccdcbec30ac8432b033ee7bb13b GIT binary patch literal 1341 zcmaJ>Z)n_P7*AJpW2_&BV_H9GNGERAyCio_E*I|F=91ic+tQZni5){|n!I-xFaJ#5 zcxh2Ab0`i)I~iptZqo^ytaIXULt#^~4F7x>`y%yIarh6VRSuc>L49+*>k5vA#7GZL3btr zUa-^(C<0ZVdg@D%!LZI{qcjf3m3_SCSaCJdiHDYp&={5(2whdH0f#~FoEToF`_p=l3{O%Io}>6(_-iGhAR6Y|J_1)z$DmTCKZm?fHad9;tjB!M?o zU@c3mk{VY=anbPr&cu^3jiPCsW#e=o!?N_Fc!Hu6B!zA^M)&ay%O_HJ>mrahPcQRD zDc|yiPFbP~q05tGyxO$HpUz z>ZB9EEP|Ia&~XEl61+2n?NP z8JSI{DVAf!JWWeEft3>y$E8GB5OaN0DsmPXSPw*!xQ?(g&2daRFHmfXqiH#jPUj_o z&2t+Ok<$ok+`=Nycfj(Z2UO^ICC4$_tuk75pyO8^7Z=A^e5ayn zh8+oZMU`xE1)lLV(DR;S;muO;#%&l-G=~~3g|6%16D+yFmq8O1TNJK{0cxXTqw0cx9VQXg^QJ?UpYFAJ~Vmc_RfeDHJiaF(0 z4b8Fr3>o#HX&^vzw~8g#S!{~eHEmlHO+vI?8$onf8)9Ii$@S2PK5*pNvuM13C`dvn z{O+5hzjl32Z8>x!e(iim50%?Ju`U1ePPG#)i!=JciM>CLh`(h97p|Wr{nU5(#7VF7uH}o}wT+jV!GZoA&o_=Q)N>!c wGZU_yxI_v!y-!mwns5L6!qo>qxUqMp1N+R}pls=wyC?dg735**TyEmvfAodMH~;_u literal 0 HcmV?d00001 diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig index e623f13..0721d87 100644 --- a/Resources/views/method.html.twig +++ b/Resources/views/method.html.twig @@ -6,7 +6,10 @@ {% if data.https %} - + HTTPS + {% endif %} + {% if data.authentication %} + Needs authentication {% endif %} diff --git a/Tests/Annotation/ApiDocTest.php b/Tests/Annotation/ApiDocTest.php index c03b280..b5c6007 100644 --- a/Tests/Annotation/ApiDocTest.php +++ b/Tests/Annotation/ApiDocTest.php @@ -28,6 +28,7 @@ class ApiDocTest extends TestCase $this->assertFalse($annot->isResource()); $this->assertFalse(isset($array['description'])); $this->assertNull($annot->getInput()); + $this->assertFalse($array['authentication']); } public function testConstructWithInvalidData() @@ -193,4 +194,16 @@ class ApiDocTest extends TestCase $this->assertEquals($array['statusCodes'][$code], $message); } } + + public function testConstructWithAuthentication() + { + $data = array( + 'authentication' => true + ); + + $annot = new ApiDoc($data); + $array = $annot->toArray(); + + $this->assertTrue($array['authentication']); + } } diff --git a/Tests/Extractor/ApiDocExtratorTest.php b/Tests/Extractor/ApiDocExtratorTest.php index fadd412..261340f 100644 --- a/Tests/Extractor/ApiDocExtratorTest.php +++ b/Tests/Extractor/ApiDocExtratorTest.php @@ -152,4 +152,16 @@ class ApiDocExtractorTest extends WebTestCase $annotation->getDescription() ); } + + public function testGetWithAuthentication() + { + $container = $this->getContainer(); + $extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor'); + $annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::AuthenticatedAction', 'test_route_13'); + + $this->assertNotNull($annotation); + $this->assertTrue( + $annotation->getAuthentication() + ); + } } diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index 38d7fe1..714a7e6 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -127,4 +127,12 @@ class TestController { } + /** + * @ApiDoc( + * authentication=true + * ) + */ + public function authenticatedAction() + { + } } diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml index d72aaa6..d128ce0 100644 --- a/Tests/Fixtures/app/config/routing.yml +++ b/Tests/Fixtures/app/config/routing.yml @@ -64,6 +64,10 @@ test_route_12: requirements: _scheme: https +test_route_13: + pattern: /authenticated + defaults: { _controller: NelmioApiDocTestBundle:Test:authenticated } + test_service_route_1: pattern: /tests.{_format} defaults: { _controller: nemlio.test.controller:indexAction, _format: json } diff --git a/Tests/Formatter/SimpleFormatterTest.php b/Tests/Formatter/SimpleFormatterTest.php index 060f779..be00e0b 100644 --- a/Tests/Formatter/SimpleFormatterTest.php +++ b/Tests/Formatter/SimpleFormatterTest.php @@ -385,6 +385,7 @@ With multiple lines.', '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), ), 'https' => false, + 'authentication' => false, ); $this->assertEquals($expected, $result);