From fef40329a485b0c4715027521b24b274a773a020 Mon Sep 17 00:00:00 2001 From: Greg Holland Date: Tue, 11 Dec 2012 17:59:03 -0800 Subject: [PATCH 1/3] Add a config option for a default sandbox accept header --- DependencyInjection/Configuration.php | 1 + DependencyInjection/NelmioApiDocExtension.php | 1 + Formatter/HtmlFormatter.php | 14 ++++++++++++++ Resources/config/formatters.xml | 3 +++ Resources/views/method.html.twig | 8 ++++++++ 5 files changed, 27 insertions(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index c08d0ad..f3ca77a 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -39,6 +39,7 @@ class Configuration implements ConfigurationInterface ->children() ->scalarNode('enabled')->defaultTrue()->end() ->scalarNode('endpoint')->defaultValue('/app_dev.php')->end() + ->scalarNode('accept_type')->defaultValue('')->end() ->arrayNode('request_format') ->addDefaultsIfNotSet() ->children() diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index 19790aa..2718679 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -32,6 +32,7 @@ class NelmioApiDocExtension extends Extension $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.accept_type', $config['sandbox']['accept_type']); $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')); diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index 8204891..0e17f7f 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -45,6 +45,11 @@ class HtmlFormatter extends AbstractFormatter */ private $requestFormatMethod; + /** + * @var string + */ + private $acceptType; + /** * @var array */ @@ -90,6 +95,14 @@ class HtmlFormatter extends AbstractFormatter $this->engine = $engine; } + /** + * @param string $acceptType + */ + public function setAcceptType($acceptType) + { + $this->acceptType = $acceptType; + } + /** * @param string $method */ @@ -144,6 +157,7 @@ class HtmlFormatter extends AbstractFormatter 'endpoint' => $this->endpoint, 'enableSandbox' => $this->enableSandbox, 'requestFormatMethod' => $this->requestFormatMethod, + 'acceptType' => $this->acceptType, 'defaultRequestFormat' => $this->defaultRequestFormat, 'date' => date(DATE_RFC822), 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), diff --git a/Resources/config/formatters.xml b/Resources/config/formatters.xml index 6a8ae76..98f29c5 100644 --- a/Resources/config/formatters.xml +++ b/Resources/config/formatters.xml @@ -43,6 +43,9 @@ %nelmio_api_doc.sandbox.request_format.default_format% + + %nelmio_api_doc.sandbox.accept_type% + %nelmio_api_doc.sandbox.authentication% diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig index e623f13..f5263b5 100644 --- a/Resources/views/method.html.twig +++ b/Resources/views/method.html.twig @@ -202,6 +202,14 @@
Headers + {% if acceptType %} +

+ + = + - +

+ {% endif %} +

= From 62b30fdb87fb269a39aa1732ed11a5efe05f3d7b Mon Sep 17 00:00:00 2001 From: Greg Holland Date: Tue, 8 Jan 2013 16:38:52 -0800 Subject: [PATCH 2/3] Fix spacing & indentation --- Formatter/HtmlFormatter.php | 2 +- Resources/views/method.html.twig | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index 0e17f7f..9d5449f 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -157,7 +157,7 @@ class HtmlFormatter extends AbstractFormatter 'endpoint' => $this->endpoint, 'enableSandbox' => $this->enableSandbox, 'requestFormatMethod' => $this->requestFormatMethod, - 'acceptType' => $this->acceptType, + 'acceptType' => $this->acceptType, 'defaultRequestFormat' => $this->defaultRequestFormat, 'date' => date(DATE_RFC822), 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), diff --git a/Resources/views/method.html.twig b/Resources/views/method.html.twig index f5263b5..264d13c 100644 --- a/Resources/views/method.html.twig +++ b/Resources/views/method.html.twig @@ -203,11 +203,11 @@ Headers {% if acceptType %} -

- - = - - -

+

+ + = + - +

{% endif %}

From 826fd358416ff899e9d43377ed517b64ce70853c Mon Sep 17 00:00:00 2001 From: Greg Holland Date: Tue, 8 Jan 2013 16:45:51 -0800 Subject: [PATCH 3/3] update doc to reflect new accept header config param --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d65dba..7d0403b 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,7 @@ configure this sandbox using the following parameters: delivery: query # only query delivery is supported for now 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 - + accept_type: application/json # default null, if set, the value is automatically populated as the Accept header The bundle provides a way to register multiple `input` parsers. The first parser that can handle the specified input is used, so you can configure their priorities via container tags. Here's an example parser service registration: