mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-08 18:49:26 +03:00
Allow to configure default request format
This commit is contained in:
parent
3540bcfcd8
commit
52df5ebf47
@ -28,9 +28,18 @@ class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->scalarNode('enabled')->defaultTrue()->end()
|
||||
->scalarNode('endpoint')->defaultValue('/app_dev.php')->end()
|
||||
->enumNode('request_format_method')
|
||||
->values(array('format_param', 'accept_header'))
|
||||
->defaultValue('format_param')
|
||||
->arrayNode('request_format')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->enumNode('method')
|
||||
->values(array('format_param', 'accept_header'))
|
||||
->defaultValue('format_param')
|
||||
->end()
|
||||
->enumNode('default_format')
|
||||
->values(array('json', 'xml'))
|
||||
->defaultValue('json')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('authentication')
|
||||
->children()
|
||||
|
@ -31,7 +31,8 @@ class NelmioApiDocExtension extends Extension
|
||||
$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.endpoint', $config['sandbox']['endpoint']);
|
||||
$container->setParameter('nelmio_api_doc.sandbox.request_format_method', $config['sandbox']['request_format_method']);
|
||||
$container->setParameter('nelmio_api_doc.sandbox.request_format.method', $config['sandbox']['request_format']['method']);
|
||||
$container->setParameter('nelmio_api_doc.sandbox.request_format.default_format', $config['sandbox']['request_format']['default_format']);
|
||||
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('formatters.xml');
|
||||
|
@ -45,6 +45,11 @@ class HtmlFormatter extends AbstractFormatter
|
||||
*/
|
||||
private $requestFormatMethod;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultRequestFormat;
|
||||
|
||||
/**
|
||||
* @param array $authentication
|
||||
*/
|
||||
@ -93,6 +98,11 @@ class HtmlFormatter extends AbstractFormatter
|
||||
$this->requestFormatMethod = $method;
|
||||
}
|
||||
|
||||
public function setDefaultRequestFormat($format)
|
||||
{
|
||||
$this->defaultRequestFormat = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -146,14 +156,15 @@ class HtmlFormatter extends AbstractFormatter
|
||||
private function getGlobalVars()
|
||||
{
|
||||
return array(
|
||||
'apiName' => $this->apiName,
|
||||
'authentication' => $this->authentication,
|
||||
'endpoint' => $this->endpoint,
|
||||
'enableSandbox' => $this->enableSandbox,
|
||||
'requestFormatMethod' => $this->requestFormatMethod,
|
||||
'date' => date(DATE_RFC822),
|
||||
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
|
||||
'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
|
||||
'apiName' => $this->apiName,
|
||||
'authentication' => $this->authentication,
|
||||
'endpoint' => $this->endpoint,
|
||||
'enableSandbox' => $this->enableSandbox,
|
||||
'requestFormatMethod' => $this->requestFormatMethod,
|
||||
'defaultRequestFormat' => $this->defaultRequestFormat,
|
||||
'date' => date(DATE_RFC822),
|
||||
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
|
||||
'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,10 @@
|
||||
<argument>%nelmio_api_doc.sandbox.endpoint%</argument>
|
||||
</call>
|
||||
<call method="setRequestFormatMethod">
|
||||
<argument>%nelmio_api_doc.sandbox.request_format_method%</argument>
|
||||
<argument>%nelmio_api_doc.sandbox.request_format.method%</argument>
|
||||
</call>
|
||||
<call method="setDefaultRequestFormat">
|
||||
<argument>%nelmio_api_doc.sandbox.request_format.default_format%</argument>
|
||||
</call>
|
||||
<call method="setAuthentication">
|
||||
<argument>%nelmio_api_doc.sandbox.authentication%</argument>
|
||||
|
@ -18,8 +18,8 @@
|
||||
<div id="sandbox_configuration">
|
||||
request format:
|
||||
<select id="request_format">
|
||||
<option value="json">JSON</option>
|
||||
<option value="xml">XML</option>
|
||||
<option value="json"{{ defaultRequestFormat == 'json' ? ' selected' : '' }}>JSON</option>
|
||||
<option value="xml"{{ defaultRequestFormat == 'xml' ? ' selected' : '' }}>XML</option>
|
||||
</select>
|
||||
{% if authentication %}
|
||||
api key: <input type="text" id="api_key"/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user