From e11ee357b5560b0e1ff9d5248b819fed485884ca Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 23 May 2012 00:02:38 +0200 Subject: [PATCH 1/6] Backported the bundle to support Symfony 2.0.x --- Extractor/ApiDocExtractor.php | 2 +- Form/Extension/DescriptionFieldTypeExtension.php | 2 +- Parser/FormTypeParser.php | 6 +++++- Tests/Fixtures/Form/TestType.php | 4 ++-- Tests/Fixtures/app/config/default.yml | 6 +++--- Tests/WebTestCase.php | 2 +- Tests/bootstrap.php | 4 ++++ composer.json | 15 ++++++++------- 8 files changed, 25 insertions(+), 16 deletions(-) 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/Form/Extension/DescriptionFieldTypeExtension.php b/Form/Extension/DescriptionFieldTypeExtension.php index c309bb1..f827ba0 100644 --- a/Form/Extension/DescriptionFieldTypeExtension.php +++ b/Form/Extension/DescriptionFieldTypeExtension.php @@ -37,7 +37,7 @@ class DescriptionFieldTypeExtension extends AbstractTypeExtension /** * {@inheritdoc} */ - public function getDefaultOptions() + public function getDefaultOptions(array $options) { return array( 'description' => '', diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php index e044d5b..35b0057 100644 --- a/Parser/FormTypeParser.php +++ b/Parser/FormTypeParser.php @@ -54,8 +54,12 @@ class FormTypeParser { $builder = $this->formFactory->createBuilder($type); + $refl = new \ReflectionProperty('Symfony\Component\Form\FormBuilder', 'children'); + $refl->setAccessible(true); + $children = $refl->getValue($builder); + $parameters = array(); - foreach ($builder->all() as $name => $child) { + foreach ($children as $name => $child) { if ($child instanceof FormBuilder) { $childBuilder = $child; } else { diff --git a/Tests/Fixtures/Form/TestType.php b/Tests/Fixtures/Form/TestType.php index 004e4e9..4689bbf 100644 --- a/Tests/Fixtures/Form/TestType.php +++ b/Tests/Fixtures/Form/TestType.php @@ -29,7 +29,7 @@ class TestType extends AbstractType /** * {@inheritdoc} */ - public function getDefaultOptions() + public function getDefaultOptions(array $options) { return array( 'data_class' => 'Nelmio\ApiDocBundle\Tests\Fixtures\Model\Test', @@ -38,6 +38,6 @@ class TestType extends AbstractType public function getName() { - return ''; + return 'foobar'; } } diff --git a/Tests/Fixtures/app/config/default.yml b/Tests/Fixtures/app/config/default.yml index 6b4401c..cb7ef7a 100644 --- a/Tests/Fixtures/app/config/default.yml +++ b/Tests/Fixtures/app/config/default.yml @@ -7,11 +7,11 @@ framework: validation: { enabled: true, enable_annotations: true } form: ~ test: ~ - default_locale: en session: + default_locale: en auto_start: true - storage_id: session.storage.mock_file - profiler: { only_exceptions: false } + storage_id: session.storage.filesystem + profiler: false templating: { engines: ['twig'] } # Twig Configuration diff --git a/Tests/WebTestCase.php b/Tests/WebTestCase.php index dba3f87..95a2cbf 100644 --- a/Tests/WebTestCase.php +++ b/Tests/WebTestCase.php @@ -12,7 +12,7 @@ namespace Nelmio\ApiDocBundle\Tests; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase; -use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\HttpKernel\Util\Filesystem; use Symfony\Component\HttpKernel\Kernel; abstract class WebTestCase extends BaseWebTestCase diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 0204cd7..13adf81 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -12,3 +12,7 @@ if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader 'curl -s http://getcomposer.org/installer | php'.PHP_EOL. 'php composer.phar install'.PHP_EOL); } + +if (class_exists('Doctrine\Common\Annotations\AnnotationRegistry')) { + \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass')); +} diff --git a/composer.json b/composer.json index 5eec681..0d23397 100644 --- a/composer.json +++ b/composer.json @@ -15,15 +15,16 @@ } ], "require": { - "symfony/framework-bundle": "2.1.*", - "symfony/twig-bundle": "2.1.*", - "symfony/form": "2.1.*" + "symfony/symfony": "2.0.*", + "symfony/framework-bundle": "2.0.*", + "symfony/twig-bundle": "2.0.*", + "symfony/form": "2.0.*" }, "require-dev": { - "symfony/css-selector": "2.1.*", - "symfony/browser-kit": "2.1.*", - "symfony/validator": "2.1.*", - "symfony/yaml": "2.1.*" + "symfony/css-selector": "2.0.*", + "symfony/browser-kit": "2.0.*", + "symfony/validator": "2.0.*", + "symfony/yaml": "2.0.*" }, "autoload": { "psr-0": { "Nelmio\\ApiDocBundle": "" } From d4f67eb23effbf7f75e9e1a016e47a3bde6bbbbf Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 23 May 2012 09:33:10 +0200 Subject: [PATCH 2/6] Fixed composer.json --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 0d23397..da7de2e 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,6 @@ } ], "require": { - "symfony/symfony": "2.0.*", "symfony/framework-bundle": "2.0.*", "symfony/twig-bundle": "2.0.*", "symfony/form": "2.0.*" From 0c3a15d3b0778f61f7217c562810be278a65ab86 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 23 May 2012 09:47:27 +0200 Subject: [PATCH 3/6] Fixed travis-ci image --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f84c5d7..c92d0ad 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ NelmioApiDocBundle ================== -[![Build Status](https://secure.travis-ci.org/nelmio/NelmioApiDocBundle.png?branch=master)](http://travis-ci.org/nelmio/NelmioApiDocBundle) +[![Build Status](https://secure.travis-ci.org/nelmio/NelmioApiDocBundle.png?branch=1.0.x)](http://travis-ci.org/nelmio/NelmioApiDocBundle) The **NelmioApiDocBundle** bundle allows you to generate a decent documentation for your APIs. From caf9961a6d24884ddfd46111862d009df381e944 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 23 May 2012 09:48:33 +0200 Subject: [PATCH 4/6] Removed PHP 5.3.2 in travis-ci config --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c3ef52f..ea5262a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.3.2 - 5.3 - 5.4 From 382f8fa2970f96764edbcddbe75d8aeecaeb6973 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 23 May 2012 10:02:25 +0200 Subject: [PATCH 5/6] Fixed composer.json --- composer.json | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/composer.json b/composer.json index da7de2e..d691e7a 100644 --- a/composer.json +++ b/composer.json @@ -15,15 +15,7 @@ } ], "require": { - "symfony/framework-bundle": "2.0.*", - "symfony/twig-bundle": "2.0.*", - "symfony/form": "2.0.*" - }, - "require-dev": { - "symfony/css-selector": "2.0.*", - "symfony/browser-kit": "2.0.*", - "symfony/validator": "2.0.*", - "symfony/yaml": "2.0.*" + "symfony/symfony": "2.0.*" }, "autoload": { "psr-0": { "Nelmio\\ApiDocBundle": "" } From e6438d657fe494ae3a7989ec2dfaaac975933b87 Mon Sep 17 00:00:00 2001 From: kphoen Date: Thu, 24 May 2012 01:22:45 +0200 Subject: [PATCH 6/6] Add: sandbox, to easily try API methods --- DependencyInjection/Configuration.php | 3 +- DependencyInjection/NelmioApiDocExtension.php | 1 + Formatter/HtmlFormatter.php | 20 +- Resources/config/formatters.xml | 3 + Resources/public/css/screen.css | 57 +++++ Resources/views/layout.html.twig | 125 ++++++++++ Resources/views/method.html.twig | 223 +++++++++++------- 7 files changed, 349 insertions(+), 83 deletions(-) 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/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 8fb3bf9..430cc84 100644 --- a/Resources/public/css/screen.css +++ b/Resources/public/css/screen.css @@ -1139,3 +1139,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 }} + +