• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 20822307873

08 Jan 2026 03:35PM UTC coverage: 21.258% (-7.6%) from 28.879%
20822307873

Pull #7658

github

web-flow
Merge 7e9d13d39 into 550b7621d
Pull Request #7658: fix(openapi): properly document list parameters

0 of 2 new or added lines in 1 file covered. (0.0%)

14467 existing lines in 472 files now uncovered.

12215 of 57461 relevant lines covered (21.26%)

49.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Symfony/Bundle/DependencyInjection/Configuration.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Symfony\Bundle\DependencyInjection;
15

16
use ApiPlatform\Doctrine\Common\Filter\OrderFilterInterface;
17
use ApiPlatform\Metadata\ApiResource;
18
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
19
use ApiPlatform\Metadata\Post;
20
use ApiPlatform\Metadata\Put;
21
use ApiPlatform\Symfony\Controller\MainController;
22
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
23
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
24
use Doctrine\ORM\EntityManagerInterface;
25
use Doctrine\ORM\OptimisticLockException;
26
use GraphQL\GraphQL;
27
use Symfony\Bundle\FrameworkBundle\Controller\ControllerHelper;
28
use Symfony\Bundle\FullStack;
29
use Symfony\Bundle\MakerBundle\MakerBundle;
30
use Symfony\Bundle\MercureBundle\MercureBundle;
31
use Symfony\Bundle\TwigBundle\TwigBundle;
32
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
33
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
34
use Symfony\Component\Config\Definition\ConfigurationInterface;
35
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
36
use Symfony\Component\HttpFoundation\Response;
37
use Symfony\Component\JsonStreamer\JsonStreamWriter;
38
use Symfony\Component\Messenger\MessageBusInterface;
39
use Symfony\Component\Serializer\Exception\ExceptionInterface as SerializerExceptionInterface;
40
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
41
use Symfony\Component\Yaml\Yaml;
42

43
/**
44
 * The configuration of the bundle.
45
 *
46
 * @author Kévin Dunglas <dunglas@gmail.com>
47
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
48
 */
49
final class Configuration implements ConfigurationInterface
50
{
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getConfigTreeBuilder(): TreeBuilder
55
    {
UNCOV
56
        $treeBuilder = new TreeBuilder('api_platform');
×
UNCOV
57
        $rootNode = $treeBuilder->getRootNode();
×
58

UNCOV
59
        $rootNode
×
UNCOV
60
            ->beforeNormalization()
×
UNCOV
61
                ->ifTrue(static function ($v) {
×
UNCOV
62
                    return false === ($v['enable_swagger'] ?? null);
×
UNCOV
63
                })
×
UNCOV
64
                ->then(static function ($v) {
×
UNCOV
65
                    $v['swagger']['versions'] = [];
×
66

UNCOV
67
                    return $v;
×
UNCOV
68
                })
×
UNCOV
69
            ->end()
×
UNCOV
70
            ->children()
×
UNCOV
71
                ->scalarNode('title')
×
UNCOV
72
                    ->info('The title of the API.')
×
UNCOV
73
                    ->cannotBeEmpty()
×
UNCOV
74
                    ->defaultValue('')
×
UNCOV
75
                ->end()
×
UNCOV
76
                ->scalarNode('description')
×
UNCOV
77
                    ->info('The description of the API.')
×
UNCOV
78
                    ->cannotBeEmpty()
×
UNCOV
79
                    ->defaultValue('')
×
UNCOV
80
                ->end()
×
UNCOV
81
                ->scalarNode('version')
×
UNCOV
82
                    ->info('The version of the API.')
×
UNCOV
83
                    ->cannotBeEmpty()
×
UNCOV
84
                    ->defaultValue('0.0.0')
×
UNCOV
85
                ->end()
×
UNCOV
86
                ->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
×
UNCOV
87
                ->booleanNode('use_symfony_listeners')->defaultFalse()->info(sprintf('Uses Symfony event listeners instead of the %s.', MainController::class))->end()
×
UNCOV
88
                ->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end()
×
UNCOV
89
                ->scalarNode('asset_package')->defaultNull()->info('Specify an asset package name to use.')->end()
×
UNCOV
90
                ->scalarNode('path_segment_name_generator')->defaultValue('api_platform.metadata.path_segment_name_generator.underscore')->info('Specify a path name generator to use.')->end()
×
UNCOV
91
                ->scalarNode('inflector')->defaultValue('api_platform.metadata.inflector')->info('Specify an inflector to use.')->end()
×
UNCOV
92
                ->arrayNode('validator')
×
UNCOV
93
                    ->addDefaultsIfNotSet()
×
UNCOV
94
                    ->children()
×
UNCOV
95
                        ->variableNode('serialize_payload_fields')->defaultValue([])->info('Set to null to serialize all payload fields when a validation error is thrown, or set the fields you want to include explicitly.')->end()
×
UNCOV
96
                        ->booleanNode('query_parameter_validation')
×
UNCOV
97
                            ->defaultValue(true)
×
UNCOV
98
                            ->setDeprecated('api-platform/symfony', '4.2', 'Will be removed in API Platform 5.0.')
×
UNCOV
99
                        ->end()
×
UNCOV
100
                    ->end()
×
UNCOV
101
                ->end()
×
UNCOV
102
                ->arrayNode('eager_loading')
×
UNCOV
103
                    ->canBeDisabled()
×
UNCOV
104
                    ->addDefaultsIfNotSet()
×
UNCOV
105
                    ->children()
×
UNCOV
106
                        ->booleanNode('fetch_partial')->defaultFalse()->info('Fetch only partial data according to serialization groups. If enabled, Doctrine ORM entities will not work as expected if any of the other fields are used.')->end()
×
UNCOV
107
                        ->integerNode('max_joins')->defaultValue(30)->info('Max number of joined relations before EagerLoading throws a RuntimeException')->end()
×
UNCOV
108
                        ->booleanNode('force_eager')->defaultTrue()->info('Force join on every relation. If disabled, it will only join relations having the EAGER fetch mode.')->end()
×
UNCOV
109
                    ->end()
×
UNCOV
110
                ->end()
×
UNCOV
111
                ->booleanNode('handle_symfony_errors')->defaultFalse()->info('Allows to handle symfony exceptions.')->end()
×
UNCOV
112
                ->booleanNode('enable_swagger')->defaultTrue()->info('Enable the Swagger documentation and export.')->end()
×
UNCOV
113
                ->booleanNode('enable_json_streamer')->defaultValue(class_exists(ControllerHelper::class) && class_exists(JsonStreamWriter::class))->info('Enable json streamer.')->end()
×
UNCOV
114
                ->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger UI')->end()
×
UNCOV
115
                ->booleanNode('enable_re_doc')->defaultValue(class_exists(TwigBundle::class))->info('Enable ReDoc')->end()
×
UNCOV
116
                ->booleanNode('enable_entrypoint')->defaultTrue()->info('Enable the entrypoint')->end()
×
UNCOV
117
                ->booleanNode('enable_docs')->defaultTrue()->info('Enable the docs')->end()
×
UNCOV
118
                ->booleanNode('enable_profiler')->defaultTrue()->info('Enable the data collector and the WebProfilerBundle integration.')->end()
×
UNCOV
119
                ->booleanNode('enable_phpdoc_parser')->defaultTrue()->info('Enable resource metadata collector using PHPStan PhpDocParser.')->end()
×
UNCOV
120
                ->booleanNode('enable_link_security')->defaultFalse()->info('Enable security for Links (sub resources)')->end()
×
UNCOV
121
                ->arrayNode('collection')
×
UNCOV
122
                    ->addDefaultsIfNotSet()
×
UNCOV
123
                    ->children()
×
UNCOV
124
                        ->scalarNode('exists_parameter_name')->defaultValue('exists')->cannotBeEmpty()->info('The name of the query parameter to filter on nullable field values.')->end()
×
UNCOV
125
                        ->scalarNode('order')->defaultValue('ASC')->info('The default order of results.')->end() // Default ORDER is required for postgresql and mysql >= 5.7 when using LIMIT/OFFSET request
×
UNCOV
126
                        ->scalarNode('order_parameter_name')->defaultValue('order')->cannotBeEmpty()->info('The name of the query parameter to order results.')->end()
×
UNCOV
127
                        ->enumNode('order_nulls_comparison')->defaultNull()->values(interface_exists(OrderFilterInterface::class) ? array_merge(array_keys(OrderFilterInterface::NULLS_DIRECTION_MAP), [null]) : [null])->info('The nulls comparison strategy.')->end()
×
UNCOV
128
                        ->arrayNode('pagination')
×
UNCOV
129
                            ->canBeDisabled()
×
UNCOV
130
                            ->addDefaultsIfNotSet()
×
UNCOV
131
                            ->children()
×
UNCOV
132
                                ->scalarNode('page_parameter_name')->defaultValue('page')->cannotBeEmpty()->info('The default name of the parameter handling the page number.')->end()
×
UNCOV
133
                                ->scalarNode('enabled_parameter_name')->defaultValue('pagination')->cannotBeEmpty()->info('The name of the query parameter to enable or disable pagination.')->end()
×
UNCOV
134
                                ->scalarNode('items_per_page_parameter_name')->defaultValue('itemsPerPage')->cannotBeEmpty()->info('The name of the query parameter to set the number of items per page.')->end()
×
UNCOV
135
                                ->scalarNode('partial_parameter_name')->defaultValue('partial')->cannotBeEmpty()->info('The name of the query parameter to enable or disable partial pagination.')->end()
×
UNCOV
136
                            ->end()
×
UNCOV
137
                        ->end()
×
UNCOV
138
                    ->end()
×
UNCOV
139
                ->end()
×
UNCOV
140
                ->arrayNode('mapping')
×
UNCOV
141
                    ->addDefaultsIfNotSet()
×
UNCOV
142
                    ->children()
×
UNCOV
143
                        ->arrayNode('imports')
×
UNCOV
144
                            ->prototype('scalar')->end()
×
UNCOV
145
                        ->end()
×
UNCOV
146
                        ->arrayNode('paths')
×
UNCOV
147
                            ->prototype('scalar')->end()
×
UNCOV
148
                        ->end()
×
UNCOV
149
                    ->end()
×
UNCOV
150
                ->end()
×
UNCOV
151
                ->arrayNode('resource_class_directories')
×
UNCOV
152
                    ->prototype('scalar')->end()
×
UNCOV
153
                    ->setDeprecated('api-platform/symfony', '4.1', 'The "resource_class_directories" configuration is deprecated, classes using #[ApiResource] attribute are autoconfigured by the dependency injection container.')
×
UNCOV
154
                ->end()
×
UNCOV
155
                ->arrayNode('serializer')
×
UNCOV
156
                    ->addDefaultsIfNotSet()
×
UNCOV
157
                    ->children()
×
UNCOV
158
                        ->booleanNode('hydra_prefix')->defaultFalse()->info('Use the "hydra:" prefix.')->end()
×
UNCOV
159
                    ->end()
×
UNCOV
160
                ->end()
×
UNCOV
161
            ->end();
×
162

UNCOV
163
        $this->addDoctrineOrmSection($rootNode);
×
UNCOV
164
        $this->addDoctrineMongoDbOdmSection($rootNode);
×
UNCOV
165
        $this->addOAuthSection($rootNode);
×
UNCOV
166
        $this->addGraphQlSection($rootNode);
×
UNCOV
167
        $this->addSwaggerSection($rootNode);
×
UNCOV
168
        $this->addHttpCacheSection($rootNode);
×
UNCOV
169
        $this->addMercureSection($rootNode);
×
UNCOV
170
        $this->addMessengerSection($rootNode);
×
UNCOV
171
        $this->addElasticsearchSection($rootNode);
×
UNCOV
172
        $this->addOpenApiSection($rootNode);
×
UNCOV
173
        $this->addMakerSection($rootNode);
×
174

UNCOV
175
        $this->addExceptionToStatusSection($rootNode);
×
176

UNCOV
177
        $this->addFormatSection($rootNode, 'formats', [
×
UNCOV
178
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
UNCOV
179
        ]);
×
UNCOV
180
        $this->addFormatSection($rootNode, 'patch_formats', [
×
UNCOV
181
            'json' => ['mime_types' => ['application/merge-patch+json']],
×
UNCOV
182
        ]);
×
183

UNCOV
184
        $defaultDocFormats = [
×
UNCOV
185
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
UNCOV
186
            'jsonopenapi' => ['mime_types' => ['application/vnd.openapi+json']],
×
UNCOV
187
            'html' => ['mime_types' => ['text/html']],
×
UNCOV
188
        ];
×
189

UNCOV
190
        if (class_exists(Yaml::class)) {
×
UNCOV
191
            $defaultDocFormats['yamlopenapi'] = ['mime_types' => ['application/vnd.openapi+yaml']];
×
192
        }
193

UNCOV
194
        $this->addFormatSection($rootNode, 'docs_formats', $defaultDocFormats);
×
195

UNCOV
196
        $this->addFormatSection($rootNode, 'error_formats', [
×
UNCOV
197
            'jsonld' => ['mime_types' => ['application/ld+json']],
×
UNCOV
198
            'jsonproblem' => ['mime_types' => ['application/problem+json']],
×
UNCOV
199
            'json' => ['mime_types' => ['application/problem+json', 'application/json']],
×
UNCOV
200
        ]);
×
UNCOV
201
        $rootNode
×
UNCOV
202
            ->children()
×
UNCOV
203
                ->arrayNode('jsonschema_formats')
×
UNCOV
204
                    ->scalarPrototype()->end()
×
UNCOV
205
                    ->defaultValue([])
×
UNCOV
206
                    ->info('The JSON formats to compute the JSON Schemas for.')
×
UNCOV
207
                ->end()
×
UNCOV
208
            ->end();
×
209

UNCOV
210
        $this->addDefaultsSection($rootNode);
×
211

UNCOV
212
        return $treeBuilder;
×
213
    }
214

215
    private function addDoctrineOrmSection(ArrayNodeDefinition $rootNode): void
216
    {
UNCOV
217
        $rootNode
×
UNCOV
218
            ->children()
×
UNCOV
219
                ->arrayNode('doctrine')
×
UNCOV
220
                    ->{class_exists(DoctrineBundle::class) && interface_exists(EntityManagerInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
UNCOV
221
                ->end()
×
UNCOV
222
            ->end();
×
223
    }
224

225
    private function addDoctrineMongoDbOdmSection(ArrayNodeDefinition $rootNode): void
226
    {
UNCOV
227
        $rootNode
×
UNCOV
228
            ->children()
×
UNCOV
229
                ->arrayNode('doctrine_mongodb_odm')
×
UNCOV
230
                    ->{class_exists(DoctrineMongoDBBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
UNCOV
231
                ->end()
×
UNCOV
232
            ->end();
×
233
    }
234

235
    private function addOAuthSection(ArrayNodeDefinition $rootNode): void
236
    {
UNCOV
237
        $rootNode
×
UNCOV
238
            ->children()
×
UNCOV
239
                ->arrayNode('oauth')
×
UNCOV
240
                    ->canBeEnabled()
×
UNCOV
241
                    ->addDefaultsIfNotSet()
×
UNCOV
242
                    ->children()
×
UNCOV
243
                        ->scalarNode('clientId')->defaultValue('')->info('The oauth client id.')->end()
×
UNCOV
244
                        ->scalarNode('clientSecret')
×
UNCOV
245
                            ->defaultValue('')
×
UNCOV
246
                            ->info('The OAuth client secret. Never use this parameter in your production environment. It exposes crucial security information. This feature is intended for dev/test environments only. Enable "oauth.pkce" instead')
×
UNCOV
247
                        ->end()
×
UNCOV
248
                        ->booleanNode('pkce')->defaultFalse()->info('Enable the oauth PKCE.')->end()
×
UNCOV
249
                        ->scalarNode('type')->defaultValue('oauth2')->info('The oauth type.')->end()
×
UNCOV
250
                        ->scalarNode('flow')->defaultValue('application')->info('The oauth flow grant type.')->end()
×
UNCOV
251
                        ->scalarNode('tokenUrl')->defaultValue('')->info('The oauth token url.')->end()
×
UNCOV
252
                        ->scalarNode('authorizationUrl')->defaultValue('')->info('The oauth authentication url.')->end()
×
UNCOV
253
                        ->scalarNode('refreshUrl')->defaultValue('')->info('The oauth refresh url.')->end()
×
UNCOV
254
                        ->arrayNode('scopes')
×
UNCOV
255
                            ->prototype('scalar')->end()
×
UNCOV
256
                        ->end()
×
UNCOV
257
                    ->end()
×
UNCOV
258
                ->end()
×
UNCOV
259
            ->end();
×
260
    }
261

262
    private function addGraphQlSection(ArrayNodeDefinition $rootNode): void
263
    {
UNCOV
264
        $rootNode
×
UNCOV
265
            ->children()
×
UNCOV
266
                ->arrayNode('graphql')
×
UNCOV
267
                    ->{class_exists(GraphQL::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
UNCOV
268
                    ->addDefaultsIfNotSet()
×
UNCOV
269
                    ->children()
×
UNCOV
270
                        ->scalarNode('default_ide')->defaultValue('graphiql')->end()
×
UNCOV
271
                        ->arrayNode('graphiql')
×
UNCOV
272
                            ->{class_exists(GraphQL::class) && class_exists(TwigBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
UNCOV
273
                        ->end()
×
UNCOV
274
                        ->arrayNode('introspection')
×
UNCOV
275
                            ->canBeDisabled()
×
UNCOV
276
                        ->end()
×
UNCOV
277
                        ->integerNode('max_query_depth')->defaultValue(20)
×
UNCOV
278
                        ->end()
×
UNCOV
279
                        ->arrayNode('graphql_playground')
×
UNCOV
280
                            ->setDeprecated('api-platform/core', '4.0')
×
UNCOV
281
                        ->end()
×
UNCOV
282
                        ->integerNode('max_query_complexity')->defaultValue(500)
×
UNCOV
283
                        ->end()
×
UNCOV
284
                        ->scalarNode('nesting_separator')->defaultValue('_')->info('The separator to use to filter nested fields.')->end()
×
UNCOV
285
                        ->arrayNode('collection')
×
UNCOV
286
                            ->addDefaultsIfNotSet()
×
UNCOV
287
                            ->children()
×
UNCOV
288
                                ->arrayNode('pagination')
×
UNCOV
289
                                    ->canBeDisabled()
×
UNCOV
290
                                ->end()
×
UNCOV
291
                            ->end()
×
UNCOV
292
                        ->end()
×
UNCOV
293
                    ->end()
×
UNCOV
294
                ->end()
×
UNCOV
295
            ->end();
×
296
    }
297

298
    private function addSwaggerSection(ArrayNodeDefinition $rootNode): void
299
    {
UNCOV
300
        $supportedVersions = [3];
×
301

UNCOV
302
        $rootNode
×
UNCOV
303
            ->children()
×
UNCOV
304
                ->arrayNode('swagger')
×
UNCOV
305
                    ->addDefaultsIfNotSet()
×
UNCOV
306
                    ->children()
×
UNCOV
307
                        ->booleanNode('persist_authorization')->defaultValue(false)->info('Persist the SwaggerUI Authorization in the localStorage.')->end()
×
UNCOV
308
                        ->arrayNode('versions')
×
UNCOV
309
                            ->info('The active versions of OpenAPI to be exported or used in Swagger UI. The first value is the default.')
×
UNCOV
310
                            ->defaultValue($supportedVersions)
×
UNCOV
311
                            ->beforeNormalization()
×
UNCOV
312
                                ->always(static function ($v): array {
×
UNCOV
313
                                    if (!\is_array($v)) {
×
314
                                        $v = [$v];
×
315
                                    }
316

UNCOV
317
                                    foreach ($v as &$version) {
×
UNCOV
318
                                        $version = (int) $version;
×
319
                                    }
320

UNCOV
321
                                    return $v;
×
UNCOV
322
                                })
×
UNCOV
323
                            ->end()
×
UNCOV
324
                            ->validate()
×
UNCOV
325
                                ->ifTrue(static fn ($v): bool => $v !== array_intersect($v, $supportedVersions))
×
UNCOV
326
                                ->thenInvalid(sprintf('Only the versions %s are supported. Got %s.', implode(' and ', $supportedVersions), '%s'))
×
UNCOV
327
                            ->end()
×
UNCOV
328
                            ->prototype('scalar')->end()
×
UNCOV
329
                        ->end()
×
UNCOV
330
                        ->arrayNode('api_keys')
×
UNCOV
331
                            ->useAttributeAsKey('key')
×
UNCOV
332
                            ->validate()
×
UNCOV
333
                                ->ifTrue(static fn ($v): bool => (bool) array_filter(array_keys($v), fn ($item) => !preg_match('/^[a-zA-Z0-9._-]+$/', $item)))
×
UNCOV
334
                                ->thenInvalid('The api keys "key" is not valid according to the pattern enforced by OpenAPI 3.1 ^[a-zA-Z0-9._-]+$.')
×
UNCOV
335
                            ->end()
×
UNCOV
336
                            ->prototype('array')
×
UNCOV
337
                                ->children()
×
UNCOV
338
                                    ->scalarNode('name')
×
UNCOV
339
                                        ->info('The name of the header or query parameter containing the api key.')
×
UNCOV
340
                                    ->end()
×
UNCOV
341
                                    ->enumNode('type')
×
UNCOV
342
                                        ->info('Whether the api key should be a query parameter or a header.')
×
UNCOV
343
                                        ->values(['query', 'header'])
×
UNCOV
344
                                    ->end()
×
UNCOV
345
                                ->end()
×
UNCOV
346
                            ->end()
×
UNCOV
347
                        ->end()
×
UNCOV
348
                        ->arrayNode('http_auth')
×
UNCOV
349
                            ->info('Creates http security schemes for OpenAPI.')
×
UNCOV
350
                            ->useAttributeAsKey('key')
×
UNCOV
351
                            ->validate()
×
UNCOV
352
                                ->ifTrue(static fn ($v): bool => (bool) array_filter(array_keys($v), fn ($item) => !preg_match('/^[a-zA-Z0-9._-]+$/', $item)))
×
UNCOV
353
                                ->thenInvalid('The api keys "key" is not valid according to the pattern enforced by OpenAPI 3.1 ^[a-zA-Z0-9._-]+$.')
×
UNCOV
354
                            ->end()
×
UNCOV
355
                            ->prototype('array')
×
UNCOV
356
                                ->children()
×
UNCOV
357
                                    ->scalarNode('scheme')
×
UNCOV
358
                                        ->info('The OpenAPI HTTP auth scheme, for example "bearer"')
×
UNCOV
359
                                    ->end()
×
UNCOV
360
                                    ->scalarNode('bearerFormat')
×
UNCOV
361
                                        ->info('The OpenAPI HTTP bearer format')
×
UNCOV
362
                                    ->end()
×
UNCOV
363
                                ->end()
×
UNCOV
364
                            ->end()
×
UNCOV
365
                        ->end()
×
UNCOV
366
                        ->variableNode('swagger_ui_extra_configuration')
×
UNCOV
367
                            ->defaultValue([])
×
UNCOV
368
                            ->validate()
×
UNCOV
369
                                ->ifTrue(static fn ($v): bool => false === \is_array($v))
×
UNCOV
370
                                ->thenInvalid('The swagger_ui_extra_configuration parameter must be an array.')
×
UNCOV
371
                            ->end()
×
UNCOV
372
                            ->info('To pass extra configuration to Swagger UI, like docExpansion or filter.')
×
UNCOV
373
                        ->end()
×
UNCOV
374
                    ->end()
×
UNCOV
375
                ->end()
×
UNCOV
376
            ->end();
×
377
    }
378

379
    private function addHttpCacheSection(ArrayNodeDefinition $rootNode): void
380
    {
UNCOV
381
        $rootNode
×
UNCOV
382
            ->children()
×
UNCOV
383
                ->arrayNode('http_cache')
×
UNCOV
384
                    ->addDefaultsIfNotSet()
×
UNCOV
385
                    ->children()
×
UNCOV
386
                        ->booleanNode('public')->defaultNull()->info('To make all responses public by default.')->end()
×
UNCOV
387
                        ->arrayNode('invalidation')
×
UNCOV
388
                            ->info('Enable the tags-based cache invalidation system.')
×
UNCOV
389
                            ->canBeEnabled()
×
UNCOV
390
                            ->children()
×
UNCOV
391
                                ->arrayNode('varnish_urls')
×
UNCOV
392
                                    ->setDeprecated('api-platform/core', '3.0', 'The "varnish_urls" configuration is deprecated, use "urls" or "scoped_clients".')
×
UNCOV
393
                                    ->defaultValue([])
×
UNCOV
394
                                    ->prototype('scalar')->end()
×
UNCOV
395
                                    ->info('URLs of the Varnish servers to purge using cache tags when a resource is updated.')
×
UNCOV
396
                                ->end()
×
UNCOV
397
                                ->arrayNode('urls')
×
UNCOV
398
                                    ->defaultValue([])
×
UNCOV
399
                                    ->prototype('scalar')->end()
×
UNCOV
400
                                    ->info('URLs of the Varnish servers to purge using cache tags when a resource is updated.')
×
UNCOV
401
                                ->end()
×
UNCOV
402
                                ->arrayNode('scoped_clients')
×
UNCOV
403
                                    ->defaultValue([])
×
UNCOV
404
                                    ->prototype('scalar')->end()
×
UNCOV
405
                                    ->info('Service names of scoped client to use by the cache purger.')
×
UNCOV
406
                                ->end()
×
UNCOV
407
                                ->integerNode('max_header_length')
×
UNCOV
408
                                    ->defaultValue(7500)
×
UNCOV
409
                                    ->info('Max header length supported by the cache server.')
×
UNCOV
410
                                ->end()
×
UNCOV
411
                                ->variableNode('request_options')
×
UNCOV
412
                                    ->defaultValue([])
×
UNCOV
413
                                    ->validate()
×
UNCOV
414
                                        ->ifTrue(static fn ($v): bool => false === \is_array($v))
×
UNCOV
415
                                        ->thenInvalid('The request_options parameter must be an array.')
×
UNCOV
416
                                    ->end()
×
UNCOV
417
                                    ->info('To pass options to the client charged with the request.')
×
UNCOV
418
                                ->end()
×
UNCOV
419
                                ->scalarNode('purger')
×
UNCOV
420
                                    ->defaultValue('api_platform.http_cache.purger.varnish')
×
UNCOV
421
                                    ->info('Specify a purger to use (available values: "api_platform.http_cache.purger.varnish.ban", "api_platform.http_cache.purger.varnish.xkey", "api_platform.http_cache.purger.souin").')
×
UNCOV
422
                                ->end()
×
UNCOV
423
                                ->arrayNode('xkey')
×
UNCOV
424
                                    ->setDeprecated('api-platform/core', '3.0', 'The "xkey" configuration is deprecated, use your own purger to customize surrogate keys or the appropriate paramters.')
×
UNCOV
425
                                    ->addDefaultsIfNotSet()
×
UNCOV
426
                                    ->children()
×
UNCOV
427
                                        ->scalarNode('glue')
×
UNCOV
428
                                        ->defaultValue(' ')
×
UNCOV
429
                                        ->info('xkey glue between keys')
×
UNCOV
430
                                        ->end()
×
UNCOV
431
                                    ->end()
×
UNCOV
432
                                ->end()
×
UNCOV
433
                            ->end()
×
UNCOV
434
                        ->end()
×
UNCOV
435
                    ->end()
×
UNCOV
436
                ->end()
×
UNCOV
437
            ->end();
×
438
    }
439

440
    private function addMercureSection(ArrayNodeDefinition $rootNode): void
441
    {
UNCOV
442
        $rootNode
×
UNCOV
443
            ->children()
×
UNCOV
444
                ->arrayNode('mercure')
×
UNCOV
445
                    ->{class_exists(MercureBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
UNCOV
446
                    ->children()
×
UNCOV
447
                        ->scalarNode('hub_url')
×
UNCOV
448
                            ->defaultNull()
×
UNCOV
449
                            ->info('The URL sent in the Link HTTP header. If not set, will default to the URL for MercureBundle\'s default hub.')
×
UNCOV
450
                        ->end()
×
UNCOV
451
                        ->booleanNode('include_type')
×
UNCOV
452
                            ->defaultFalse()
×
UNCOV
453
                            ->info('Always include @type in updates (including delete ones).')
×
UNCOV
454
                        ->end()
×
UNCOV
455
                    ->end()
×
UNCOV
456
                ->end()
×
UNCOV
457
            ->end();
×
458
    }
459

460
    private function addMessengerSection(ArrayNodeDefinition $rootNode): void
461
    {
UNCOV
462
        $rootNode
×
UNCOV
463
            ->children()
×
UNCOV
464
                ->arrayNode('messenger')
×
UNCOV
465
                    ->{!class_exists(FullStack::class) && interface_exists(MessageBusInterface::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
UNCOV
466
                ->end()
×
UNCOV
467
            ->end();
×
468
    }
469

470
    private function addElasticsearchSection(ArrayNodeDefinition $rootNode): void
471
    {
UNCOV
472
        $rootNode
×
UNCOV
473
            ->children()
×
UNCOV
474
                ->arrayNode('elasticsearch')
×
UNCOV
475
                    ->canBeEnabled()
×
UNCOV
476
                    ->addDefaultsIfNotSet()
×
UNCOV
477
                    ->children()
×
UNCOV
478
                        ->booleanNode('enabled')
×
UNCOV
479
                            ->defaultFalse()
×
UNCOV
480
                            ->validate()
×
UNCOV
481
                                ->ifTrue()
×
UNCOV
482
                                ->then(static function (bool $v): bool {
×
483
                                    if (
484
                                        // ES v7
UNCOV
485
                                        !class_exists(\Elasticsearch\Client::class)
×
486
                                        // ES v8 and up
UNCOV
487
                                        && !class_exists(\Elastic\Elasticsearch\Client::class)
×
488
                                    ) {
489
                                        throw new InvalidConfigurationException('The elasticsearch/elasticsearch package is required for Elasticsearch support.');
×
490
                                    }
491

UNCOV
492
                                    return $v;
×
UNCOV
493
                                })
×
UNCOV
494
                            ->end()
×
UNCOV
495
                        ->end()
×
UNCOV
496
                        ->arrayNode('hosts')
×
UNCOV
497
                            ->beforeNormalization()->castToArray()->end()
×
UNCOV
498
                            ->defaultValue([])
×
UNCOV
499
                            ->prototype('scalar')->end()
×
UNCOV
500
                        ->end()
×
UNCOV
501
                    ->end()
×
UNCOV
502
                ->end()
×
UNCOV
503
            ->end();
×
504
    }
505

506
    private function addOpenApiSection(ArrayNodeDefinition $rootNode): void
507
    {
UNCOV
508
        $rootNode
×
UNCOV
509
            ->children()
×
UNCOV
510
                ->arrayNode('openapi')
×
UNCOV
511
                    ->addDefaultsIfNotSet()
×
UNCOV
512
                        ->children()
×
UNCOV
513
                        ->arrayNode('contact')
×
UNCOV
514
                        ->addDefaultsIfNotSet()
×
UNCOV
515
                            ->children()
×
UNCOV
516
                                ->scalarNode('name')->defaultNull()->info('The identifying name of the contact person/organization.')->end()
×
UNCOV
517
                                ->scalarNode('url')->defaultNull()->info('The URL pointing to the contact information. MUST be in the format of a URL.')->end()
×
UNCOV
518
                                ->scalarNode('email')->defaultNull()->info('The email address of the contact person/organization. MUST be in the format of an email address.')->end()
×
UNCOV
519
                            ->end()
×
UNCOV
520
                        ->end()
×
UNCOV
521
                        ->scalarNode('termsOfService')->defaultNull()->info('A URL to the Terms of Service for the API. MUST be in the format of a URL.')->end()
×
UNCOV
522
                        ->arrayNode('tags')
×
UNCOV
523
                            ->info('Global OpenApi tags overriding the default computed tags if specified.')
×
UNCOV
524
                            ->prototype('array')
×
UNCOV
525
                                ->children()
×
UNCOV
526
                                    ->scalarNode('name')->isRequired()->end()
×
UNCOV
527
                                    ->scalarNode('description')->defaultNull()->end()
×
UNCOV
528
                                ->end()
×
UNCOV
529
                            ->end()
×
UNCOV
530
                        ->end()
×
UNCOV
531
                        ->arrayNode('license')
×
UNCOV
532
                        ->addDefaultsIfNotSet()
×
UNCOV
533
                            ->children()
×
UNCOV
534
                                ->scalarNode('name')->defaultNull()->info('The license name used for the API.')->end()
×
UNCOV
535
                                ->scalarNode('url')->defaultNull()->info('URL to the license used for the API. MUST be in the format of a URL.')->end()
×
UNCOV
536
                                ->scalarNode('identifier')->defaultNull()->info('An SPDX license expression for the API. The identifier field is mutually exclusive of the url field.')->end()
×
UNCOV
537
                            ->end()
×
UNCOV
538
                        ->end()
×
UNCOV
539
                        ->variableNode('swagger_ui_extra_configuration')
×
UNCOV
540
                            ->defaultValue([])
×
UNCOV
541
                            ->validate()
×
UNCOV
542
                                ->ifTrue(static fn ($v): bool => false === \is_array($v))
×
UNCOV
543
                                ->thenInvalid('The swagger_ui_extra_configuration parameter must be an array.')
×
UNCOV
544
                            ->end()
×
UNCOV
545
                            ->info('To pass extra configuration to Swagger UI, like docExpansion or filter.')
×
UNCOV
546
                        ->end()
×
UNCOV
547
                        ->booleanNode('overrideResponses')->defaultTrue()->info('Whether API Platform adds automatic responses to the OpenAPI documentation.')->end()
×
UNCOV
548
                        ->scalarNode('error_resource_class')->defaultNull()->info('The class used to represent errors in the OpenAPI documentation.')->end()
×
UNCOV
549
                        ->scalarNode('validation_error_resource_class')->defaultNull()->info('The class used to represent validation errors in the OpenAPI documentation.')->end()
×
UNCOV
550
                    ->end()
×
UNCOV
551
                ->end()
×
UNCOV
552
            ->end();
×
553
    }
554

555
    /**
556
     * @throws InvalidConfigurationException
557
     */
558
    private function addExceptionToStatusSection(ArrayNodeDefinition $rootNode): void
559
    {
UNCOV
560
        $rootNode
×
UNCOV
561
            ->children()
×
UNCOV
562
                ->arrayNode('exception_to_status')
×
UNCOV
563
                    ->defaultValue([
×
UNCOV
564
                        SerializerExceptionInterface::class => Response::HTTP_BAD_REQUEST,
×
UNCOV
565
                        InvalidArgumentException::class => Response::HTTP_BAD_REQUEST,
×
UNCOV
566
                        OptimisticLockException::class => Response::HTTP_CONFLICT,
×
UNCOV
567
                    ])
×
UNCOV
568
                    ->info('The list of exceptions mapped to their HTTP status code.')
×
UNCOV
569
                    ->normalizeKeys(false)
×
UNCOV
570
                    ->useAttributeAsKey('exception_class')
×
UNCOV
571
                    ->prototype('integer')->end()
×
UNCOV
572
                    ->validate()
×
UNCOV
573
                        ->ifArray()
×
UNCOV
574
                        ->then(static function (array $exceptionToStatus): array {
×
UNCOV
575
                            foreach ($exceptionToStatus as $httpStatusCode) {
×
UNCOV
576
                                if ($httpStatusCode < 100 || $httpStatusCode >= 600) {
×
UNCOV
577
                                    throw new InvalidConfigurationException(sprintf('The HTTP status code "%s" is not valid.', $httpStatusCode));
×
578
                                }
579
                            }
580

UNCOV
581
                            return $exceptionToStatus;
×
UNCOV
582
                        })
×
UNCOV
583
                    ->end()
×
UNCOV
584
                ->end()
×
UNCOV
585
            ->end();
×
586
    }
587

588
    private function addFormatSection(ArrayNodeDefinition $rootNode, string $key, array $defaultValue): void
589
    {
UNCOV
590
        $rootNode
×
UNCOV
591
            ->children()
×
UNCOV
592
                ->arrayNode($key)
×
UNCOV
593
                    ->defaultValue($defaultValue)
×
UNCOV
594
                    ->info('The list of enabled formats. The first one will be the default.')
×
UNCOV
595
                    ->normalizeKeys(false)
×
UNCOV
596
                    ->useAttributeAsKey('format')
×
UNCOV
597
                    ->beforeNormalization()
×
UNCOV
598
                        ->ifArray()
×
UNCOV
599
                        ->then(static function ($v) {
×
UNCOV
600
                            foreach ($v as $format => $value) {
×
UNCOV
601
                                if (isset($value['mime_types'])) {
×
602
                                    continue;
×
603
                                }
604

UNCOV
605
                                $v[$format] = ['mime_types' => $value];
×
606
                            }
607

UNCOV
608
                            return $v;
×
UNCOV
609
                        })
×
UNCOV
610
                    ->end()
×
UNCOV
611
                    ->prototype('array')
×
UNCOV
612
                        ->children()
×
UNCOV
613
                            ->arrayNode('mime_types')->prototype('scalar')->end()->end()
×
UNCOV
614
                        ->end()
×
UNCOV
615
                    ->end()
×
UNCOV
616
                ->end()
×
UNCOV
617
            ->end();
×
618
    }
619

620
    private function addDefaultsSection(ArrayNodeDefinition $rootNode): void
621
    {
UNCOV
622
        $nameConverter = new CamelCaseToSnakeCaseNameConverter();
×
UNCOV
623
        $defaultsNode = $rootNode->children()->arrayNode('defaults');
×
624

UNCOV
625
        $defaultsNode
×
UNCOV
626
            ->ignoreExtraKeys(false)
×
UNCOV
627
            ->beforeNormalization()
×
UNCOV
628
            ->always(static function (array $defaults) use ($nameConverter): array {
×
UNCOV
629
                $normalizedDefaults = [];
×
UNCOV
630
                foreach ($defaults as $option => $value) {
×
UNCOV
631
                    $option = $nameConverter->normalize($option);
×
UNCOV
632
                    $normalizedDefaults[$option] = $value;
×
633
                }
634

UNCOV
635
                return $normalizedDefaults;
×
UNCOV
636
            });
×
637

UNCOV
638
        $this->defineDefault($defaultsNode, new \ReflectionClass(ApiResource::class), $nameConverter);
×
UNCOV
639
        $this->defineDefault($defaultsNode, new \ReflectionClass(Put::class), $nameConverter);
×
UNCOV
640
        $this->defineDefault($defaultsNode, new \ReflectionClass(Post::class), $nameConverter);
×
641
    }
642

643
    private function addMakerSection(ArrayNodeDefinition $rootNode): void
644
    {
UNCOV
645
        $rootNode
×
UNCOV
646
            ->children()
×
UNCOV
647
                ->arrayNode('maker')
×
UNCOV
648
                    ->{class_exists(MakerBundle::class) ? 'canBeDisabled' : 'canBeEnabled'}()
×
UNCOV
649
                ->end()
×
UNCOV
650
            ->end();
×
651
    }
652

653
    private function defineDefault(ArrayNodeDefinition $defaultsNode, \ReflectionClass $reflectionClass, CamelCaseToSnakeCaseNameConverter $nameConverter): void
654
    {
UNCOV
655
        foreach ($reflectionClass->getConstructor()->getParameters() as $parameter) {
×
UNCOV
656
            $defaultsNode->children()->variableNode($nameConverter->normalize($parameter->getName()));
×
657
        }
658
    }
659
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc