mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
Make JSON declaration method configurable
This commit is contained in:
parent
6aac4a001e
commit
8e03ef99fa
@ -28,6 +28,13 @@ class Configuration implements ConfigurationInterface
|
|||||||
->children()
|
->children()
|
||||||
->scalarNode('enabled')->defaultTrue()->end()
|
->scalarNode('enabled')->defaultTrue()->end()
|
||||||
->scalarNode('endpoint')->defaultValue('/app_dev.php')->end()
|
->scalarNode('endpoint')->defaultValue('/app_dev.php')->end()
|
||||||
|
->scalarNode('json_declaration_method')
|
||||||
|
->defaultValue('format_param')
|
||||||
|
->validate()
|
||||||
|
->ifNotInArray(array('format_param', 'accept_header'))
|
||||||
|
->thenInvalid("Unknown json declaration method '%s'.")
|
||||||
|
->end()
|
||||||
|
->end()
|
||||||
->arrayNode('authentication')
|
->arrayNode('authentication')
|
||||||
->children()
|
->children()
|
||||||
->scalarNode('name')->isRequired()->end()
|
->scalarNode('name')->isRequired()->end()
|
||||||
|
@ -31,6 +31,7 @@ class NelmioApiDocExtension extends Extension
|
|||||||
$container->setParameter('nelmio_api_doc.api_name', $config['name']);
|
$container->setParameter('nelmio_api_doc.api_name', $config['name']);
|
||||||
$container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']);
|
$container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']);
|
||||||
$container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']);
|
$container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']);
|
||||||
|
$container->setParameter('nelmio_api_doc.sandbox.json_declaration_method', $config['sandbox']['json_declaration_method']);
|
||||||
|
|
||||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||||
$loader->load('formatters.xml');
|
$loader->load('formatters.xml');
|
||||||
|
@ -40,6 +40,11 @@ class HtmlFormatter extends AbstractFormatter
|
|||||||
*/
|
*/
|
||||||
private $engine;
|
private $engine;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $jsonDeclarationMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $authentication
|
* @param array $authentication
|
||||||
*/
|
*/
|
||||||
@ -80,6 +85,14 @@ class HtmlFormatter extends AbstractFormatter
|
|||||||
$this->engine = $engine;
|
$this->engine = $engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $method
|
||||||
|
*/
|
||||||
|
public function setJsonDeclarationMethod($method)
|
||||||
|
{
|
||||||
|
$this->jsonDeclarationMethod = $method;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -133,13 +146,14 @@ class HtmlFormatter extends AbstractFormatter
|
|||||||
private function getGlobalVars()
|
private function getGlobalVars()
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'apiName' => $this->apiName,
|
'apiName' => $this->apiName,
|
||||||
'authentication' => $this->authentication,
|
'authentication' => $this->authentication,
|
||||||
'endpoint' => $this->endpoint,
|
'endpoint' => $this->endpoint,
|
||||||
'enableSandbox' => $this->enableSandbox,
|
'enableSandbox' => $this->enableSandbox,
|
||||||
'date' => date(DATE_RFC822),
|
'jsonDeclarationMethod' => $this->jsonDeclarationMethod,
|
||||||
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
|
'date' => date(DATE_RFC822),
|
||||||
'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
|
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
|
||||||
|
'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,9 @@
|
|||||||
<call method="setEndpoint">
|
<call method="setEndpoint">
|
||||||
<argument>%nelmio_api_doc.sandbox.endpoint%</argument>
|
<argument>%nelmio_api_doc.sandbox.endpoint%</argument>
|
||||||
</call>
|
</call>
|
||||||
|
<call method="setJsonDeclarationMethod">
|
||||||
|
<argument>%nelmio_api_doc.sandbox.json_declaration_method%</argument>
|
||||||
|
</call>
|
||||||
<call method="setAuthentication">
|
<call method="setAuthentication">
|
||||||
<argument>%nelmio_api_doc.sandbox.authentication%</argument>
|
<argument>%nelmio_api_doc.sandbox.authentication%</argument>
|
||||||
</call>
|
</call>
|
||||||
|
@ -134,13 +134,18 @@
|
|||||||
var url = $(this).attr('action'),
|
var url = $(this).attr('action'),
|
||||||
method = $(this).attr('method'),
|
method = $(this).attr('method'),
|
||||||
self = this,
|
self = this,
|
||||||
params = {
|
params = {},
|
||||||
_format: 'json' // default format if not overriden in the form
|
|
||||||
},
|
|
||||||
headers = {},
|
headers = {},
|
||||||
content = $(this).find('textarea.content').val();
|
content = $(this).find('textarea.content').val();
|
||||||
result_container = $('.result', $(this).parent());
|
result_container = $('.result', $(this).parent());
|
||||||
|
|
||||||
|
var jsonDeclarationMethod = '{{ jsonDeclarationMethod }}';
|
||||||
|
if (jsonDeclarationMethod == 'format_param') {
|
||||||
|
params['_format'] = 'json';
|
||||||
|
} else if (jsonDeclarationMethod == 'accept_header') {
|
||||||
|
headers['Accept'] = 'application/json';
|
||||||
|
}
|
||||||
|
|
||||||
// retrieve all the parameters to send
|
// retrieve all the parameters to send
|
||||||
$('.parameters .tuple', $(this)).each(function() {
|
$('.parameters .tuple', $(this)).each(function() {
|
||||||
var key, value;
|
var key, value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user