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
->root('nelmio_api_doc')
->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()
->arrayNode('routes')
->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')) {
$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" />
</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">
<argument type="collection" /> <!-- Path patterns -->
</service>

View File

@ -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();

View File

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