From 5c12ff19de72ef2c8c9809e71b1bb72c431d5e36 Mon Sep 17 00:00:00 2001 From: Christian Schiffler Date: Tue, 8 Aug 2017 19:32:53 +0200 Subject: [PATCH] Allow configuration to be split on root key level. We now allow to split the configuration on multiple files, each containing one of the various root keys of the "documentation" entry. This means, you may now split "documentation/*" out to own yml files and import them. NOTE: this only allows splitting of entries being a direct child of the documentation entry, so splitting i.e. the info key over multiple files will not work. --- DependencyInjection/Configuration.php | 1 + .../NelmioApiDocExtensionTest.php | 85 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 Tests/DependencyInjection/NelmioApiDocExtensionTest.php 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)); + } +}