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

api-platform / core / 16705318661

03 Aug 2025 01:05PM UTC coverage: 0.0% (-21.9%) from 21.944%
16705318661

Pull #7317

github

web-flow
Merge 1ca8642ff into d06b1a0a0
Pull Request #7317: Fix/4372 skip null values in hal

0 of 14 new or added lines in 3 files covered. (0.0%)

11680 existing lines in 376 files now uncovered.

0 of 51817 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/Metadata/Extractor/YamlResourceExtractor.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\Metadata\Extractor;
15

16
use ApiPlatform\Doctrine\Odm\State\Options as OdmOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options as OrmOptions;
18
use ApiPlatform\Elasticsearch\State\Options as ElasticsearchOptions;
19
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
20
use ApiPlatform\Metadata\GetCollection;
21
use ApiPlatform\Metadata\HeaderParameter;
22
use ApiPlatform\Metadata\Post;
23
use ApiPlatform\Metadata\QueryParameter;
24
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
25
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
26
use ApiPlatform\OpenApi\Model\Parameter;
27
use ApiPlatform\OpenApi\Model\RequestBody;
28
use ApiPlatform\State\OptionsInterface;
29
use Symfony\Component\WebLink\Link;
30
use Symfony\Component\Yaml\Exception\ParseException;
31
use Symfony\Component\Yaml\Yaml;
32

33
/**
34
 * Extracts an array of metadata from a list of YAML files.
35
 *
36
 * @author Antoine Bluchet <soyuka@gmail.com>
37
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
38
 * @author Kévin Dunglas <dunglas@gmail.com>
39
 * @author Vincent Chalamon <vincentchalamon@gmail.com>
40
 */
41
final class YamlResourceExtractor extends AbstractResourceExtractor
42
{
43
    use ResourceExtractorTrait;
44

45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function extractPath(string $path): void
49
    {
50
        try {
UNCOV
51
            $resourcesYaml = Yaml::parse((string) file_get_contents($path), Yaml::PARSE_CONSTANT);
×
52
        } catch (ParseException $e) {
×
53
            $e->setParsedFile($path);
×
54

55
            throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
×
56
        }
57

UNCOV
58
        if (null === $resourcesYaml = $resourcesYaml['resources'] ?? $resourcesYaml) {
×
59
            return;
×
60
        }
61

UNCOV
62
        if (!\is_array($resourcesYaml)) {
×
63
            throw new InvalidArgumentException(\sprintf('"resources" setting is expected to be null or an array, %s given in "%s".', \gettype($resourcesYaml), $path));
×
64
        }
65

UNCOV
66
        $this->buildResources($resourcesYaml, $path);
×
67
    }
68

69
    private function buildResources(array $resourcesYaml, string $path): void
70
    {
UNCOV
71
        foreach ($resourcesYaml as $resourceName => $resourceYaml) {
×
UNCOV
72
            $resourceName = $this->resolve($resourceName);
×
73

UNCOV
74
            if (null === $resourceYaml) {
×
UNCOV
75
                $resourceYaml = [[]];
×
76
            }
77

UNCOV
78
            if (!\array_key_exists(0, $resourceYaml)) {
×
UNCOV
79
                $resourceYaml = [$resourceYaml];
×
80
            }
81

UNCOV
82
            foreach ($resourceYaml as $key => $resourceYamlDatum) {
×
UNCOV
83
                if (null === $resourceYamlDatum) {
×
UNCOV
84
                    $resourceYamlDatum = [];
×
85
                }
86

87
                try {
UNCOV
88
                    $base = $this->buildExtendedBase($resourceYamlDatum);
×
UNCOV
89
                    $this->resources[$resourceName][$key] = array_merge($base, [
×
UNCOV
90
                        'operations' => $this->buildOperations($resourceYamlDatum, $base),
×
UNCOV
91
                        'graphQlOperations' => $this->buildGraphQlOperations($resourceYamlDatum, $base),
×
UNCOV
92
                    ]);
×
93
                } catch (InvalidArgumentException $exception) {
×
94
                    throw new InvalidArgumentException(\sprintf('%s in "%s" (%s).', $exception->getMessage(), $resourceName, $path));
×
95
                }
96
            }
97
        }
98
    }
99

100
    private function buildExtendedBase(array $resource): array
101
    {
UNCOV
102
        return array_merge($this->buildBase($resource), [
×
UNCOV
103
            'uriTemplate' => $this->phpize($resource, 'uriTemplate', 'string'),
×
UNCOV
104
            'routePrefix' => $this->phpize($resource, 'routePrefix', 'string'),
×
UNCOV
105
            'stateless' => $this->phpize($resource, 'stateless', 'bool'),
×
UNCOV
106
            'sunset' => $this->phpize($resource, 'sunset', 'string'),
×
UNCOV
107
            'acceptPatch' => $this->phpize($resource, 'acceptPatch', 'string'),
×
UNCOV
108
            'host' => $this->phpize($resource, 'host', 'string'),
×
UNCOV
109
            'condition' => $this->phpize($resource, 'condition', 'string'),
×
UNCOV
110
            'controller' => $this->phpize($resource, 'controller', 'string'),
×
UNCOV
111
            'queryParameterValidationEnabled' => $this->phpize($resource, 'queryParameterValidationEnabled', 'bool'),
×
UNCOV
112
            'types' => $this->buildArrayValue($resource, 'types'),
×
UNCOV
113
            'cacheHeaders' => $this->buildArrayValue($resource, 'cacheHeaders'),
×
UNCOV
114
            'hydraContext' => $this->buildArrayValue($resource, 'hydraContext'),
×
UNCOV
115
            'openapi' => $this->buildOpenapi($resource),
×
UNCOV
116
            'paginationViaCursor' => $this->buildArrayValue($resource, 'paginationViaCursor'),
×
UNCOV
117
            'exceptionToStatus' => $this->buildArrayValue($resource, 'exceptionToStatus'),
×
UNCOV
118
            'defaults' => $this->buildArrayValue($resource, 'defaults'),
×
UNCOV
119
            'requirements' => $this->buildArrayValue($resource, 'requirements'),
×
UNCOV
120
            'options' => $this->buildArrayValue($resource, 'options'),
×
UNCOV
121
            'status' => $this->phpize($resource, 'status', 'integer'),
×
UNCOV
122
            'schemes' => $this->buildArrayValue($resource, 'schemes'),
×
UNCOV
123
            'formats' => $this->buildArrayValue($resource, 'formats'),
×
UNCOV
124
            'uriVariables' => $this->buildUriVariables($resource),
×
UNCOV
125
            'inputFormats' => $this->buildArrayValue($resource, 'inputFormats'),
×
UNCOV
126
            'outputFormats' => $this->buildArrayValue($resource, 'outputFormats'),
×
UNCOV
127
            'stateOptions' => $this->buildStateOptions($resource),
×
UNCOV
128
            'links' => $this->buildLinks($resource),
×
UNCOV
129
            'headers' => $this->buildHeaders($resource),
×
UNCOV
130
            'parameters' => $this->buildParameters($resource),
×
UNCOV
131
        ]);
×
132
    }
133

134
    private function buildBase(array $resource): array
135
    {
UNCOV
136
        return [
×
UNCOV
137
            'shortName' => $this->phpize($resource, 'shortName', 'string'),
×
UNCOV
138
            'description' => $this->phpize($resource, 'description', 'string'),
×
UNCOV
139
            'urlGenerationStrategy' => $this->phpize($resource, 'urlGenerationStrategy', 'integer'),
×
UNCOV
140
            'deprecationReason' => $this->phpize($resource, 'deprecationReason', 'string'),
×
UNCOV
141
            'fetchPartial' => $this->phpize($resource, 'fetchPartial', 'bool'),
×
UNCOV
142
            'forceEager' => $this->phpize($resource, 'forceEager', 'bool'),
×
UNCOV
143
            'paginationClientEnabled' => $this->phpize($resource, 'paginationClientEnabled', 'bool'),
×
UNCOV
144
            'paginationClientItemsPerPage' => $this->phpize($resource, 'paginationClientItemsPerPage', 'bool'),
×
UNCOV
145
            'paginationClientPartial' => $this->phpize($resource, 'paginationClientPartial', 'bool'),
×
UNCOV
146
            'paginationEnabled' => $this->phpize($resource, 'paginationEnabled', 'bool'),
×
UNCOV
147
            'paginationFetchJoinCollection' => $this->phpize($resource, 'paginationFetchJoinCollection', 'bool'),
×
UNCOV
148
            'paginationUseOutputWalkers' => $this->phpize($resource, 'paginationUseOutputWalkers', 'bool'),
×
UNCOV
149
            'paginationItemsPerPage' => $this->phpize($resource, 'paginationItemsPerPage', 'integer'),
×
UNCOV
150
            'paginationMaximumItemsPerPage' => $this->phpize($resource, 'paginationMaximumItemsPerPage', 'integer'),
×
UNCOV
151
            'paginationPartial' => $this->phpize($resource, 'paginationPartial', 'bool'),
×
UNCOV
152
            'paginationType' => $this->phpize($resource, 'paginationType', 'string'),
×
UNCOV
153
            'processor' => $this->phpize($resource, 'processor', 'string'),
×
UNCOV
154
            'provider' => $this->phpize($resource, 'provider', 'string'),
×
UNCOV
155
            'security' => $this->phpize($resource, 'security', 'string'),
×
UNCOV
156
            'securityMessage' => $this->phpize($resource, 'securityMessage', 'string'),
×
UNCOV
157
            'securityPostDenormalize' => $this->phpize($resource, 'securityPostDenormalize', 'string'),
×
UNCOV
158
            'securityPostDenormalizeMessage' => $this->phpize($resource, 'securityPostDenormalizeMessage', 'string'),
×
UNCOV
159
            'securityPostValidation' => $this->phpize($resource, 'securityPostValidation', 'string'),
×
UNCOV
160
            'securityPostValidationMessage' => $this->phpize($resource, 'securityPostValidationMessage', 'string'),
×
UNCOV
161
            'input' => $this->phpize($resource, 'input', 'bool|string'),
×
UNCOV
162
            'output' => $this->phpize($resource, 'output', 'bool|string'),
×
UNCOV
163
            'normalizationContext' => $this->buildArrayValue($resource, 'normalizationContext'),
×
UNCOV
164
            'denormalizationContext' => $this->buildArrayValue($resource, 'denormalizationContext'),
×
UNCOV
165
            'collectDenormalizationErrors' => $this->phpize($resource, 'collectDenormalizationErrors', 'bool'),
×
UNCOV
166
            'validationContext' => $this->buildArrayValue($resource, 'validationContext'),
×
UNCOV
167
            'filters' => $this->buildArrayValue($resource, 'filters'),
×
UNCOV
168
            'order' => $this->buildArrayValue($resource, 'order'),
×
UNCOV
169
            'extraProperties' => $this->buildArrayValue($resource, 'extraProperties'),
×
UNCOV
170
            'mercure' => $this->buildMercure($resource),
×
UNCOV
171
            'messenger' => $this->buildMessenger($resource),
×
UNCOV
172
            'read' => $this->phpize($resource, 'read', 'bool'),
×
UNCOV
173
            'write' => $this->phpize($resource, 'write', 'bool'),
×
UNCOV
174
        ];
×
175
    }
176

177
    private function buildUriVariables(array $resource): ?array
178
    {
UNCOV
179
        if (!\array_key_exists('uriVariables', $resource)) {
×
UNCOV
180
            return null;
×
181
        }
182

UNCOV
183
        $uriVariables = [];
×
UNCOV
184
        foreach ($resource['uriVariables'] as $parameterName => $data) {
×
UNCOV
185
            if (\is_string($data)) {
×
186
                $uriVariables[$data] = $data;
×
187
                continue;
×
188
            }
189

UNCOV
190
            if (2 === (is_countable($data) ? \count($data) : 0) && isset($data[0]) && isset($data[1])) {
×
UNCOV
191
                $data['fromClass'] = $data[0];
×
UNCOV
192
                $data['fromProperty'] = $data[1];
×
UNCOV
193
                unset($data[0], $data[1]);
×
194
            }
UNCOV
195
            if (isset($data['fromClass'])) {
×
UNCOV
196
                $uriVariables[$parameterName]['from_class'] = $this->resolve($data['fromClass']);
×
197
            }
UNCOV
198
            if (isset($data['fromProperty'])) {
×
UNCOV
199
                $uriVariables[$parameterName]['from_property'] = $data['fromProperty'];
×
200
            }
UNCOV
201
            if (isset($data['toClass'])) {
×
202
                $uriVariables[$parameterName]['to_class'] = $this->resolve($data['toClass']);
×
203
            }
UNCOV
204
            if (isset($data['toProperty'])) {
×
UNCOV
205
                $uriVariables[$parameterName]['to_property'] = $data['toProperty'];
×
206
            }
UNCOV
207
            if (isset($data['identifiers'])) {
×
208
                $uriVariables[$parameterName]['identifiers'] = $data['identifiers'];
×
209
            }
UNCOV
210
            if (isset($data['compositeIdentifier'])) {
×
211
                $uriVariables[$parameterName]['composite_identifier'] = $data['compositeIdentifier'];
×
212
            }
UNCOV
213
            if (isset($data['security'])) {
×
214
                $uriVariables[$parameterName]['security'] = $data['security'];
×
215
            }
216
        }
217

UNCOV
218
        return $uriVariables;
×
219
    }
220

221
    private function buildOpenapi(array $resource): bool|OpenApiOperation|null
222
    {
UNCOV
223
        if (!\array_key_exists('openapi', $resource)) {
×
UNCOV
224
            return null;
×
225
        }
226

UNCOV
227
        if (!\is_array($resource['openapi'])) {
×
228
            return $this->phpize($resource, 'openapi', 'bool');
×
229
        }
230

UNCOV
231
        $allowedProperties = array_map(fn (\ReflectionProperty $reflProperty): string => $reflProperty->getName(), (new \ReflectionClass(OpenApiOperation::class))->getProperties());
×
UNCOV
232
        foreach ($resource['openapi'] as $key => $value) {
×
UNCOV
233
            $resource['openapi'][$key] = match ($key) {
×
234
                'externalDocs' => new ExternalDocumentation(description: $value['description'] ?? '', url: $value['url'] ?? ''),
×
235
                'requestBody' => new RequestBody(description: $value['description'] ?? '', content: isset($value['content']) ? new \ArrayObject($value['content'] ?? []) : null, required: $value['required'] ?? false),
×
236
                'callbacks' => new \ArrayObject($value ?? []),
×
UNCOV
237
                default => $value,
×
UNCOV
238
            };
×
239

UNCOV
240
            if (\in_array($key, $allowedProperties, true)) {
×
241
                continue;
×
242
            }
243

UNCOV
244
            $resource['openapi']['extensionProperties'][$key] = $value;
×
UNCOV
245
            unset($resource['openapi'][$key]);
×
246
        }
247

UNCOV
248
        if (\array_key_exists('parameters', $resource['openapi']) && \is_array($openapiParameters = $resource['openapi']['parameters'] ?? [])) {
×
249
            $parameters = [];
×
250
            foreach ($openapiParameters as $parameter) {
×
251
                $parameters[] = new Parameter(
×
252
                    name: $parameter['name'],
×
253
                    in: $parameter['in'],
×
254
                    description: $parameter['description'] ?? '',
×
255
                    required: $parameter['required'] ?? false,
×
256
                    deprecated: $parameter['deprecated'] ?? false,
×
257
                    allowEmptyValue: $parameter['allowEmptyValue'] ?? false,
×
258
                    schema: $parameter['schema'] ?? [],
×
259
                    style: $parameter['style'] ?? null,
×
260
                    explode: $parameter['explode'] ?? false,
×
261
                    allowReserved: $parameter['allowReserved '] ?? false,
×
262
                    example: $parameter['example'] ?? null,
×
263
                    examples: isset($parameter['examples']) ? new \ArrayObject($parameter['examples']) : null,
×
264
                    content: isset($parameter['content']) ? new \ArrayObject($parameter['content']) : null
×
265
                );
×
266
            }
267
            $resource['openapi']['parameters'] = $parameters;
×
268
        }
269

UNCOV
270
        return new OpenApiOperation(...$resource['openapi']);
×
271
    }
272

273
    /**
274
     * @return bool|string|string[]|null
275
     */
276
    private function buildMercure(array $resource): array|bool|string|null
277
    {
UNCOV
278
        if (!\array_key_exists('mercure', $resource)) {
×
UNCOV
279
            return null;
×
280
        }
281

282
        if (\is_string($resource['mercure'])) {
×
283
            return $this->phpize($resource, 'mercure', 'bool|string');
×
284
        }
285

286
        return $resource['mercure'];
×
287
    }
288

289
    private function buildMessenger(array $resource): bool|array|string|null
290
    {
UNCOV
291
        if (!\array_key_exists('messenger', $resource)) {
×
UNCOV
292
            return null;
×
293
        }
294

295
        return $this->phpize($resource, 'messenger', 'bool|string');
×
296
    }
297

298
    private function buildOperations(array $resource, array $root): ?array
299
    {
UNCOV
300
        if (!\array_key_exists('operations', $resource)) {
×
UNCOV
301
            return null;
×
302
        }
303

UNCOV
304
        $data = [];
×
UNCOV
305
        foreach ($resource['operations'] as $class => $operation) {
×
UNCOV
306
            if (null === $operation) {
×
UNCOV
307
                $operation = [];
×
308
            }
309

UNCOV
310
            if (\array_key_exists('class', $operation)) {
×
311
                if (!\array_key_exists('name', $operation) && \is_string($class)) {
×
312
                    $operation['name'] = $class;
×
313
                }
314
                $class = $operation['class'];
×
315
            }
316

UNCOV
317
            if (empty($class)) {
×
318
                throw new InvalidArgumentException('Missing "class" attribute');
×
319
            }
320

UNCOV
321
            if (!class_exists($class)) {
×
322
                throw new InvalidArgumentException(\sprintf('Operation class "%s" does not exist', $class));
×
323
            }
324

UNCOV
325
            $datum = $this->buildExtendedBase($operation);
×
UNCOV
326
            foreach ($datum as $key => $value) {
×
UNCOV
327
                if (null === $value) {
×
UNCOV
328
                    $datum[$key] = $root[$key];
×
329
                }
330
            }
331

UNCOV
332
            if (\in_array((string) $class, [GetCollection::class, Post::class], true)) {
×
UNCOV
333
                $datum['itemUriTemplate'] = $this->phpize($operation, 'itemUriTemplate', 'string');
×
UNCOV
334
            } elseif (isset($operation['itemUriTemplate'])) {
×
335
                throw new InvalidArgumentException(\sprintf('"itemUriTemplate" option is not allowed on a %s operation.', $class));
×
336
            }
337

UNCOV
338
            $data[] = array_merge($datum, [
×
UNCOV
339
                'read' => $this->phpize($operation, 'read', 'bool'),
×
UNCOV
340
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
×
UNCOV
341
                'validate' => $this->phpize($operation, 'validate', 'bool'),
×
UNCOV
342
                'write' => $this->phpize($operation, 'write', 'bool'),
×
UNCOV
343
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
×
UNCOV
344
                'queryParameterValidate' => $this->phpize($operation, 'queryParameterValidate', 'bool'),
×
UNCOV
345
                'strictQueryParameterValidation' => $this->phpize($operation, 'strictQueryParameterValidation', 'bool'),
×
UNCOV
346
                'hideHydraOperation' => $this->phpize($resource, 'hideHydraOperation', 'bool'),
×
UNCOV
347
                'priority' => $this->phpize($operation, 'priority', 'integer'),
×
UNCOV
348
                'name' => $this->phpize($operation, 'name', 'string'),
×
UNCOV
349
                'class' => (string) $class,
×
UNCOV
350
            ]);
×
351
        }
352

UNCOV
353
        return $data;
×
354
    }
355

356
    private function buildGraphQlOperations(array $resource, array $root): ?array
357
    {
UNCOV
358
        if (!\array_key_exists('graphQlOperations', $resource) || !\is_array($resource['graphQlOperations'])) {
×
UNCOV
359
            return null;
×
360
        }
361

UNCOV
362
        $data = [];
×
UNCOV
363
        foreach ($resource['graphQlOperations'] as $class => $operation) {
×
364
            if (null === $operation) {
×
365
                $operation = [];
×
366
            }
367

368
            if (\array_key_exists('class', $operation)) {
×
369
                if (!\array_key_exists('name', $operation) && \is_string($class)) {
×
370
                    $operation['name'] = $class;
×
371
                }
372
                $class = $operation['class'];
×
373
            }
374

375
            if (empty($class)) {
×
376
                throw new InvalidArgumentException('Missing "class" attribute');
×
377
            }
378

379
            if (!class_exists($class)) {
×
380
                throw new InvalidArgumentException(\sprintf('Operation class "%s" does not exist', $class));
×
381
            }
382

383
            $datum = $this->buildBase($operation);
×
384
            foreach ($datum as $key => $value) {
×
385
                if (null === $value) {
×
386
                    $datum[$key] = $root[$key];
×
387
                }
388
            }
389

390
            $data[] = array_merge($datum, [
×
391
                'resolver' => $this->phpize($operation, 'resolver', 'string'),
×
392
                'args' => $operation['args'] ?? null,
×
393
                'extraArgs' => $operation['extraArgs'] ?? null,
×
394
                'class' => (string) $class,
×
395
                'read' => $this->phpize($operation, 'read', 'bool'),
×
396
                'deserialize' => $this->phpize($operation, 'deserialize', 'bool'),
×
397
                'validate' => $this->phpize($operation, 'validate', 'bool'),
×
398
                'write' => $this->phpize($operation, 'write', 'bool'),
×
399
                'serialize' => $this->phpize($operation, 'serialize', 'bool'),
×
400
                'priority' => $this->phpize($operation, 'priority', 'integer'),
×
401
                'name' => $this->phpize($operation, 'name', 'string'),
×
402
            ]);
×
403
        }
404

UNCOV
405
        return $data ?: null;
×
406
    }
407

408
    private function buildStateOptions(array $resource): ?OptionsInterface
409
    {
UNCOV
410
        $stateOptions = $resource['stateOptions'] ?? [];
×
UNCOV
411
        if (!\is_array($stateOptions)) {
×
412
            return null;
×
413
        }
414

UNCOV
415
        if (!$stateOptions) {
×
UNCOV
416
            return null;
×
417
        }
418

419
        $configuration = reset($stateOptions);
×
420
        switch (key($stateOptions)) {
×
421
            case 'elasticsearchOptions':
×
422
                if (class_exists(ElasticsearchOptions::class)) {
×
423
                    return new ElasticsearchOptions($configuration['index'] ?? null);
×
424
                }
425
                break;
×
426
            case 'doctrineOdmOptions':
×
427
                if (class_exists(OdmOptions::class)) {
×
428
                    return new OdmOptions($configuration['documentClass'] ?? null);
×
429
                }
430
                break;
×
431
            case 'doctrineOrmOptions':
×
432
                if (class_exists(OrmOptions::class)) {
×
433
                    return new OrmOptions($configuration['entityClass'] ?? null);
×
434
                }
435
                break;
×
436
        }
437

438
        return null;
×
439
    }
440

441
    /**
442
     * @return Link[]
443
     */
444
    private function buildLinks(array $resource): ?array
445
    {
UNCOV
446
        if (!isset($resource['links']) || !\is_array($resource['links'])) {
×
UNCOV
447
            return null;
×
448
        }
449

450
        $links = [];
×
451
        foreach ($resource['links'] as $link) {
×
452
            $links[] = new Link(rel: $link['rel'], href: $link['href']);
×
453
        }
454

455
        return $links;
×
456
    }
457

458
    /**
459
     * @return array<string, string>
460
     */
461
    private function buildHeaders(array $resource): ?array
462
    {
UNCOV
463
        if (!isset($resource['headers']) || !\is_array($resource['headers'])) {
×
UNCOV
464
            return null;
×
465
        }
466

467
        $headers = [];
×
468
        foreach ($resource['headers'] as $key => $value) {
×
469
            $headers[$key] = $value;
×
470
        }
471

472
        return $headers;
×
473
    }
474

475
    /**
476
     * @return array<string, \ApiPlatform\Metadata\Parameter>
477
     */
478
    private function buildParameters(array $resource): ?array
479
    {
UNCOV
480
        if (!isset($resource['parameters']) || !\is_array($resource['parameters'])) {
×
UNCOV
481
            return null;
×
482
        }
483

484
        $parameters = [];
×
485
        foreach ($resource['parameters'] as $key => $parameter) {
×
486
            $cl = ($parameter['in'] ?? 'query') === 'header' ? HeaderParameter::class : QueryParameter::class;
×
487
            $parameters[$key] = new $cl(
×
488
                key: $key,
×
489
                required: $this->phpize($parameter, 'required', 'bool'),
×
490
                schema: $parameter['schema'] ?? null,
×
491
                openApi: ($parameter['openapi'] ?? null) ? new Parameter(
×
492
                    name: $parameter['openapi']['name'],
×
493
                    in: $parameter['in'] ?? 'query',
×
494
                    description: $parameter['openapi']['description'] ?? '',
×
495
                    required: $parameter['openapi']['required'] ?? $parameter['required'] ?? false,
×
496
                    deprecated: $parameter['openapi']['deprecated'] ?? false,
×
497
                    allowEmptyValue: $parameter['openapi']['allowEmptyValue'] ?? false,
×
498
                    schema: $parameter['openapi']['schema'] ?? $parameter['schema'] ?? [],
×
499
                    style: $parameter['openapi']['style'] ?? null,
×
500
                    explode: $parameter['openapi']['explode'] ?? false,
×
501
                    allowReserved: $parameter['openapi']['allowReserved '] ?? false,
×
502
                    example: $parameter['openapi']['example'] ?? null,
×
503
                    examples: isset($parameter['openapi']['examples']) ? new \ArrayObject($parameter['openapi']['examples']) : null,
×
504
                    content: isset($parameter['openapi']['content']) ? new \ArrayObject($parameter['openapi']['content']) : null
×
505
                ) : null,
×
506
                provider: $this->phpize($parameter, 'provider', 'string'),
×
507
                filter: $this->phpize($parameter, 'filter', 'string'),
×
508
                property: $this->phpize($parameter, 'property', 'string'),
×
509
                description: $this->phpize($parameter, 'description', 'string'),
×
510
                priority: $this->phpize($parameter, 'priority', 'integer'),
×
511
                extraProperties: $this->buildArrayValue($parameter, 'extraProperties') ?? [],
×
512
            );
×
513
        }
514

515
        return $parameters;
×
516
    }
517
}
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

© 2025 Coveralls, Inc