mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Merge pull request #123 from fvilpoix/authentication_attribute
adding 'authentication' attribute
This commit is contained in:
commit
43b8f89845
@ -93,6 +93,11 @@ class ApiDoc
|
|||||||
*/
|
*/
|
||||||
private $https = false;
|
private $https = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
private $authentication = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -130,6 +135,10 @@ class ApiDoc
|
|||||||
$this->addStatusCode($statusCode, $description);
|
$this->addStatusCode($statusCode, $description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($data['authentication'])) {
|
||||||
|
$this->setAuthentication((bool) $data['authentication']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -276,6 +285,22 @@ class ApiDoc
|
|||||||
$this->https = $https;
|
$this->https = $https;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public function getAuthentication()
|
||||||
|
{
|
||||||
|
return $this->authentication;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param boolean $secured
|
||||||
|
*/
|
||||||
|
public function setAuthentication($authentication)
|
||||||
|
{
|
||||||
|
$this->authentication = $authentication;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -315,6 +340,7 @@ class ApiDoc
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data['https'] = $this->https;
|
$data['https'] = $this->https;
|
||||||
|
$data['authentication'] = $this->authentication;
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,8 @@ class ApiDocExtractor
|
|||||||
|
|
||||||
const FOS_REST_REQUEST_PARAM_CLASS = 'FOS\\RestBundle\\Controller\\Annotations\\RequestParam';
|
const FOS_REST_REQUEST_PARAM_CLASS = 'FOS\\RestBundle\\Controller\\Annotations\\RequestParam';
|
||||||
|
|
||||||
|
const JMS_SECURITY_EXTRA_SECURE_CLASS = 'JMS\\SecurityExtraBundle\\Annotation\\Secure';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ContainerInterface
|
* @var ContainerInterface
|
||||||
*/
|
*/
|
||||||
@ -360,6 +362,8 @@ class ApiDocExtractor
|
|||||||
'description' => $annot->description,
|
'description' => $annot->description,
|
||||||
'readonly' => false
|
'readonly' => false
|
||||||
));
|
));
|
||||||
|
} elseif (is_a($annot, self::JMS_SECURITY_EXTRA_SECURE_CLASS)) {
|
||||||
|
$annotation->setAuthentication(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,7 +538,7 @@ form .request-content {
|
|||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.padlock {
|
.icon {
|
||||||
height: 12px;
|
height: 12px;
|
||||||
margin-left: 3px;
|
margin-left: 3px;
|
||||||
}
|
}
|
BIN
Resources/public/image/keys.png
Normal file
BIN
Resources/public/image/keys.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
@ -6,7 +6,10 @@
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
{% if data.https %}
|
{% 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/keys.png') }}" class="icon" alt="Needs authentication" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<span class="path">
|
<span class="path">
|
||||||
|
@ -28,6 +28,7 @@ class ApiDocTest extends TestCase
|
|||||||
$this->assertFalse($annot->isResource());
|
$this->assertFalse($annot->isResource());
|
||||||
$this->assertFalse(isset($array['description']));
|
$this->assertFalse(isset($array['description']));
|
||||||
$this->assertNull($annot->getInput());
|
$this->assertNull($annot->getInput());
|
||||||
|
$this->assertFalse($array['authentication']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testConstructWithInvalidData()
|
public function testConstructWithInvalidData()
|
||||||
@ -197,4 +198,16 @@ class ApiDocTest extends TestCase
|
|||||||
$this->assertEquals($array['statusCodes'][$code], !is_array($message) ? array($message) : $message);
|
$this->assertEquals($array['statusCodes'][$code], !is_array($message) ? array($message) : $message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testConstructWithAuthentication()
|
||||||
|
{
|
||||||
|
$data = array(
|
||||||
|
'authentication' => true
|
||||||
|
);
|
||||||
|
|
||||||
|
$annot = new ApiDoc($data);
|
||||||
|
$array = $annot->toArray();
|
||||||
|
|
||||||
|
$this->assertTrue($array['authentication']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,4 +155,16 @@ class ApiDocExtractorTest extends WebTestCase
|
|||||||
$annotation->getDescription()
|
$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()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,4 +127,12 @@ class TestController
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ApiDoc(
|
||||||
|
* authentication=true
|
||||||
|
* )
|
||||||
|
*/
|
||||||
|
public function authenticatedAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,10 @@ test_route_12:
|
|||||||
requirements:
|
requirements:
|
||||||
_scheme: https
|
_scheme: https
|
||||||
|
|
||||||
|
test_route_13:
|
||||||
|
pattern: /authenticated
|
||||||
|
defaults: { _controller: NelmioApiDocTestBundle:Test:authenticated }
|
||||||
|
|
||||||
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 }
|
||||||
|
@ -387,6 +387,7 @@ With multiple lines.',
|
|||||||
'_format' => array('dataType' => '', 'description' => '', 'requirement' => ''),
|
'_format' => array('dataType' => '', 'description' => '', 'requirement' => ''),
|
||||||
),
|
),
|
||||||
'https' => false,
|
'https' => false,
|
||||||
|
'authentication' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user