2016-07-12 00:33:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2016-12-29 12:09:26 +01:00
|
|
|
* This file is part of the NelmioApiDocBundle package.
|
2016-07-12 00:33:55 +02:00
|
|
|
*
|
2016-12-29 12:09:26 +01:00
|
|
|
* (c) Nelmio
|
2016-07-12 00:33:55 +02:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2016-12-29 12:09:26 +01:00
|
|
|
namespace Nelmio\ApiDocBundle\DependencyInjection;
|
2016-07-12 00:33:55 +02:00
|
|
|
|
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
|
|
|
|
2016-11-30 15:04:53 +01:00
|
|
|
final class Configuration implements ConfigurationInterface
|
2016-07-12 00:33:55 +02:00
|
|
|
{
|
|
|
|
public function getConfigTreeBuilder()
|
|
|
|
{
|
2019-01-25 17:17:45 +00:00
|
|
|
$treeBuilder = new TreeBuilder('nelmio_api_doc');
|
|
|
|
|
|
|
|
if (method_exists($treeBuilder, 'getRootNode')) {
|
|
|
|
$rootNode = $treeBuilder->getRootNode();
|
|
|
|
} else {
|
|
|
|
// symfony < 4.2 support
|
|
|
|
$rootNode = $treeBuilder->root('nelmio_api_doc');
|
|
|
|
}
|
|
|
|
|
|
|
|
$rootNode
|
2016-11-30 14:08:10 +01:00
|
|
|
->children()
|
2017-01-25 18:53:19 +01:00
|
|
|
->arrayNode('documentation')
|
2017-08-08 19:32:53 +02:00
|
|
|
->useAttributeAsKey('key')
|
2017-01-25 18:53:19 +01:00
|
|
|
->info('The documentation used as base')
|
|
|
|
->example(['info' => ['title' => 'My App']])
|
|
|
|
->prototype('variable')->end()
|
|
|
|
->end()
|
2020-05-28 13:19:11 +02:00
|
|
|
->arrayNode('media_types')
|
|
|
|
->info('List of enabled Media Types')
|
|
|
|
->defaultValue(['json'])
|
|
|
|
->prototype('scalar')->end()
|
|
|
|
->end()
|
2018-01-05 13:08:02 +01:00
|
|
|
->arrayNode('areas')
|
2016-11-30 14:08:10 +01:00
|
|
|
->info('Filter the routes that are documented')
|
2019-01-05 16:37:43 +01:00
|
|
|
->defaultValue(
|
|
|
|
[
|
|
|
|
'default' => [
|
|
|
|
'path_patterns' => [],
|
|
|
|
'host_patterns' => [],
|
|
|
|
'with_annotation' => false,
|
|
|
|
'documentation' => [],
|
2019-04-16 18:22:51 +03:00
|
|
|
'name_patterns' => [],
|
2019-01-05 16:37:43 +01:00
|
|
|
],
|
|
|
|
]
|
|
|
|
)
|
2018-01-05 13:08:02 +01:00
|
|
|
->beforeNormalization()
|
|
|
|
->ifTrue(function ($v) {
|
2018-07-27 09:44:19 +05:00
|
|
|
return 0 === count($v) || isset($v['path_patterns']) || isset($v['host_patterns']) || isset($v['documentation']);
|
2018-01-05 13:08:02 +01:00
|
|
|
})
|
|
|
|
->then(function ($v) {
|
|
|
|
return ['default' => $v];
|
|
|
|
})
|
|
|
|
->end()
|
|
|
|
->validate()
|
|
|
|
->ifTrue(function ($v) {
|
|
|
|
return !isset($v['default']);
|
|
|
|
})
|
|
|
|
->thenInvalid('You must specify a `default` area under `nelmio_api_doc.areas`.')
|
|
|
|
->end()
|
|
|
|
->useAttributeAsKey('name')
|
|
|
|
->prototype('array')
|
|
|
|
->addDefaultsIfNotSet()
|
|
|
|
->children()
|
|
|
|
->arrayNode('path_patterns')
|
2018-03-13 12:40:36 -03:00
|
|
|
->defaultValue([])
|
2018-01-05 13:08:02 +01:00
|
|
|
->example(['^/api', '^/api(?!/admin)'])
|
|
|
|
->prototype('scalar')->end()
|
|
|
|
->end()
|
2018-03-13 12:40:36 -03:00
|
|
|
->arrayNode('host_patterns')
|
|
|
|
->defaultValue([])
|
|
|
|
->example(['^api\.'])
|
|
|
|
->prototype('scalar')->end()
|
|
|
|
->end()
|
2019-04-16 18:22:51 +03:00
|
|
|
->arrayNode('name_patterns')
|
|
|
|
->defaultValue([])
|
|
|
|
->example(['^api_v1'])
|
|
|
|
->prototype('scalar')->end()
|
|
|
|
->end()
|
2019-01-05 16:37:43 +01:00
|
|
|
->booleanNode('with_annotation')
|
|
|
|
->defaultFalse()
|
|
|
|
->info('whether to filter by annotation')
|
|
|
|
->end()
|
2018-07-26 10:16:10 +05:00
|
|
|
->arrayNode('documentation')
|
|
|
|
->useAttributeAsKey('key')
|
2018-08-14 12:30:38 +05:00
|
|
|
->defaultValue([])
|
|
|
|
->info('The documentation used for area')
|
2018-07-26 10:16:10 +05:00
|
|
|
->example(['info' => ['title' => 'My App']])
|
|
|
|
->prototype('variable')->end()
|
|
|
|
->end()
|
2016-11-30 14:08:10 +01:00
|
|
|
->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
2017-06-25 15:40:07 +02:00
|
|
|
->arrayNode('models')
|
|
|
|
->addDefaultsIfNotSet()
|
|
|
|
->children()
|
|
|
|
->booleanNode('use_jms')->defaultFalse()->end()
|
|
|
|
->end()
|
2018-06-10 09:56:38 +02:00
|
|
|
->children()
|
|
|
|
->arrayNode('names')
|
|
|
|
->prototype('array')
|
|
|
|
->children()
|
|
|
|
->scalarNode('alias')->isRequired()->end()
|
|
|
|
->scalarNode('type')->isRequired()->end()
|
2018-08-26 22:15:44 +02:00
|
|
|
->variableNode('groups')
|
|
|
|
->defaultValue(null)
|
|
|
|
->validate()
|
|
|
|
->ifTrue(function ($v) { return null !== $v && !is_array($v); })
|
|
|
|
->thenInvalid('Model groups must be either `null` or an array.')
|
|
|
|
->end()
|
2018-06-10 09:56:38 +02:00
|
|
|
->end()
|
|
|
|
->arrayNode('areas')
|
|
|
|
->defaultValue([])
|
|
|
|
->prototype('scalar')->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
2017-06-25 15:40:07 +02:00
|
|
|
->end()
|
2016-11-30 14:08:10 +01:00
|
|
|
->end();
|
|
|
|
|
2016-07-12 00:33:55 +02:00
|
|
|
return $treeBuilder;
|
|
|
|
}
|
|
|
|
}
|