diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 95405b9..c6596d1 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -42,10 +42,10 @@ final class Configuration implements ConfigurationInterface ->children() ->arrayNode('areas') ->info('Filter the routes that are documented') - ->defaultValue(['default' => ['path_patterns' => [], 'host_patterns' => []]]) + ->defaultValue(['default' => ['path_patterns' => [], 'host_patterns' => [], 'documentation' => []]]) ->beforeNormalization() ->ifTrue(function ($v) { - return 0 === count($v) || isset($v['path_patterns']) || isset($v['host_patterns']); + return 0 === count($v) || isset($v['path_patterns']) || isset($v['host_patterns']) || isset($v['documentation']); }) ->then(function ($v) { return ['default' => $v]; diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index a9d609a..6053f2c 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -20,18 +20,18 @@ class ConfigurationTest extends TestCase public function testDefaultArea() { $processor = new Processor(); - $config = $processor->processConfiguration(new Configuration(), [['areas' => ['path_patterns' => ['/foo']]]]); + $config = $processor->processConfiguration(new Configuration(), [['areas' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []]]]); - $this->assertSame(['default' => ['path_patterns' => ['/foo'], 'host_patterns' => []]], $config['areas']); + $this->assertSame(['default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []]], $config['areas']); } public function testAreas() { $processor = new Processor(); $config = $processor->processConfiguration(new Configuration(), [['areas' => $areas = [ - 'default' => ['path_patterns' => ['/foo'], 'host_patterns' => []], - 'internal' => ['path_patterns' => ['/internal'], 'host_patterns' => ['^swagger\.']], - 'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => []], + 'default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []], + 'internal' => ['path_patterns' => ['/internal'], 'host_patterns' => ['^swagger\.'], 'documentation' => []], + 'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => [], 'documentation' => []], ]]]); $this->assertSame($areas, $config['areas']); @@ -136,6 +136,6 @@ class ConfigurationTest extends TestCase $processor = new Processor(); $config = $processor->processConfiguration(new Configuration(), [['routes' => ['path_patterns' => ['/foo']]]]); - $this->assertSame(['default' => ['path_patterns' => ['/foo'], 'host_patterns' => []]], $config['areas']); + $this->assertSame(['default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []]], $config['areas']); } } diff --git a/Tests/DependencyInjection/NelmioApiDocExtensionTest.php b/Tests/DependencyInjection/NelmioApiDocExtensionTest.php index a2b3a25..4f2714b 100644 --- a/Tests/DependencyInjection/NelmioApiDocExtensionTest.php +++ b/Tests/DependencyInjection/NelmioApiDocExtensionTest.php @@ -24,8 +24,8 @@ class NelmioApiDocExtensionTest extends TestCase $extension = new NelmioApiDocExtension(); $extension->load([[ 'areas' => [ - 'default' => ['path_patterns' => ['/foo'], 'host_patterns' => []], - 'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => []], + 'default' => ['path_patterns' => ['/foo'], 'host_patterns' => [], 'documentation' => []], + 'commercial' => ['path_patterns' => ['/internal'], 'host_patterns' => [], 'documentation' => []], ], 'models' => [ 'names' => [ @@ -92,33 +92,45 @@ class NelmioApiDocExtensionTest extends TestCase $extension = new NelmioApiDocExtension(); $extension->load([ [ - 'documentation' => [ - 'info' => [ - 'title' => 'API documentation', - 'description' => 'This is the api documentation, use it wisely', - ], - ], + 'areas' => [ + 'default' => [ + 'documentation' => [ + 'info' => [ + 'title' => 'API documentation', + 'description' => 'This is the api documentation, use it wisely', + ], + ], + ] + ] ], [ - 'documentation' => [ - 'tags' => [ - [ - 'name' => 'secured', - 'description' => 'Requires authentication', - ], - [ - 'name' => 'another', - 'description' => 'Another tag serving another purpose', + 'areas' => [ + 'default' => [ + 'documentation' => [ + 'tags' => [ + [ + 'name' => 'secured', + 'description' => 'Requires authentication', + ], + [ + 'name' => 'another', + 'description' => 'Another tag serving another purpose', + ], + ], ], ], ], ], [ - 'documentation' => [ - 'paths' => [ - '/api/v1/model' => [ - 'get' => [ - 'tags' => ['secured'], + 'areas' => [ + 'default' => [ + 'documentation' => [ + 'paths' => [ + '/api/v1/model' => [ + 'get' => [ + 'tags' => ['secured'], + ], + ], ], ], ], @@ -148,6 +160,6 @@ class NelmioApiDocExtensionTest extends TestCase ], ], ], - ], $container->getDefinition('nelmio_api_doc.describers.config')->getArgument(0)); + ], $container->getDefinition('nelmio_api_doc.describers.config.default')->getArgument(0)); } } diff --git a/Tests/Functional/SwaggerUiTest.php b/Tests/Functional/SwaggerUiTest.php index 798980d..125e062 100644 --- a/Tests/Functional/SwaggerUiTest.php +++ b/Tests/Functional/SwaggerUiTest.php @@ -59,6 +59,7 @@ class SwaggerUiTest extends WebTestCase $client = self::createClient(); $crawler = $client->request('GET', '/app_dev.php/docs.json'); + $response = $client->getResponse(); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('application/json', $response->headers->get('Content-Type')); diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index a2d9d65..0590cf9 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -117,7 +117,47 @@ class TestKernel extends Kernel // Filter routes $c->loadFromExtension('nelmio_api_doc', [ - 'documentation' => [ + 'areas' => [ + 'default' => ['path_patterns' => ['^/api(?!/admin)'], 'host_patterns' => ['^api\.'], 'documentation' => [ + 'info' => [ + 'title' => 'My Test App', + ], + 'definitions' => [ + 'Test' => [ + 'type' => 'string', + ], + ], + 'parameters' => [ + 'test' => [ + 'name' => 'id', + 'in' => 'path', + 'required' => true, + ], + ], + ]], + 'test' => ['path_patterns' => ['^/test'], 'host_patterns' => ['^api-test\.'], 'documentation' => [ + 'info' => [ + 'title' => 'My Test App', + ], + 'definitions' => [ + 'Test' => [ + 'type' => 'string', + ], + ], + 'parameters' => [ + 'test' => [ + 'name' => 'id', + 'in' => 'path', + 'required' => true, + ], + ], + ]], + ], + ]); + } + + /* + * 'documentation' => [ 'info' => [ 'title' => 'My Test App', ], @@ -134,12 +174,7 @@ class TestKernel extends Kernel ], ], ], - 'areas' => [ - 'default' => ['path_patterns' => ['^/api(?!/admin)'], 'host_patterns' => ['^api\.']], - 'test' => ['path_patterns' => ['^/test'], 'host_patterns' => ['^api-test\.']], - ], - ]); - } + */ /** * {@inheritdoc}