diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index e88d4e8..8c18d39 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,7 +23,8 @@ class Configuration implements ConfigurationInterface ->root('nelmio_api_doc') ->children() ->scalarNode('name')->defaultValue('API documentation')->end() - ; + ->scalarNode('sandbox_target')->defaultValue('/app_dev.php')->end() + ->end(); return $treeBuilder; } diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index 63c4107..0aad910 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -29,6 +29,7 @@ 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']); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('formatters.xml'); diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index abd761b..42ef1ef 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -200,7 +200,7 @@ class ApiDocExtractor } } - $route->addOptions(array('_paramDocs' => $paramDocs)); + $route->setOptions(array_merge($route->getOptions(), array('_paramDocs' => $paramDocs))); return array('annotation' => $annotation, 'route' => $route); } diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index 170004c..90480ee 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -20,6 +20,11 @@ class HtmlFormatter extends AbstractFormatter */ private $apiName; + /** + * @var string + */ + private $sandboxTarget; + /** * @var \Symfony\Component\Templating\EngineInterface */ @@ -33,6 +38,14 @@ class HtmlFormatter extends AbstractFormatter $this->apiName = $apiName; } + /** + * @param string $sandboxTarget + */ + public function setSandboxTarget($sandboxTarget) + { + $this->sandboxTarget = $sandboxTarget; + } + /** * @param EngineInterface $engine */ @@ -69,9 +82,10 @@ class HtmlFormatter extends AbstractFormatter private function getGlobalVars() { return array( - 'apiName' => $this->apiName, - 'date' => date(DATE_RFC822), - 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), + 'apiName' => $this->apiName, + 'sandboxTarget' => $this->sandboxTarget, + '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 4e00a7a..1bf12c9 100644 --- a/Resources/config/formatters.xml +++ b/Resources/config/formatters.xml @@ -30,6 +30,9 @@ %nelmio_api_doc.api_name% + + %nelmio_api_doc.api_sandbox_target% + diff --git a/Resources/public/css/screen.css b/Resources/public/css/screen.css index acb7767..733f351 100644 --- a/Resources/public/css/screen.css +++ b/Resources/public/css/screen.css @@ -1302,3 +1302,60 @@ body ul#resources li.resource ul.endpoints li.endpoint ul.operations li.operatio #header a { text-decoration: none; } + + +/** sandbox */ +.pane:not(.selected) { + display: none; +} + +.result pre { + border: none; + padding: 10px; + font-size: 0.9em; + overflow: auto; +} + +.tabs li { + display: inline; + float: left; + margin: 10px; + cursor: pointer; +} + +.tabs li.selected { + font-weight: bold; +} + +.panes { + clear: both; + border-top: 1px solid #C3D9EC; +} + +.pane.sandbox { + border: 1px solid #C3D9EC; + border-top: none; + padding: 10px; +} + +.pane.sandbox legend { + margin-bottom: 5px; +} + +.remove { + cursor: pointer; +} + +.pane.sandbox .result { + display: none; +} + +.parameters { + float: left; + width: 50%; +} + +.buttons { + clear: both; + padding-top: 10px; +} diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 3ef872c..ff715e3 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -6,10 +6,12 @@ {{ apiName }} + + diff --git a/Tests/Fixtures/app/config/default.yml b/Tests/Fixtures/app/config/default.yml index d159f8d..1ba6505 100644 --- a/Tests/Fixtures/app/config/default.yml +++ b/Tests/Fixtures/app/config/default.yml @@ -11,7 +11,7 @@ framework: session: auto_start: true storage_id: session.storage.mock_file - profiler: { only_exceptions: false } + profiler: { only_exceptions: false } templating: { engines: ['twig'] } # Twig Configuration