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 0000000..3376980 Binary files /dev/null and b/Resources/public/image/lock.png differ diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig index 097841b..e623f13 100644 --- a/Resources/views/method.html.twig +++ b/Resources/views/method.html.twig @@ -4,6 +4,11 @@ {{ 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);