Added definition when is provided.

This commit is contained in:
Bez Hermoso 2014-08-04 10:58:41 -07:00
parent e3103c073a
commit b7f5fb58d4
4 changed files with 66 additions and 6 deletions

View File

@ -45,5 +45,10 @@ class SwaggerConfigCompilerPass implements CompilerPassInterface
$formatter->addMethodCall('setSwaggerVersion', array($container->getParameter('nelmio_api_doc.swagger.swagger_version')));
$formatter->addMethodCall('setInfo', array($container->getParameter('nelmio_api_doc.swagger.info')));
$authentication = $container->getParameter('nelmio_api_doc.sandbox.authentication');
if ($authentication !== null) {
$formatter->addMethodCall('setAuthenticationConfig', array($authentication));
}
}
}

View File

@ -54,6 +54,16 @@ class SwaggerFormatter implements FormatterInterface
DataTypes::DATETIME => 'date-time',
);
/**
* @var array
*/
protected $authConfig = null;
public function setAuthenticationConfig(array $config)
{
$this->authConfig = $config;
}
/**
* Format a collection of documentation data.
*
@ -115,7 +125,25 @@ class SwaggerFormatter implements FormatterInterface
protected function getAuthorizations()
{
return array();
$auth = array();
if ($this->authConfig === null) {
return $auth;
}
$config = $this->authConfig;
if ($config['delivery'] === 'http') {
return $auth;
}
$auth['apiKey'] = array(
'type' => 'apiKey',
'passAs' => $config['delivery'],
'keyname' => $config['name'],
);
return $auth;
}
/**
@ -157,7 +185,7 @@ class SwaggerFormatter implements FormatterInterface
'models' => array(),
'produces' => array(),
'consumes' => array(),
'authorizations' => array(),
'authorizations' => $this->getAuthorizations(),
);
$main = null;

View File

@ -53,6 +53,10 @@ jms_serializer:
auto_detection: true
nelmio_api_doc:
sandbox:
authentication:
delivery: header
name: access_token
cache:
enabled: true
exclude_sections: ["private", "exclusive"]

View File

@ -61,7 +61,13 @@ class SwaggerFormatterTest extends WebTestCase
'licenseUrl' => 'http://opensource.org/licenses/MIT',
),
'authorizations' =>
array(),
array(
'apiKey' => array(
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
)
),
'apis' =>
array(
array(
@ -419,7 +425,13 @@ With multiple lines.',
'consumes' =>
array(),
'authorizations' =>
array(),
array(
'apiKey' => array(
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
)
),
),
),
array(
@ -539,7 +551,13 @@ With multiple lines.',
'consumes' =>
array(),
'authorizations' =>
array(),
array(
'apiKey' => array(
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
)
),
),
),
array(
@ -721,7 +739,12 @@ With multiple lines.',
array (
),
'authorizations' =>
array (
array(
'apiKey' => array(
'type' => 'apiKey',
'passAs' => 'header',
'keyname' => 'access_token',
)
),
),
),