diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 5356c53..6dfa21d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,6 +22,11 @@ final class Configuration implements ConfigurationInterface $treeBuilder ->root('nelmio_api_doc') ->children() + ->arrayNode('documentation') + ->info('The documentation used as base') + ->example(['info' => ['title' => 'My App']]) + ->prototype('variable')->end() + ->end() ->arrayNode('routes') ->info('Filter the routes that are documented') ->addDefaultsIfNotSet() diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index 829df1d..579ced0 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -58,5 +58,8 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionI if (isset($bundles['ApiPlatformBundle']) && class_exists('ApiPlatform\Core\Documentation\Documentation')) { $loader->load('api_platform.xml'); } + + // Import the base configuration + $container->getDefinition('nelmio_api_doc.describers.config')->replaceArgument(0, $config['documentation']); } } diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 14bc892..f11dad0 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -14,7 +14,13 @@ - + + + + + + + diff --git a/Tests/Functional/FunctionalTest.php b/Tests/Functional/FunctionalTest.php index 94cc167..69272e7 100644 --- a/Tests/Functional/FunctionalTest.php +++ b/Tests/Functional/FunctionalTest.php @@ -17,6 +17,11 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class FunctionalTest extends WebTestCase { + public function testConfiguredDocumentation() + { + $this->assertEquals('My Test App', $this->getSwaggerDefinition()->getInfo()->getTitle()); + } + public function testUndocumentedAction() { $paths = $this->getSwaggerDefinition()->getPaths(); diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index 9cf59d5..cb59275 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -62,7 +62,12 @@ class TestKernel extends Kernel // Filter routes $c->loadFromExtension('nelmio_api_doc', [ - 'routes' => [ + 'documentation' => [ + 'info' => [ + 'title' => 'My Test App', + ], + ], + 'routes' => [ 'path_patterns' => ['^/api(?!/admin)'], ], ]);