mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +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()
|
->children()
|
||||||
->scalarNode('enabled')->defaultTrue()->end()
|
->scalarNode('enabled')->defaultTrue()->end()
|
||||||
->scalarNode('endpoint')->defaultValue('/app_dev.php')->end()
|
->scalarNode('endpoint')->defaultValue('/app_dev.php')->end()
|
||||||
->enumNode('request_format_method')
|
->arrayNode('request_format')
|
||||||
->values(array('format_param', 'accept_header'))
|
->addDefaultsIfNotSet()
|
||||||
->defaultValue('format_param')
|
->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()
|
->end()
|
||||||
->arrayNode('authentication')
|
->arrayNode('authentication')
|
||||||
->children()
|
->children()
|
||||||
|
@ -31,7 +31,8 @@ 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.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 = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||||
$loader->load('formatters.xml');
|
$loader->load('formatters.xml');
|
||||||
|
@ -45,6 +45,11 @@ class HtmlFormatter extends AbstractFormatter
|
|||||||
*/
|
*/
|
||||||
private $requestFormatMethod;
|
private $requestFormatMethod;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $defaultRequestFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $authentication
|
* @param array $authentication
|
||||||
*/
|
*/
|
||||||
@ -93,6 +98,11 @@ class HtmlFormatter extends AbstractFormatter
|
|||||||
$this->requestFormatMethod = $method;
|
$this->requestFormatMethod = $method;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setDefaultRequestFormat($format)
|
||||||
|
{
|
||||||
|
$this->defaultRequestFormat = $format;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -146,14 +156,15 @@ 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,
|
||||||
'requestFormatMethod' => $this->requestFormatMethod,
|
'requestFormatMethod' => $this->requestFormatMethod,
|
||||||
'date' => date(DATE_RFC822),
|
'defaultRequestFormat' => $this->defaultRequestFormat,
|
||||||
'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'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,10 @@
|
|||||||
<argument>%nelmio_api_doc.sandbox.endpoint%</argument>
|
<argument>%nelmio_api_doc.sandbox.endpoint%</argument>
|
||||||
</call>
|
</call>
|
||||||
<call method="setRequestFormatMethod">
|
<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>
|
||||||
<call method="setAuthentication">
|
<call method="setAuthentication">
|
||||||
<argument>%nelmio_api_doc.sandbox.authentication%</argument>
|
<argument>%nelmio_api_doc.sandbox.authentication%</argument>
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
<div id="sandbox_configuration">
|
<div id="sandbox_configuration">
|
||||||
request format:
|
request format:
|
||||||
<select id="request_format">
|
<select id="request_format">
|
||||||
<option value="json">JSON</option>
|
<option value="json"{{ defaultRequestFormat == 'json' ? ' selected' : '' }}>JSON</option>
|
||||||
<option value="xml">XML</option>
|
<option value="xml"{{ defaultRequestFormat == 'xml' ? ' selected' : '' }}>XML</option>
|
||||||
</select>
|
</select>
|
||||||
{% if authentication %}
|
{% if authentication %}
|
||||||
api key: <input type="text" id="api_key"/>
|
api key: <input type="text" id="api_key"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user