-
-
Notifications
You must be signed in to change notification settings - Fork 899
Expand file tree
/
Copy pathConfiguration.php
More file actions
209 lines (202 loc) · 9.8 KB
/
Configuration.php
File metadata and controls
209 lines (202 loc) · 9.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?php
/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\DependencyInjection;
use Nelmio\ApiDocBundle\Render\Html\AssetsMode;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('nelmio_api_doc');
$rootNode = $treeBuilder->getRootNode();
$rootNode
->children()
->booleanNode('type_info')
->info('Use the symfony/type-info component for determining types.')
->defaultFalse()
->end()
->booleanNode('use_validation_groups')
->info('If true, `groups` passed to @Model annotations will be used to limit validation constraints')
->defaultFalse()
->end()
->booleanNode('api_platform_support')
->info('If false, the service declaration that support ApiPlatform will not be loaded even if ApiPlatform is detected in your installation')
->defaultTrue()
->end()
->arrayNode('cache')
->validate()
->ifTrue(function ($v) { return null !== $v['item_id'] && null === $v['pool']; })
->thenInvalid('Can not set cache.item_id if cache.pool is null')
->end()
->children()
->scalarNode('pool')
->info('define cache pool to use')
->defaultNull()
->end()
->scalarNode('item_id')
->info('define cache item id')
->defaultNull()
->end()
->end()
->end()
->arrayNode('documentation')
->useAttributeAsKey('key')
->info('The documentation used as base')
->example(['info' => ['title' => 'My App']])
->prototype('variable')->end()
->end()
->arrayNode('media_types')
->info('List of enabled Media Types')
->defaultValue(['json'])
->prototype('scalar')->end()
->end()
->arrayNode('html_config')
->info('UI configuration options')
->addDefaultsIfNotSet()
->children()
->scalarNode('assets_mode')
->defaultValue(AssetsMode::CDN)
->validate()
->ifNotInArray([AssetsMode::BUNDLE, AssetsMode::CDN, AssetsMode::OFFLINE])
->thenInvalid('Invalid assets mode %s')
->end()
->end()
->arrayNode('swagger_ui_config')
->info('https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/')
->addDefaultsIfNotSet()
->ignoreExtraKeys(false)
->end()
->arrayNode('redocly_config')
->info('https://redocly.com/docs/redoc/config/')
->addDefaultsIfNotSet()
->ignoreExtraKeys(false)
->end()
->end()
->end()
->arrayNode('areas')
->info('Filter the routes that are documented')
->defaultValue(
[
'default' => [
'path_patterns' => [],
'host_patterns' => [],
'with_annotation' => false,
'documentation' => [],
'name_patterns' => [],
'disable_default_routes' => false,
'cache' => [],
],
]
)
->beforeNormalization()
->ifTrue(function ($v) {
return 0 === count($v) || isset($v['path_patterns']) || isset($v['host_patterns']) || isset($v['documentation']);
})
->then(function ($v): array {
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')
->defaultValue([])
->example(['^/api', '^/api(?!/admin)'])
->prototype('scalar')->end()
->end()
->arrayNode('host_patterns')
->defaultValue([])
->example(['^api\.'])
->prototype('scalar')->end()
->end()
->arrayNode('name_patterns')
->defaultValue([])
->example(['^api_v1'])
->prototype('scalar')->end()
->end()
->booleanNode('with_annotation')
->defaultFalse()
->info('whether to filter by annotation')
->end()
->booleanNode('disable_default_routes')
->defaultFalse()
->info('if set disables default routes without annotations')
->end()
->arrayNode('documentation')
->useAttributeAsKey('key')
->defaultValue([])
->info('The documentation used for area')
->example(['info' => ['title' => 'My App']])
->prototype('variable')->end()
->end()
->arrayNode('cache')
->children()
->scalarNode('pool')
->info('define cache pool to use')
->defaultNull()
->end()
->scalarNode('item_id')
->info('define cache item id')
->defaultNull()
->end()
->end()
->end()
->end()
->end()
->end()
->arrayNode('models')
->addDefaultsIfNotSet()
->children()
->booleanNode('use_jms')->defaultFalse()->end()
->end()
->children()
->arrayNode('names')
->prototype('array')
->children()
->scalarNode('alias')->isRequired()->end()
->scalarNode('type')->isRequired()->end()
->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()
->end()
->variableNode('options')
->defaultValue(null)
->validate()
->ifTrue(function ($v) { return null !== $v && !is_array($v); })
->thenInvalid('Model options must be either `null` or an array.')
->end()
->end()
->arrayNode('serializationContext')
->defaultValue([])
->prototype('variable')->end()
->end()
->arrayNode('areas')
->defaultValue([])
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
}
}