adding 'authentication' attribute

This commit is contained in:
fvilpoix 2012-12-26 12:23:28 +01:00
parent c946fbcf4f
commit 0aa1619c5f
9 changed files with 69 additions and 2 deletions

View File

@ -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;
}

View File

@ -538,7 +538,7 @@ form .request-content {
margin-bottom: 10px;
}
.padlock {
.icon {
height: 12px;
margin-left: 3px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -6,7 +6,10 @@
</span>
{% if data.https %}
<img src="{{ asset('bundles/nelmioapidoc/image/lock.png') }}" class="padlock" />
<img src="{{ asset('bundles/nelmioapidoc/image/lock.png') }}" class="icon" alt="HTTPS" />
{% endif %}
{% if data.authentication %}
<img src="{{ asset('bundles/nelmioapidoc/image/man.png') }}" class="icon" alt="Needs authentication" />
{% endif %}
<span class="path">

View File

@ -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']);
}
}

View File

@ -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()
);
}
}

View File

@ -127,4 +127,12 @@ class TestController
{
}
/**
* @ApiDoc(
* authentication=true
* )
*/
public function authenticatedAction()
{
}
}

View File

@ -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 }

View File

@ -385,6 +385,7 @@ With multiple lines.',
'_format' => array('dataType' => '', 'description' => '', 'requirement' => ''),
),
'https' => false,
'authentication' => false,
);
$this->assertEquals($expected, $result);