Merge pull request #318 from antwebes/master

Added exclude_envs to ApiDoc annotation to exclude the documentation from the specified environments
This commit is contained in:
William Durand 2014-01-20 04:50:49 -08:00
commit 347ac74648
7 changed files with 44 additions and 1 deletions

View File

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

View File

@ -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']);

View File

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

View File

@ -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:

View File

@ -261,4 +261,22 @@ class TestController
public function zReturnSelectedParsersOutputAction()
{
}
/**
* @ApiDoc(
* section="private"
* )
*/
public function privateAction()
{
}
/**
* @ApiDoc(
* section="exclusive"
* )
*/
public function exclusiveAction()
{
}
}

View File

@ -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"]

View File

@ -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 }