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
This commit is contained in:
Baldur Rensch 2012-12-10 10:21:04 -08:00
parent 63c19758aa
commit ef5cbd9b73
10 changed files with 97 additions and 5 deletions

View File

@ -88,6 +88,11 @@ class ApiDoc
*/ */
private $route; private $route;
/**
* @var boolean
*/
private $https = false;
/** /**
* @var array * @var array
*/ */
@ -244,6 +249,22 @@ class ApiDoc
return $this->route; return $this->route;
} }
/**
* @return boolean
*/
public function getHttps()
{
return $this->https;
}
/**
* @param boolean $https
*/
public function setHttps($https)
{
$this->https = $https;
}
/** /**
* @return array * @return array
*/ */
@ -282,6 +303,8 @@ class ApiDoc
$data['statusCodes'] = $statusCodes; $data['statusCodes'] = $statusCodes;
} }
$data['https'] = $this->https;
return $data; return $data;
} }
} }

View File

@ -289,6 +289,10 @@ class ApiDocExtractor
'description' => '', 'description' => '',
); );
} }
if ('_scheme' == $name) {
$https = ('https' == $value);
$annotation->setHttps($https);
}
} }
$paramDocs = array(); $paramDocs = array();

View File

@ -537,3 +537,8 @@ form .request-content {
margin-left: 20px; margin-left: 20px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.padlock {
height: 12px;
margin-left: 3px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -4,6 +4,11 @@
<span class="http_method"> <span class="http_method">
<a>{{ data.method|upper }}</a> <a>{{ data.method|upper }}</a>
</span> </span>
{% if data.https %}
<img src="{{ asset('bundles/nelmioapidoc/image/lock.png') }}" class="padlock" />
{% endif %}
<span class="path"> <span class="path">
{{ data.uri }} {{ data.uri }}
</span> </span>

View File

@ -22,7 +22,7 @@ class ApiDocExtractorTest extends WebTestCase
$data = $extractor->all(); $data = $extractor->all();
$this->assertTrue(is_array($data)); $this->assertTrue(is_array($data));
$this->assertCount(13, $data); $this->assertCount(14, $data);
foreach ($data as $d) { foreach ($data as $d) {
$this->assertTrue(is_array($d)); $this->assertTrue(is_array($d));
@ -61,6 +61,9 @@ class ApiDocExtractorTest extends WebTestCase
$this->assertEquals('create test', $a2->getDescription()); $this->assertEquals('create test', $a2->getDescription());
$this->assertFalse(isset($array2['filters'])); $this->assertFalse(isset($array2['filters']));
$this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput()); $this->assertEquals('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', $a2->getInput());
$a3 = $data['10']['annotation'];
$this->assertTrue($a3->getHttps());
} }
public function testGet() public function testGet()

View File

@ -120,4 +120,11 @@ class TestController
{ {
} }
/**
* @ApiDoc()
*/
public function secureRouteAction()
{
}
} }

View File

@ -58,6 +58,12 @@ test_route_11:
requirements: requirements:
_method: POST _method: POST
test_route_12:
pattern: /secure-route
defaults: { _controller: NelmioApiDocTestBundle:Test:secureRoute }
requirements:
_scheme: https
test_service_route_1: test_service_route_1:
pattern: /tests.{_format} pattern: /tests.{_format}
defaults: { _controller: nemlio.test.controller:indexAction, _format: json } defaults: { _controller: nemlio.test.controller:indexAction, _format: json }

View File

@ -247,6 +247,16 @@ _This method is useful to test if the getDocComment works._
- Type: int - Type: int
### `ANY` /secure-route ###
#### Requirements ####
**_scheme**
- Requirement: https
### `ANY` /yet-another/{id} ### ### `ANY` /yet-another/{id} ###

View File

@ -50,6 +50,7 @@ class SimpleFormatterTest extends WebTestCase
'requirements' => array( 'requirements' => array(
'_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''),
), ),
'https' => false,
), ),
1 => 1 =>
array( array(
@ -75,6 +76,7 @@ class SimpleFormatterTest extends WebTestCase
'requirements' => array( 'requirements' => array(
'_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''),
), ),
'https' => false,
), ),
2 => 2 =>
array( array(
@ -108,6 +110,7 @@ class SimpleFormatterTest extends WebTestCase
'requirements' => array( 'requirements' => array(
'_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''),
), ),
'https' => false,
), ),
3 => 3 =>
array( array(
@ -141,6 +144,7 @@ class SimpleFormatterTest extends WebTestCase
'requirements' => array( 'requirements' => array(
'_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''),
), ),
'https' => false,
), ),
), ),
'others' => 'others' =>
@ -160,12 +164,14 @@ class SimpleFormatterTest extends WebTestCase
), ),
), ),
'description' => 'create another test', 'description' => 'create another test',
'https' => false,
), ),
1 => 1 =>
array( array(
'method' => 'ANY', 'method' => 'ANY',
'uri' => '/any', 'uri' => '/any',
'description' => 'Action without HTTP verb', 'description' => 'Action without HTTP verb',
'https' => false,
), ),
2 => 2 =>
array( array(
@ -176,6 +182,7 @@ class SimpleFormatterTest extends WebTestCase
'foo' => array('dataType' => '', 'description' => '', 'requirement' => ''), 'foo' => array('dataType' => '', 'description' => '', 'requirement' => ''),
), ),
'description' => 'Action without HTTP verb', 'description' => 'Action without HTTP verb',
'https' => false,
), ),
3 => 3 =>
array( array(
@ -268,7 +275,8 @@ With multiple lines.',
) )
), ),
), ),
'description' => 'Testing JMS' 'description' => 'Testing JMS',
'https' => false,
), ),
4 => 4 =>
array( array(
@ -282,7 +290,8 @@ With multiple lines.',
'description' => 'A nice description', 'description' => 'A nice description',
'readonly' => false 'readonly' => false
) )
) ),
'https' => false,
), ),
5 => 5 =>
array( array(
@ -293,10 +302,26 @@ With multiple lines.',
'id' => array('dataType' => 'int', 'description' => 'A nice comment', 'requirement' => ''), 'id' => array('dataType' => 'int', 'description' => 'A nice comment', 'requirement' => ''),
'page' => array('dataType' => 'int', 'description' => '', 'requirement' => ''), 'page' => array('dataType' => 'int', 'description' => '', 'requirement' => ''),
), ),
'https' => false,
'description' => 'This method is useful to test if the getDocComment works.', '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." 'documentation' => "This method is useful to test if the getDocComment works.\nAnd, it supports multilines until the first '@' char."
), ),
6 => 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( array(
'method' => 'ANY', 'method' => 'ANY',
'uri' => '/yet-another/{id}', 'uri' => '/yet-another/{id}',
@ -304,8 +329,9 @@ With multiple lines.',
array( array(
'id' => array('dataType' => '', 'description' => '', 'requirement' => '\d+') 'id' => array('dataType' => '', 'description' => '', 'requirement' => '\d+')
), ),
'https' => false,
), ),
7 => 8 =>
array( array(
'method' => 'GET', 'method' => 'GET',
'uri' => '/z-action-with-query-param', 'uri' => '/z-action-with-query-param',
@ -313,8 +339,9 @@ With multiple lines.',
array( array(
'page' => array('description' => 'Page of the overview.', 'requirement' => '\d+') 'page' => array('description' => 'Page of the overview.', 'requirement' => '\d+')
), ),
'https' => false,
), ),
8 => 9 =>
array( array(
'method' => 'POST', 'method' => 'POST',
'uri' => '/z-action-with-request-param', 'uri' => '/z-action-with-request-param',
@ -322,6 +349,7 @@ With multiple lines.',
array( array(
'param1' => array('description' => 'Param1 description.', 'required' => true, 'dataType' => 'string', 'readonly' => false) 'param1' => array('description' => 'Param1 description.', 'required' => true, 'dataType' => 'string', 'readonly' => false)
), ),
'https' => false,
), ),
), ),
); );
@ -356,6 +384,7 @@ With multiple lines.',
'requirements' => array( 'requirements' => array(
'_format' => array('dataType' => '', 'description' => '', 'requirement' => ''), '_format' => array('dataType' => '', 'description' => '', 'requirement' => ''),
), ),
'https' => false,
); );
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);