mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Merge pull request #85 from vslinko/json-declaration-method
Make request format configurable
This commit is contained in:
commit
bd3e63c479
@ -28,6 +28,19 @@ class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->scalarNode('enabled')->defaultTrue()->end()
|
||||
->scalarNode('endpoint')->defaultValue('/app_dev.php')->end()
|
||||
->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()
|
||||
->scalarNode('name')->isRequired()->end()
|
||||
|
@ -31,6 +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.default_format', $config['sandbox']['request_format']['default_format']);
|
||||
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('formatters.xml');
|
||||
|
@ -40,6 +40,16 @@ class HtmlFormatter extends AbstractFormatter
|
||||
*/
|
||||
private $engine;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $requestFormatMethod;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultRequestFormat;
|
||||
|
||||
/**
|
||||
* @param array $authentication
|
||||
*/
|
||||
@ -80,6 +90,19 @@ class HtmlFormatter extends AbstractFormatter
|
||||
$this->engine = $engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
*/
|
||||
public function setRequestFormatMethod($method)
|
||||
{
|
||||
$this->requestFormatMethod = $method;
|
||||
}
|
||||
|
||||
public function setDefaultRequestFormat($format)
|
||||
{
|
||||
$this->defaultRequestFormat = $format;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -137,6 +160,8 @@ class HtmlFormatter extends AbstractFormatter
|
||||
'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'),
|
||||
|
@ -37,6 +37,12 @@
|
||||
<call method="setEndpoint">
|
||||
<argument>%nelmio_api_doc.sandbox.endpoint%</argument>
|
||||
</call>
|
||||
<call method="setRequestFormatMethod">
|
||||
<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>
|
||||
</call>
|
||||
|
@ -148,7 +148,7 @@ table tbody tr:last-child td {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#api_key_wrapper {
|
||||
#sandbox_configuration {
|
||||
float: right;
|
||||
padding: 10px 0 10px 0;
|
||||
}
|
||||
|
@ -15,11 +15,16 @@
|
||||
<body>
|
||||
<div id="header">
|
||||
<a href=""><h1>{{ apiName }}</h1></a>
|
||||
<div id="sandbox_configuration">
|
||||
request format:
|
||||
<select id="request_format">
|
||||
<option value="json"{{ defaultRequestFormat == 'json' ? ' selected' : '' }}>JSON</option>
|
||||
<option value="xml"{{ defaultRequestFormat == 'xml' ? ' selected' : '' }}>XML</option>
|
||||
</select>
|
||||
{% if authentication %}
|
||||
<div id="api_key_wrapper">
|
||||
api key: <input type="text" id="api_key"/>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<br style="clear: both;" />
|
||||
</div>
|
||||
<div class="container" id="resources_container">
|
||||
@ -51,7 +56,7 @@
|
||||
$btn = $container.parents('.pane').find('.to-raw');
|
||||
|
||||
$container.addClass('prettyprinted');
|
||||
$container.html(rawData);
|
||||
$container.html($('<div/>').text(rawData).html());
|
||||
|
||||
$btn.removeClass('to-raw');
|
||||
$btn.addClass('to-prettify');
|
||||
@ -105,11 +110,7 @@
|
||||
|
||||
container.data('raw-response', data);
|
||||
|
||||
if ('<' === data[0]) {
|
||||
renderRawBody(container);
|
||||
} else {
|
||||
renderPrettifiedBody(container);
|
||||
}
|
||||
|
||||
container.parents('.pane').find('.to-prettify').text('Raw');
|
||||
container.parents('.pane').find('.to-raw').text('Raw');
|
||||
@ -134,13 +135,19 @@
|
||||
var url = $(this).attr('action'),
|
||||
method = $(this).attr('method'),
|
||||
self = this,
|
||||
params = {
|
||||
_format: 'json' // default format if not overriden in the form
|
||||
},
|
||||
params = {},
|
||||
headers = {},
|
||||
content = $(this).find('textarea.content').val();
|
||||
content = $(this).find('textarea.content').val(),
|
||||
result_container = $('.result', $(this).parent());
|
||||
|
||||
var requestFormat = $('#request_format').val();
|
||||
var requestFormatMethod = '{{ requestFormatMethod }}';
|
||||
if (requestFormatMethod == 'format_param') {
|
||||
params['_format'] = requestFormat;
|
||||
} else if (requestFormatMethod == 'accept_header') {
|
||||
headers['Accept'] = 'application/' + requestFormat;
|
||||
}
|
||||
|
||||
// retrieve all the parameters to send
|
||||
$('.parameters .tuple', $(this)).each(function() {
|
||||
var key, value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user