diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b00a713..744b48f 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,6 +23,7 @@ final class Configuration implements ConfigurationInterface ->root('nelmio_api_doc') ->children() ->arrayNode('documentation') + ->useAttributeAsKey('key') ->info('The documentation used as base') ->example(['info' => ['title' => 'My App']]) ->prototype('variable')->end() diff --git a/Tests/DependencyInjection/NelmioApiDocExtensionTest.php b/Tests/DependencyInjection/NelmioApiDocExtensionTest.php new file mode 100644 index 0000000..27ca35c --- /dev/null +++ b/Tests/DependencyInjection/NelmioApiDocExtensionTest.php @@ -0,0 +1,85 @@ +setParameter('kernel.bundles', []); + $extension = new NelmioApiDocExtension(); + $extension->load([ + [ + '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', + ], + ], + ], + ], + [ + 'documentation' => [ + 'paths' => [ + '/api/v1/model' => [ + 'get' => [ + 'tags' => ['secured'], + ], + ], + ], + ], + ], + ], $container); + + $this->assertSame([ + 'info' => [ + 'title' => 'API documentation', + 'description' => 'This is the api documentation, use it wisely', + ], + 'tags' => [ + [ + 'name' => 'secured', + 'description' => 'Requires authentication', + ], + [ + 'name' => 'another', + 'description' => 'Another tag serving another purpose', + ], + ], + 'paths' => [ + '/api/v1/model' => [ + 'get' => [ + 'tags' => ['secured'], + ], + ], + ], + ], $container->getDefinition('nelmio_api_doc.describers.config')->getArgument(0)); + } +}