2012-04-12 20:34:19 +02:00
|
|
|
<?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;
|
2012-04-12 20:34:19 +02:00
|
|
|
|
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
|
|
|
|
|
|
|
class Configuration implements ConfigurationInterface
|
|
|
|
{
|
|
|
|
public function getConfigTreeBuilder()
|
|
|
|
{
|
|
|
|
$treeBuilder = new TreeBuilder();
|
|
|
|
$treeBuilder
|
|
|
|
->root('nelmio_api_doc')
|
|
|
|
->children()
|
|
|
|
->scalarNode('name')->defaultValue('API documentation')->end()
|
2014-01-16 13:42:37 +01:00
|
|
|
->arrayNode('exclude_sections')
|
|
|
|
->prototype('scalar')
|
|
|
|
->end()
|
|
|
|
->end()
|
2015-06-07 11:34:26 +02:00
|
|
|
->booleanNode('default_sections_opened')->defaultTrue()->end()
|
2013-04-08 11:44:43 +02:00
|
|
|
->arrayNode('motd')
|
|
|
|
->addDefaultsIfNotSet()
|
|
|
|
->children()
|
|
|
|
->scalarNode('template')->defaultValue('NelmioApiDocBundle::Components/motd.html.twig')->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
2012-10-17 18:44:14 +04:00
|
|
|
->arrayNode('request_listener')
|
|
|
|
->beforeNormalization()
|
|
|
|
->ifTrue(function ($a) { return is_bool($a); })
|
|
|
|
->then(function ($a) { return array('enabled' => $a); })
|
|
|
|
->end()
|
|
|
|
->addDefaultsIfNotSet()
|
|
|
|
->children()
|
|
|
|
->booleanNode('enabled')->defaultTrue()->end()
|
|
|
|
->scalarNode('parameter')->defaultValue('_doc')->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
2012-07-18 13:18:26 +02:00
|
|
|
->arrayNode('sandbox')
|
|
|
|
->addDefaultsIfNotSet()
|
|
|
|
->children()
|
|
|
|
->scalarNode('enabled')->defaultTrue()->end()
|
2013-03-01 21:24:54 +01:00
|
|
|
->scalarNode('endpoint')->defaultNull()->end()
|
2014-01-10 11:16:09 +01:00
|
|
|
->scalarNode('accept_type')->defaultNull()->end()
|
2014-05-21 15:59:55 +02:00
|
|
|
->arrayNode('body_format')
|
|
|
|
->addDefaultsIfNotSet()
|
|
|
|
->beforeNormalization()
|
|
|
|
->ifString()
|
2014-06-17 17:05:00 -07:00
|
|
|
->then(function ($v) { return array('default_format' => $v); })
|
2014-05-21 15:59:55 +02:00
|
|
|
->end()
|
|
|
|
->children()
|
|
|
|
->arrayNode('formats')
|
|
|
|
->defaultValue(array('form', 'json'))
|
|
|
|
->prototype('scalar')->end()
|
|
|
|
->end()
|
|
|
|
->enumNode('default_format')
|
|
|
|
->values(array('form', 'json'))
|
|
|
|
->defaultValue('form')
|
|
|
|
->end()
|
|
|
|
->end()
|
2013-06-04 15:30:07 -07:00
|
|
|
->end()
|
2012-10-17 15:27:20 +04:00
|
|
|
->arrayNode('request_format')
|
|
|
|
->addDefaultsIfNotSet()
|
|
|
|
->children()
|
2014-05-17 22:45:30 +02:00
|
|
|
->arrayNode('formats')
|
|
|
|
->defaultValue(array(
|
|
|
|
'json' => 'application/json',
|
|
|
|
'xml' => 'application/xml'
|
|
|
|
))
|
|
|
|
->prototype('scalar')->end()
|
|
|
|
->end()
|
2012-10-17 15:27:20 +04:00
|
|
|
->enumNode('method')
|
|
|
|
->values(array('format_param', 'accept_header'))
|
|
|
|
->defaultValue('format_param')
|
|
|
|
->end()
|
2014-05-17 22:45:30 +02:00
|
|
|
->scalarNode('default_format')->defaultValue('json')->end()
|
2012-10-17 15:27:20 +04:00
|
|
|
->end()
|
2012-10-16 23:41:16 +04:00
|
|
|
->end()
|
2012-08-10 13:55:35 +02:00
|
|
|
->arrayNode('authentication')
|
|
|
|
->children()
|
2012-10-17 15:15:35 +04:00
|
|
|
->scalarNode('delivery')
|
2012-08-10 13:55:35 +02:00
|
|
|
->isRequired()
|
2012-10-17 15:15:35 +04:00
|
|
|
->validate()
|
2014-07-25 12:08:00 +02:00
|
|
|
->ifNotInArray(array('query', 'http', 'header'))
|
2012-10-17 15:15:35 +04:00
|
|
|
->thenInvalid("Unknown authentication delivery type '%s'.")
|
|
|
|
->end()
|
2012-08-10 13:55:35 +02:00
|
|
|
->end()
|
2014-07-25 12:08:00 +02:00
|
|
|
->scalarNode('name')->isRequired()->end()
|
|
|
|
->enumNode('type')
|
|
|
|
->info('Required if http delivery is selected.')
|
|
|
|
->values(array('basic', 'bearer'))
|
|
|
|
->end()
|
2013-04-12 08:49:38 +03:00
|
|
|
->booleanNode('custom_endpoint')->defaultFalse()->end()
|
2012-08-10 13:55:35 +02:00
|
|
|
->end()
|
2014-07-25 12:08:00 +02:00
|
|
|
->validate()
|
2014-07-30 10:50:23 +02:00
|
|
|
->ifTrue(function ($v) {
|
2014-07-25 12:08:00 +02:00
|
|
|
return 'http' === $v['delivery'] && !$v['type'] ;
|
|
|
|
})
|
|
|
|
->thenInvalid('"type" is required when using http delivery.')
|
|
|
|
->end()
|
|
|
|
# http_basic BC
|
|
|
|
->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()
|
2012-08-10 13:55:35 +02:00
|
|
|
->end()
|
2015-06-07 11:34:26 +02:00
|
|
|
->booleanNode('entity_to_choice')->defaultTrue()->end()
|
2012-07-18 13:18:26 +02:00
|
|
|
->end()
|
|
|
|
->end()
|
2014-06-17 17:05:00 -07:00
|
|
|
->arrayNode('swagger')
|
|
|
|
->addDefaultsIfNotSet()
|
|
|
|
->children()
|
2014-08-07 12:06:04 -07:00
|
|
|
->scalarNode('model_naming_strategy')->defaultValue('dot_notation')->end()
|
2014-06-17 17:05:00 -07:00
|
|
|
->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()
|
2015-06-07 11:34:26 +02:00
|
|
|
->scalarNode('TermsOfServiceUrl')->defaultNull()->end()
|
|
|
|
->scalarNode('contact')->defaultNull()->end()
|
|
|
|
->scalarNode('license')->defaultNull()->end()
|
|
|
|
->scalarNode('licenseUrl')->defaultNull()->end()
|
2014-06-17 17:05:00 -07:00
|
|
|
->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
2014-07-21 10:26:06 -07:00
|
|
|
->arrayNode('cache')
|
|
|
|
->addDefaultsIfNotSet()
|
|
|
|
->children()
|
2015-06-07 11:34:26 +02:00
|
|
|
->booleanNode('enabled')->defaultFalse()->end()
|
2014-07-21 10:26:06 -07:00
|
|
|
->scalarNode('file')->defaultValue('%kernel.cache_dir%/api-doc.cache')->end()
|
|
|
|
->end()
|
|
|
|
->end()
|
2012-05-24 01:22:45 +02:00
|
|
|
->end();
|
2012-04-12 20:34:19 +02:00
|
|
|
|
|
|
|
return $treeBuilder;
|
|
|
|
}
|
|
|
|
}
|