178 lines
8.2 KiB
PHP
Raw Permalink Normal View History

<?php
2012-04-13 11:03:05 +02:00
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2012-04-13 10:05:32 +02:00
namespace Nelmio\ApiDocBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
2024-06-18 20:01:11 +03:00
public function getConfigTreeBuilder(): TreeBuilder
{
$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
->children()
->scalarNode('name')->defaultValue('API documentation')->end()
->arrayNode('exclude_sections')
->prototype('scalar')
->end()
->end()
->booleanNode('default_sections_opened')->defaultTrue()->end()
2013-04-08 11:44:43 +02:00
->arrayNode('motd')
->addDefaultsIfNotSet()
->children()
->scalarNode('template')->defaultValue('@NelmioApiDoc/Components/motd.html.twig')->end()
2013-04-08 11:44:43 +02:00
->end()
->end()
->arrayNode('request_listener')
->beforeNormalization()
->ifTrue(function ($a) { return is_bool($a); })
2024-10-01 15:54:04 +03:00
->then(function ($a) { return ['enabled' => $a]; })
->end()
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultTrue()->end()
->scalarNode('parameter')->defaultValue('_doc')->end()
->end()
->end()
->arrayNode('sandbox')
->addDefaultsIfNotSet()
->children()
->scalarNode('enabled')->defaultTrue()->end()
->scalarNode('endpoint')->defaultNull()->end()
->scalarNode('accept_type')->defaultNull()->end()
->arrayNode('body_format')
->addDefaultsIfNotSet()
->beforeNormalization()
->ifString()
2024-10-01 15:54:04 +03:00
->then(function ($v) { return ['default_format' => $v]; })
->end()
->children()
->arrayNode('formats')
2024-10-01 15:54:04 +03:00
->defaultValue(['form', 'json'])
->prototype('scalar')->end()
->end()
->enumNode('default_format')
2024-10-01 15:54:04 +03:00
->values(['form', 'json'])
->defaultValue('form')
->end()
->end()
->end()
->arrayNode('request_format')
->addDefaultsIfNotSet()
->children()
2014-05-17 22:45:30 +02:00
->arrayNode('formats')
2024-10-01 15:54:04 +03:00
->defaultValue([
2014-05-17 22:45:30 +02:00
'json' => 'application/json',
2024-10-01 15:54:04 +03:00
'xml' => 'application/xml',
])
2014-05-17 22:45:30 +02:00
->prototype('scalar')->end()
->end()
->enumNode('method')
2024-10-01 15:54:04 +03:00
->values(['format_param', 'accept_header'])
->defaultValue('format_param')
->end()
2014-05-17 22:45:30 +02:00
->scalarNode('default_format')->defaultValue('json')->end()
->end()
->end()
->arrayNode('authentication')
->children()
2012-10-17 15:15:35 +04:00
->scalarNode('delivery')
->isRequired()
2012-10-17 15:15:35 +04:00
->validate()
2024-10-01 15:54:04 +03:00
->ifNotInArray(['query', 'http', 'header'])
2012-10-17 15:15:35 +04:00
->thenInvalid("Unknown authentication delivery type '%s'.")
->end()
->end()
2014-07-25 12:08:00 +02:00
->scalarNode('name')->isRequired()->end()
->enumNode('type')
->info('Required if http delivery is selected.')
2024-10-01 15:54:04 +03:00
->values(['basic', 'bearer'])
2014-07-25 12:08:00 +02:00
->end()
2013-04-12 08:49:38 +03:00
->booleanNode('custom_endpoint')->defaultFalse()->end()
->end()
2014-07-25 12:08:00 +02:00
->validate()
2014-07-30 10:50:23 +02:00
->ifTrue(function ($v) {
2024-10-01 15:54:04 +03:00
return 'http' === $v['delivery'] && !$v['type'];
2014-07-25 12:08:00 +02:00
})
->thenInvalid('"type" is required when using http delivery.')
->end()
2024-10-01 15:54:04 +03:00
// http_basic BC
2014-07-25 12:08:00 +02:00
->beforeNormalization()
->ifTrue(function ($v) {
return 'http_basic' === $v['delivery'];
})
->then(function ($v) {
$v['delivery'] = 'http';
$v['type'] = 'basic';
return $v;
})
->end()
->beforeNormalization()
->ifTrue(function ($v) {
return 'http' === $v['delivery'];
})
->then(function ($v) {
if ('http' === $v['delivery'] && !isset($v['name'])) {
$v['name'] = 'Authorization';
}
return $v;
})
->end()
->end()
->booleanNode('entity_to_choice')->defaultTrue()->end()
->end()
->end()
->arrayNode('swagger')
->addDefaultsIfNotSet()
->children()
2014-08-07 12:06:04 -07:00
->scalarNode('model_naming_strategy')->defaultValue('dot_notation')->end()
->scalarNode('api_base_path')->defaultValue('/api')->end()
->scalarNode('swagger_version')->defaultValue('1.2')->end()
->scalarNode('api_version')->defaultValue('0.1')->end()
->arrayNode('info')
->addDefaultsIfNotSet()
->children()
->scalarNode('title')->defaultValue('Symfony2')->end()
->scalarNode('description')->defaultValue('My awesome Symfony2 app!')->end()
->scalarNode('TermsOfServiceUrl')->defaultNull()->end()
->scalarNode('contact')->defaultNull()->end()
->scalarNode('license')->defaultNull()->end()
->scalarNode('licenseUrl')->defaultNull()->end()
->end()
->end()
->end()
->end()
->arrayNode('cache')
->addDefaultsIfNotSet()
->children()
->booleanNode('enabled')->defaultFalse()->end()
->scalarNode('file')->defaultValue('%kernel.cache_dir%/api-doc.cache')->end()
->end()
->end()
2024-10-01 15:54:04 +03:00
->end()
;
return $treeBuilder;
}
}