diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ec79579..f049223 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -46,6 +46,10 @@ class Configuration implements ConfigurationInterface ->scalarNode('enabled')->defaultTrue()->end() ->scalarNode('endpoint')->defaultNull()->end() ->scalarNode('accept_type')->defaultValue('')->end() + ->enumNode('body_format') + ->values(array('form', 'json')) + ->defaultValue('form') + ->end() ->arrayNode('request_format') ->addDefaultsIfNotSet() ->children() diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index ce10263..d26a39d 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -34,6 +34,7 @@ class NelmioApiDocExtension extends Extension $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.body_format', $config['sandbox']['body_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')); diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index d4520fc..750f82c 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -50,6 +50,11 @@ class HtmlFormatter extends AbstractFormatter */ private $acceptType; + /** + * @var string + */ + private $bodyFormat; + /** * @var array */ @@ -108,6 +113,14 @@ class HtmlFormatter extends AbstractFormatter $this->acceptType = $acceptType; } + /** + * @param string $bodyFormat + */ + public function setBodyFormat($bodyFormat) + { + $this->bodyFormat = $bodyFormat; + } + /** * @param string $method */ @@ -179,6 +192,7 @@ class HtmlFormatter extends AbstractFormatter 'enableSandbox' => $this->enableSandbox, 'requestFormatMethod' => $this->requestFormatMethod, 'acceptType' => $this->acceptType, + 'bodyFormat' => $this->bodyFormat, 'defaultRequestFormat' => $this->defaultRequestFormat, 'date' => date(DATE_RFC822), 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), diff --git a/README.md b/README.md index 9ed3a02..ed38e28 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,10 @@ configure this sandbox using the following parameters: 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 + body_format: form # default form, determines whether to send x-www-form-urlencoded data or json-encoded data in sandbox requests + request_format: + method: format_param # default format_param, alternately accept_header, decides how to request the response format + default_format: json # default json, alternately xml, determines which content format to request back by default 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: diff --git a/Resources/config/formatters.xml b/Resources/config/formatters.xml index a91a862..2cff274 100644 --- a/Resources/config/formatters.xml +++ b/Resources/config/formatters.xml @@ -48,6 +48,9 @@ %nelmio_api_doc.sandbox.accept_type% + + %nelmio_api_doc.sandbox.body_format% + %nelmio_api_doc.sandbox.authentication% diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index d1da09e..c89d590 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -16,6 +16,11 @@