mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Allow to disable the sandbox, refactor the configuration. Fix #37
This commit is contained in:
parent
208d25f825
commit
bee518f92e
@ -23,7 +23,13 @@ class Configuration implements ConfigurationInterface
|
||||
->root('nelmio_api_doc')
|
||||
->children()
|
||||
->scalarNode('name')->defaultValue('API documentation')->end()
|
||||
->scalarNode('sandbox_target')->defaultValue('/app_dev.php')->end()
|
||||
->arrayNode('sandbox')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->scalarNode('enabled')->defaultTrue()->end()
|
||||
->scalarNode('endpoint')->defaultValue('/app_dev.php')->end()
|
||||
->end()
|
||||
->end()
|
||||
->end();
|
||||
|
||||
return $treeBuilder;
|
||||
|
@ -29,7 +29,8 @@ class NelmioApiDocExtension extends Extension
|
||||
$config = $processor->processConfiguration($configuration, $configs);
|
||||
|
||||
$container->setParameter('nelmio_api_doc.api_name', $config['name']);
|
||||
$container->setParameter('nelmio_api_doc.api_sandbox_target', $config['sandbox_target']);
|
||||
$container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']);
|
||||
$container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']);
|
||||
|
||||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
|
||||
$loader->load('formatters.xml');
|
||||
|
@ -23,7 +23,12 @@ class HtmlFormatter extends AbstractFormatter
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sandboxTarget;
|
||||
private $endpoint;
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
private $enableSandbox;
|
||||
|
||||
/**
|
||||
* @var \Symfony\Component\Templating\EngineInterface
|
||||
@ -39,11 +44,19 @@ class HtmlFormatter extends AbstractFormatter
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sandboxTarget
|
||||
* @param string $endpoint
|
||||
*/
|
||||
public function setSandboxTarget($sandboxTarget)
|
||||
public function setEndpoint($endpoint)
|
||||
{
|
||||
$this->sandboxTarget = $sandboxTarget;
|
||||
$this->endpoint = $endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param boolean $enableSandbox
|
||||
*/
|
||||
public function setEnableSandbox($enableSandbox)
|
||||
{
|
||||
$this->enableSandbox = $enableSandbox;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,7 +96,8 @@ class HtmlFormatter extends AbstractFormatter
|
||||
{
|
||||
return array(
|
||||
'apiName' => $this->apiName,
|
||||
'sandboxTarget' => $this->sandboxTarget,
|
||||
'endpoint' => $this->endpoint,
|
||||
'enableSandbox' => $this->enableSandbox,
|
||||
'date' => date(DATE_RFC822),
|
||||
'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'),
|
||||
'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'),
|
||||
|
@ -174,6 +174,15 @@ You can specify your own API name:
|
||||
nelmio_api_doc:
|
||||
name: My API
|
||||
|
||||
This bundle provides a sandbox mode in order to test API methods. You can
|
||||
configure this sandbox using the following parameters:
|
||||
|
||||
# app/config/config.yml
|
||||
nelmio_api_doc:
|
||||
sandbox:
|
||||
enabled: true # default: true, you can set this parameter to `false` to disable the sandbox
|
||||
endpoint: http://sandbox.example.com/ # default: /app_dev.php, use this parameter to define which URL to call through the sandbox
|
||||
|
||||
|
||||
## Credits ##
|
||||
|
||||
|
@ -30,8 +30,11 @@
|
||||
<call method="setApiName">
|
||||
<argument>%nelmio_api_doc.api_name%</argument>
|
||||
</call>
|
||||
<call method="setSandboxTarget">
|
||||
<argument>%nelmio_api_doc.api_sandbox_target%</argument>
|
||||
<call method="setEnableSandbox">
|
||||
<argument>%nelmio_api_doc.sandbox.enabled%</argument>
|
||||
</call>
|
||||
<call method="setEndpoint">
|
||||
<argument>%nelmio_api_doc.sandbox.endpoint%</argument>
|
||||
</call>
|
||||
</service>
|
||||
</services>
|
||||
|
@ -29,6 +29,7 @@
|
||||
$(this).next().slideToggle('slow');
|
||||
});
|
||||
|
||||
{% if enableSandbox %}
|
||||
var toggleButtonText = function ($btn) {
|
||||
if ($btn.text() === 'Default') {
|
||||
$btn.text('Raw');
|
||||
@ -171,7 +172,7 @@
|
||||
|
||||
// and trigger the API call
|
||||
$.ajax({
|
||||
url: '{{ sandboxTarget }}' + url,
|
||||
url: '{{ endpoint }}' + url,
|
||||
type: method,
|
||||
data: content.length ? content : params,
|
||||
headers: headers,
|
||||
@ -256,6 +257,7 @@
|
||||
$element.find('input.value').val(content_type);
|
||||
|
||||
});
|
||||
{% endif %}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -18,7 +18,9 @@
|
||||
<div class="content" style="display: {% if displayContent is defined and displayContent == true %}display{% else %}none{% endif %};">
|
||||
<ul class="tabs">
|
||||
<li class="selected" data-pane="content">Documentation</li>
|
||||
{% if enableSandbox %}
|
||||
<li data-pane="sandbox">Sandbox</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<div class="panes">
|
||||
@ -106,6 +108,7 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if enableSandbox %}
|
||||
<div class="pane sandbox">
|
||||
<form method="{{ data.method|upper }}" action="{{ data.uri }}">
|
||||
<fieldset class="parameters">
|
||||
@ -181,6 +184,7 @@
|
||||
<pre class="response prettyprint"></pre>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
Loading…
x
Reference in New Issue
Block a user