mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Make response format more configurable
This commit is contained in:
parent
f25c2f1eeb
commit
3540bcfcd8
@ -28,17 +28,20 @@ class Configuration implements ConfigurationInterface
|
||||
->children()
|
||||
->scalarNode('enabled')->defaultTrue()->end()
|
||||
->scalarNode('endpoint')->defaultValue('/app_dev.php')->end()
|
||||
->enumNode('json_declaration_method')
|
||||
->enumNode('request_format_method')
|
||||
->values(array('format_param', 'accept_header'))
|
||||
->defaultValue('format_param')
|
||||
->end()
|
||||
->arrayNode('authentication')
|
||||
->children()
|
||||
->scalarNode('name')->isRequired()->end()
|
||||
->enumNode('delivery')
|
||||
// header|query|request, but only query is implemented for now
|
||||
->values(array('query'))
|
||||
->scalarNode('delivery')
|
||||
->isRequired()
|
||||
->validate()
|
||||
// header|query|request, but only query is implemented for now
|
||||
->ifNotInArray(array('query'))
|
||||
->thenInvalid("Unknown authentication delivery type '%s'.")
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
@ -31,7 +31,7 @@ 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.json_declaration_method', $config['sandbox']['json_declaration_method']);
|
||||
$container->setParameter('nelmio_api_doc.sandbox.request_format_method', $config['sandbox']['request_format_method']);
|
||||
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('formatters.xml');
|
||||
|
@ -43,7 +43,7 @@ class HtmlFormatter extends AbstractFormatter
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $jsonDeclarationMethod;
|
||||
private $requestFormatMethod;
|
||||
|
||||
/**
|
||||
* @param array $authentication
|
||||
@ -88,9 +88,9 @@ class HtmlFormatter extends AbstractFormatter
|
||||
/**
|
||||
* @param string $method
|
||||
*/
|
||||
public function setJsonDeclarationMethod($method)
|
||||
public function setRequestFormatMethod($method)
|
||||
{
|
||||
$this->jsonDeclarationMethod = $method;
|
||||
$this->requestFormatMethod = $method;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -150,7 +150,7 @@ class HtmlFormatter extends AbstractFormatter
|
||||
'authentication' => $this->authentication,
|
||||
'endpoint' => $this->endpoint,
|
||||
'enableSandbox' => $this->enableSandbox,
|
||||
'jsonDeclarationMethod' => $this->jsonDeclarationMethod,
|
||||
'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'),
|
||||
|
@ -37,8 +37,8 @@
|
||||
<call method="setEndpoint">
|
||||
<argument>%nelmio_api_doc.sandbox.endpoint%</argument>
|
||||
</call>
|
||||
<call method="setJsonDeclarationMethod">
|
||||
<argument>%nelmio_api_doc.sandbox.json_declaration_method%</argument>
|
||||
<call method="setRequestFormatMethod">
|
||||
<argument>%nelmio_api_doc.sandbox.request_format_method%</argument>
|
||||
</call>
|
||||
<call method="setAuthentication">
|
||||
<argument>%nelmio_api_doc.sandbox.authentication%</argument>
|
||||
|
@ -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">JSON</option>
|
||||
<option value="xml">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');
|
||||
@ -136,14 +137,15 @@
|
||||
self = this,
|
||||
params = {},
|
||||
headers = {},
|
||||
content = $(this).find('textarea.content').val();
|
||||
content = $(this).find('textarea.content').val(),
|
||||
result_container = $('.result', $(this).parent());
|
||||
|
||||
var jsonDeclarationMethod = '{{ jsonDeclarationMethod }}';
|
||||
if (jsonDeclarationMethod == 'format_param') {
|
||||
params['_format'] = 'json';
|
||||
} else if (jsonDeclarationMethod == 'accept_header') {
|
||||
headers['Accept'] = 'application/json';
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user