diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 7a03f78..21a73c8 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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() diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index 321a2cc..db4867d 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -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'); diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index 0e570c7..2981ca1 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -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} */ @@ -133,13 +156,15 @@ class HtmlFormatter extends AbstractFormatter private function getGlobalVars() { return array( - 'apiName' => $this->apiName, - 'authentication' => $this->authentication, - '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'), + 'apiName' => $this->apiName, + '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'), ); } diff --git a/Resources/config/formatters.xml b/Resources/config/formatters.xml index bc1dcbf..6a8ae76 100644 --- a/Resources/config/formatters.xml +++ b/Resources/config/formatters.xml @@ -37,6 +37,12 @@ %nelmio_api_doc.sandbox.endpoint% + + %nelmio_api_doc.sandbox.request_format.method% + + + %nelmio_api_doc.sandbox.request_format.default_format% + %nelmio_api_doc.sandbox.authentication% diff --git a/Resources/public/css/screen.css b/Resources/public/css/screen.css index 4b73b61..d0960bc 100644 --- a/Resources/public/css/screen.css +++ b/Resources/public/css/screen.css @@ -148,9 +148,9 @@ table tbody tr:last-child td { text-decoration: none; } -#api_key_wrapper { - float: right; - padding: 10px 0 10px 0; +#sandbox_configuration { + float: right; + padding: 10px 0 10px 0; } #colophon { diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 306befb..f314231 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -15,11 +15,16 @@