diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index cafd3d0..3c943c3 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,6 +23,10 @@ class Configuration implements ConfigurationInterface ->root('nelmio_api_doc') ->children() ->scalarNode('name')->defaultValue('API documentation')->end() + ->arrayNode('exclude_sections') + ->prototype('scalar') + ->end() + ->end() ->arrayNode('motd') ->addDefaultsIfNotSet() ->children() diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index be2e5b8..3406f25 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -29,6 +29,7 @@ class NelmioApiDocExtension extends Extension $config = $processor->processConfiguration($configuration, $configs); $container->setParameter('nelmio_api_doc.motd.template', $config['motd']['template']); + $container->setParameter('nelmio_api_doc.exclude_sections', $config['exclude_sections']); $container->setParameter('nelmio_api_doc.api_name', $config['name']); $container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']); $container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']); diff --git a/Extractor/ApiDocExtractor.php b/Extractor/ApiDocExtractor.php index 993e2ba..6f051a8 100644 --- a/Extractor/ApiDocExtractor.php +++ b/Extractor/ApiDocExtractor.php @@ -100,6 +100,7 @@ class ApiDocExtractor { $array = array(); $resources = array(); + $excludeSections = $this->container->getParameter('nelmio_api_doc.exclude_sections'); foreach ($routes as $route) { if (!$route instanceof Route) { @@ -107,7 +108,8 @@ class ApiDocExtractor } if ($method = $this->getReflectionMethod($route->getDefault('_controller'))) { - if ($annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS)) { + $annotation = $this->reader->getMethodAnnotation($method, self::ANNOTATION_CLASS); + if ($annotation && !in_array($annotation->getSection(), $excludeSections)) { if ($annotation->isResource()) { if ($resource = $annotation->getResource()) { $resources[] = $resource; diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 0483079..637c515 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -355,6 +355,12 @@ You can specify your own API name: nelmio_api_doc: name: My API +You can specify which sections to exclude from the documentation generation: + + # app/config/config.yml + nelmio_api_doc: + exclude_sections: ["privateapi", "testapi"] + The bundle provides a way to register multiple `input` parsers. The first parser that can handle the specified input is used, so you can configure their priorities via container tags. Here's an example parser service registration: @@ -396,6 +402,7 @@ Look at the built-in [Handlers](https://github.com/nelmio/NelmioApiDocBundle/tre ``` yaml nelmio_api_doc: name: API documentation + exclude_sections: [] motd: template: NelmioApiDocBundle::Components/motd.html.twig request_listener: diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index 1c0a266..5d9d3f3 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -261,4 +261,22 @@ class TestController public function zReturnSelectedParsersOutputAction() { } + + /** + * @ApiDoc( + * section="private" + * ) + */ + public function privateAction() + { + } + + /** + * @ApiDoc( + * section="exclusive" + * ) + */ + public function exclusiveAction() + { + } } diff --git a/Tests/Fixtures/app/config/default.yml b/Tests/Fixtures/app/config/default.yml index 6d596bc..c7edc26 100644 --- a/Tests/Fixtures/app/config/default.yml +++ b/Tests/Fixtures/app/config/default.yml @@ -51,3 +51,6 @@ jms_serializer: # class: My\FooBundle\Entity\User # expected path: @MyFooBundle/Resources/config/serializer/Entity.User.(yml|xml|php) auto_detection: true + +nelmio_api_doc: + exclude_sections: ["private", "exclusive"] diff --git a/Tests/Fixtures/app/config/routing.yml b/Tests/Fixtures/app/config/routing.yml index 62be809..370ae0d 100644 --- a/Tests/Fixtures/app/config/routing.yml +++ b/Tests/Fixtures/app/config/routing.yml @@ -141,3 +141,11 @@ test_route_19: test_route_20: pattern: /z-return-selected-parsers-input defaults: { _controller: NelmioApiDocTestBundle:Test:zReturnSelectedParsersInput } + +test_route_private: + pattern: /private + defaults: { _controller: NelmioApiDocTestBundle:Test:private } + +test_route_exclusive: + pattern: /exclusive + defaults: { _controller: NelmioApiDocTestBundle:Test:exclusive } \ No newline at end of file