From ef5cbd9b7356afa04dd92e8a8b729cd71d890575 Mon Sep 17 00:00:00 2001 From: Baldur Rensch Date: Mon, 10 Dec 2012 10:21:04 -0800 Subject: [PATCH] Added padlock icon for secure routes This fixes #115 - Added an https property to the annotation - Added glyphicon padlock icon - Updated Templates - Updated Unit tests --- Annotation/ApiDoc.php | 23 ++++++++++++ Extractor/ApiDocExtractor.php | 4 ++ Resources/public/css/screen.css | 5 +++ Resources/public/image/lock.png | Bin 0 -> 1301 bytes Resources/views/method.html.twig | 5 +++ Tests/Extractor/ApiDocExtratorTest.php | 5 ++- Tests/Fixtures/Controller/TestController.php | 7 ++++ Tests/Fixtures/app/config/routing.yml | 6 +++ Tests/Formatter/MarkdownFormatterTest.php | 10 +++++ Tests/Formatter/SimpleFormatterTest.php | 37 +++++++++++++++++-- 10 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 Resources/public/image/lock.png diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php index 184e1d3..aac6f38 100644 --- a/Annotation/ApiDoc.php +++ b/Annotation/ApiDoc.php @@ -88,6 +88,11 @@ class ApiDoc */ private $route; + /** + * @var boolean + */ + private $https = false; + /** * @var array */ @@ -244,6 +249,22 @@ class ApiDoc return $this->route; } + /** + * @return boolean + */ + public function getHttps() + { + return $this->https; + } + + /** + * @param boolean $https + */ + public function setHttps($https) + { + $this->https = $https; + } + /** * @return array */ @@ -282,6 +303,8 @@ class ApiDoc $data['statusCodes'] = $statusCodes; } + $data['https'] = $this->https; + return $data; } } diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 422bbbf..c0a325c 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -289,6 +289,10 @@ class ApiDocExtractor 'description' => '', ); } + if ('_scheme' == $name) { + $https = ('https' == $value); + $annotation->setHttps($https); + } } $paramDocs = array(); diff --git a/Resources/public/css/screen.css b/Resources/public/css/screen.css index 887c014..47843ca 100644 --- a/Resources/public/css/screen.css +++ b/Resources/public/css/screen.css @@ -537,3 +537,8 @@ form .request-content { margin-left: 20px; margin-bottom: 10px; } + +.padlock { + height: 12px; + margin-left: 3px; +} \ No newline at end of file diff --git a/Resources/public/image/lock.png b/Resources/public/image/lock.png new file mode 100644 index 0000000000000000000000000000000000000000..3376980665ca3367341659a14297fac3a4e9ab2a GIT binary patch literal 1301 zcmaJ>U5MON6i&O;x~+q*veqpXLRMu(XYwwdN*}aJLGZzceXxC#VrlUQLE0C=B2vAXo!Kr}8j{?5 zPtJGFcm8s`GB=ypwRaaqQHjz)y-L|-&@&;u2` zlxH?b)yoxHLm{NaR61#KJWm6V;xi%u{Ij&c@dC?{8zlLRA_7H_=;6f>Z=t=YRQ2M} z7dhpb7RG_XvYk#R)k&vN*kt)^HXGXzge1{OMm-;!-J~B)k1XggvO*`o4)W>PqS-)g zoM#BrjS#$`T;4S7N5e#sl(AhiVEGisdR`pYKs&-!c!$PawWC@ufNT{;s2y6Q9*ff> zFv;D$9gP%iYf~?1hwdOw+hU;$J?P_zkm3i72y^B6&>;mhT^(8N_-jeeGwrrxD?l_r zI?DkWXhoja3o0-KU6v)yP_;salVWGFfvrFyN!bLeaX`!HAj1Jw;CVyHW{bKCin1*0 zk|;}s5w_$<*z_$JJB_i<9c=oZSVaq=iBVWX$Q`vxrG+qxS}35k1whY~P0R6P!P9Xi zhg@OkEJM2(B99)FLUHcGfa7J-XcCE0AmQ`mB&UmpP*BsFXc$0bhFE(`%0`hB!2hs@ z1ay^4>zt_Z3`@w^mVzDZ!eNi9E*|b&C+-u)HT@<@NYaLjX4}Qg{-)atT8@SMD96S< z=sE;2*ll3hEfxpjEloSpB$E(tH%E{hHisDcWO73?qUWBuIZwv>o06{9xe|E# z{lJ@#?3wvYJ~oY?nEid`ord(rc%y%^bNbA~xxe4~^~TyqU%%FPmwIU8kMAbx55Ca& z;rIu)zTK&9o85V6srSoj<;82&@hdAUJJ#6k()y#df0ym@SFc=Ovu{_d-DfYl+b3_m z|Hb+zk5Lm>$HrfOuktp^j{QU5-gn~MDL=6~1)ux#@a1OW!+ob(<_iTU$QciWTa zFMWFTrOOxk%a`VVI{nm_Q!oE@ {{ data.method|upper }} + + {% if data.https %} + + {% endif %} + {{ data.uri }} diff --git a/Tests/Extractor/ApiDocExtratorTest.php b/Tests/Extractor/ApiDocExtratorTest.php index 17a4e97..fadd412 100644 --- a/Tests/Extractor/ApiDocExtratorTest.php +++ b/Tests/Extractor/ApiDocExtratorTest.php @@ -22,7 +22,7 @@ class ApiDocExtractorTest extends WebTestCase $data = $extractor->all(); $this->assertTrue(is_array($data)); - $this->assertCount(13, $data); + $this->assertCount(14, $data); foreach ($data as $d) { $this->assertTrue(is_array($d)); @@ -61,6 +61,9 @@ class ApiDocExtractorTest extends WebTestCase $this->assertEquals('create test', $a2->getDescription()); $this->assertFalse(isset($array2['filters'])); $this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput()); + + $a3 = $data['10']['annotation']; + $this->assertTrue($a3->getHttps()); } public function testGet() diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index a55c0af..38d7fe1 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -120,4 +120,11 @@ class TestController { } + /** + * @ApiDoc() + */ + public function secureRouteAction() + { + } + } diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml index ba5f121..d72aaa6 100644 --- a/Tests/Fixtures/app/config/routing.yml +++ b/Tests/Fixtures/app/config/routing.yml @@ -58,6 +58,12 @@ test_route_11: requirements: _method: POST +test_route_12: + pattern: /secure-route + defaults: { _controller: NelmioApiDocTestBundle:Test:secureRoute } + requirements: + _scheme: https + test_service_route_1: pattern: /tests.{_format} defaults: { _controller: nemlio.test.controller:indexAction, _format: json } diff --git a/Tests/Formatter/MarkdownFormatterTest.php b/Tests/Formatter/MarkdownFormatterTest.php index f90f111..87cac08 100644 --- a/Tests/Formatter/MarkdownFormatterTest.php +++ b/Tests/Formatter/MarkdownFormatterTest.php @@ -247,6 +247,16 @@ _This method is useful to test if the getDocComment works._ - Type: int +### `ANY` /secure-route ### + + +#### Requirements #### + +**_scheme** + + - Requirement: https + + ### `ANY` /yet-another/{id} ### diff --git a/Tests/Formatter/SimpleFormatterTest.php b/Tests/Formatter/SimpleFormatterTest.php index af5236b..060f779 100644 --- a/Tests/Formatter/SimpleFormatterTest.php +++ b/Tests/Formatter/SimpleFormatterTest.php @@ -50,6 +50,7 @@ class SimpleFormatterTest extends WebTestCase 'requirements' => array( '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), ), + 'https' => false, ), 1 => array( @@ -75,6 +76,7 @@ class SimpleFormatterTest extends WebTestCase 'requirements' => array( '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), ), + 'https' => false, ), 2 => array( @@ -108,6 +110,7 @@ class SimpleFormatterTest extends WebTestCase 'requirements' => array( '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), ), + 'https' => false, ), 3 => array( @@ -141,6 +144,7 @@ class SimpleFormatterTest extends WebTestCase 'requirements' => array( '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), ), + 'https' => false, ), ), 'others' => @@ -160,12 +164,14 @@ class SimpleFormatterTest extends WebTestCase ), ), 'description' => 'create another test', + 'https' => false, ), 1 => array( 'method' => 'ANY', 'uri' => '/any', 'description' => 'Action without HTTP verb', + 'https' => false, ), 2 => array( @@ -176,6 +182,7 @@ class SimpleFormatterTest extends WebTestCase 'foo' => array('dataType' => '', 'description' => '', 'requirement' => ''), ), 'description' => 'Action without HTTP verb', + 'https' => false, ), 3 => array( @@ -268,7 +275,8 @@ With multiple lines.', ) ), ), - 'description' => 'Testing JMS' + 'description' => 'Testing JMS', + 'https' => false, ), 4 => array( @@ -282,7 +290,8 @@ With multiple lines.', 'description' => 'A nice description', 'readonly' => false ) - ) + ), + 'https' => false, ), 5 => array( @@ -293,10 +302,26 @@ With multiple lines.', 'id' => array('dataType' => 'int', 'description' => 'A nice comment', 'requirement' => ''), 'page' => array('dataType' => 'int', 'description' => '', 'requirement' => ''), ), + 'https' => false, 'description' => 'This method is useful to test if the getDocComment works.', 'documentation' => "This method is useful to test if the getDocComment works.\nAnd, it supports multilines until the first '@' char." ), 6 => + array( + 'method' => 'ANY', + 'uri' => '/secure-route', + // 'description' => '[secureRouteAction description]', + // 'documentation' => '[secureRouteAction description]', + 'requirements' => array( + '_scheme' => array( + 'requirement' => 'https', + 'dataType' => null, + 'description' => null, + ), + ), + 'https' => true, + ), + 7 => array( 'method' => 'ANY', 'uri' => '/yet-another/{id}', @@ -304,8 +329,9 @@ With multiple lines.', array( 'id' => array('dataType' => '', 'description' => '', 'requirement' => '\d+') ), + 'https' => false, ), - 7 => + 8 => array( 'method' => 'GET', 'uri' => '/z-action-with-query-param', @@ -313,8 +339,9 @@ With multiple lines.', array( 'page' => array('description' => 'Page of the overview.', 'requirement' => '\d+') ), + 'https' => false, ), - 8 => + 9 => array( 'method' => 'POST', 'uri' => '/z-action-with-request-param', @@ -322,6 +349,7 @@ With multiple lines.', array( 'param1' => array('description' => 'Param1 description.', 'required' => true, 'dataType' => 'string', 'readonly' => false) ), + 'https' => false, ), ), ); @@ -356,6 +384,7 @@ With multiple lines.', 'requirements' => array( '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), ), + 'https' => false, ); $this->assertEquals($expected, $result);