mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Added a configuration parameter to determine the default body format.
This commit is contained in:
parent
705e01625e
commit
a9f0613cee
@ -46,6 +46,10 @@ class Configuration implements ConfigurationInterface
|
|||||||
->scalarNode('enabled')->defaultTrue()->end()
|
->scalarNode('enabled')->defaultTrue()->end()
|
||||||
->scalarNode('endpoint')->defaultNull()->end()
|
->scalarNode('endpoint')->defaultNull()->end()
|
||||||
->scalarNode('accept_type')->defaultValue('')->end()
|
->scalarNode('accept_type')->defaultValue('')->end()
|
||||||
|
->enumNode('body_format')
|
||||||
|
->values(array('form', 'json'))
|
||||||
|
->defaultValue('form')
|
||||||
|
->end()
|
||||||
->arrayNode('request_format')
|
->arrayNode('request_format')
|
||||||
->addDefaultsIfNotSet()
|
->addDefaultsIfNotSet()
|
||||||
->children()
|
->children()
|
||||||
|
@ -34,6 +34,7 @@ class NelmioApiDocExtension extends Extension
|
|||||||
$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.accept_type', $config['sandbox']['accept_type']);
|
$container->setParameter('nelmio_api_doc.sandbox.accept_type', $config['sandbox']['accept_type']);
|
||||||
|
$container->setParameter('nelmio_api_doc.sandbox.body_format', $config['sandbox']['body_format']);
|
||||||
$container->setParameter('nelmio_api_doc.sandbox.request_format.default_format', $config['sandbox']['request_format']['default_format']);
|
$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'));
|
||||||
|
@ -50,6 +50,11 @@ class HtmlFormatter extends AbstractFormatter
|
|||||||
*/
|
*/
|
||||||
private $acceptType;
|
private $acceptType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $bodyFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
@ -108,6 +113,14 @@ class HtmlFormatter extends AbstractFormatter
|
|||||||
$this->acceptType = $acceptType;
|
$this->acceptType = $acceptType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $bodyFormat
|
||||||
|
*/
|
||||||
|
public function setBodyFormat($bodyFormat)
|
||||||
|
{
|
||||||
|
$this->bodyFormat = $bodyFormat;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $method
|
* @param string $method
|
||||||
*/
|
*/
|
||||||
@ -179,6 +192,7 @@ class HtmlFormatter extends AbstractFormatter
|
|||||||
'enableSandbox' => $this->enableSandbox,
|
'enableSandbox' => $this->enableSandbox,
|
||||||
'requestFormatMethod' => $this->requestFormatMethod,
|
'requestFormatMethod' => $this->requestFormatMethod,
|
||||||
'acceptType' => $this->acceptType,
|
'acceptType' => $this->acceptType,
|
||||||
|
'bodyFormat' => $this->bodyFormat,
|
||||||
'defaultRequestFormat' => $this->defaultRequestFormat,
|
'defaultRequestFormat' => $this->defaultRequestFormat,
|
||||||
'date' => date(DATE_RFC822),
|
'date' => date(DATE_RFC822),
|
||||||
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
|
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
|
||||||
|
@ -49,6 +49,9 @@
|
|||||||
<call method="setAcceptType">
|
<call method="setAcceptType">
|
||||||
<argument>%nelmio_api_doc.sandbox.accept_type%</argument>
|
<argument>%nelmio_api_doc.sandbox.accept_type%</argument>
|
||||||
</call>
|
</call>
|
||||||
|
<call method="setBodyFormat">
|
||||||
|
<argument>%nelmio_api_doc.sandbox.body_format%</argument>
|
||||||
|
</call>
|
||||||
<call method="setAuthentication">
|
<call method="setAuthentication">
|
||||||
<argument>%nelmio_api_doc.sandbox.authentication%</argument>
|
<argument>%nelmio_api_doc.sandbox.authentication%</argument>
|
||||||
</call>
|
</call>
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
<div id="header">
|
<div id="header">
|
||||||
<a href=""><h1>{{ apiName }}</h1></a>
|
<a href=""><h1>{{ apiName }}</h1></a>
|
||||||
<div id="sandbox_configuration">
|
<div id="sandbox_configuration">
|
||||||
content format:
|
body format:
|
||||||
<select id="content_format">
|
<select id="body_format">
|
||||||
<option value="x-www-form-urlencoded">Form Data</option>
|
<option value="x-www-form-urlencoded"{{ bodyFormat == 'form' ? ' selected' : '' }}>Form Data</option>
|
||||||
<option value="json">JSON</option>
|
<option value="json"{{ bodyFormat == 'json' ? ' selected' : '' }}>JSON</option>
|
||||||
</select>
|
</select>
|
||||||
request format:
|
request format:
|
||||||
<select id="request_format">
|
<select id="request_format">
|
||||||
@ -158,6 +158,7 @@
|
|||||||
method = method.split('|').sort().pop();
|
method = method.split('|').sort().pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set default requestFormat
|
||||||
var requestFormat = $('#request_format').val();
|
var requestFormat = $('#request_format').val();
|
||||||
var requestFormatMethod = '{{ requestFormatMethod }}';
|
var requestFormatMethod = '{{ requestFormatMethod }}';
|
||||||
if (requestFormatMethod == 'format_param') {
|
if (requestFormatMethod == 'format_param') {
|
||||||
@ -166,8 +167,12 @@
|
|||||||
headers['Accept'] = 'application/' + requestFormat;
|
headers['Accept'] = 'application/' + requestFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set content format
|
// set default bodyFormat
|
||||||
var contentFormat = $('#content_format').val();
|
var bodyFormat = $('#body_format').val();
|
||||||
|
|
||||||
|
if(!('Content-type' in headers)) {
|
||||||
|
headers['Content-type'] = 'application/'+bodyFormat;
|
||||||
|
}
|
||||||
|
|
||||||
// retrieve all the parameters to send
|
// retrieve all the parameters to send
|
||||||
$('.parameters .tuple', $(this)).each(function() {
|
$('.parameters .tuple', $(this)).each(function() {
|
||||||
@ -192,9 +197,6 @@
|
|||||||
headers[key] = value;
|
headers[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!('Content-type' in headers)) {
|
|
||||||
headers['Content-type'] = 'application/'+contentFormat;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// fix parameters in URL
|
// fix parameters in URL
|
||||||
@ -226,13 +228,11 @@
|
|||||||
|
|
||||||
// prepare final parameters
|
// prepare final parameters
|
||||||
var body = params;
|
var body = params;
|
||||||
if(contentFormat == 'json') {
|
if(bodyFormat == 'json') {
|
||||||
body = JSON.stringify(body);
|
body = JSON.stringify(body);
|
||||||
}
|
}
|
||||||
var data = content.length ? content : body;
|
var data = content.length ? content : body;
|
||||||
|
|
||||||
console.log(contentFormat); console.log(data);
|
|
||||||
|
|
||||||
// and trigger the API call
|
// and trigger the API call
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: endpoint + url,
|
url: endpoint + url,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user