Add a config option to configure the base of the documentation

This commit is contained in:
Guilhem N 2017-01-25 18:53:19 +01:00
parent fcf0b104c0
commit 0f2cb3fde2
No known key found for this signature in database
GPG Key ID: 9E5D2DB67BF054DD
5 changed files with 25 additions and 1 deletions

View File

@ -22,6 +22,11 @@ final class Configuration implements ConfigurationInterface
$treeBuilder $treeBuilder
->root('nelmio_api_doc') ->root('nelmio_api_doc')
->children() ->children()
->arrayNode('documentation')
->info('The documentation used as base')
->example(['info' => ['title' => 'My App']])
->prototype('variable')->end()
->end()
->scalarNode('source_folder')->defaultValue('%kernel.root_dir%/../src')->end() ->scalarNode('source_folder')->defaultValue('%kernel.root_dir%/../src')->end()
->arrayNode('routes') ->arrayNode('routes')
->info('Filter the routes that are documented') ->info('Filter the routes that are documented')

View File

@ -54,5 +54,8 @@ final class NelmioApiDocExtension extends Extension
if (isset($bundles['ApiPlatformBundle']) && class_exists('ApiPlatform\Core\Documentation\Documentation')) { if (isset($bundles['ApiPlatformBundle']) && class_exists('ApiPlatform\Core\Documentation\Documentation')) {
$loader->load('api_platform.xml'); $loader->load('api_platform.xml');
} }
// Import the base configuration
$container->getDefinition('nelmio_api_doc.describers.config')->replaceArgument(0, $config['documentation']);
} }
} }

View File

@ -14,7 +14,13 @@
<argument type="service" id="controller_name_converter" /> <argument type="service" id="controller_name_converter" />
</service> </service>
<!-- Extractors --> <!-- Describers -->
<service id="nelmio_api_doc.describers.config" class="Nelmio\ApiDocBundle\Describer\ExternalDocDescriber" public="false">
<argument type="collection" />
<tag name="nelmio_api_doc.describer" priority="1000" />
</service>
<service id="nelmio_api_doc.describers.route.filtered_route_collection_builder" class="Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder" public="false"> <service id="nelmio_api_doc.describers.route.filtered_route_collection_builder" class="Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder" public="false">
<argument type="collection" /> <!-- Path patterns --> <argument type="collection" /> <!-- Path patterns -->
</service> </service>

View File

@ -17,6 +17,11 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class FunctionalTest extends WebTestCase class FunctionalTest extends WebTestCase
{ {
public function testConfiguredDocumentation()
{
$this->assertEquals('My Test App', $this->getSwaggerDefinition()->getInfo()->getTitle());
}
public function testUndocumentedAction() public function testUndocumentedAction()
{ {
$paths = $this->getSwaggerDefinition()->getPaths(); $paths = $this->getSwaggerDefinition()->getPaths();

View File

@ -62,6 +62,11 @@ class TestKernel extends Kernel
// Filter routes // Filter routes
$c->loadFromExtension('nelmio_api_doc', [ $c->loadFromExtension('nelmio_api_doc', [
'documentation' => [
'info' => [
'title' => 'My Test App',
],
],
'source_folder' => '%kernel.root_dir%', 'source_folder' => '%kernel.root_dir%',
'routes' => [ 'routes' => [
'path_patterns' => ['^/api(?!/admin)'], 'path_patterns' => ['^/api(?!/admin)'],