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

api-platform / core / 18118486316

30 Sep 2025 04:11AM UTC coverage: 0.0% (-22.0%) from 21.956%
18118486316

Pull #7397

github

web-flow
Merge e92aeff57 into 55fd65795
Pull Request #7397: fix(jsonschema/jsonld): make `@id` and `@type` properties required only in the JSON-LD schema for output

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

12143 existing lines in 402 files now uncovered.

0 of 53916 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
            'jsonStream' => $this->phpize($resource, 'jsonStream', 'bool'),
×
UNCOV
175
        ];
×
176
    }
177

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

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

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

UNCOV
219
        return $uriVariables;
×
220
    }
221

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
354
        return $data;
×
355
    }
356

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

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

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

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

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

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

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

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

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

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

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

439
        return null;
×
440
    }
441

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

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

456
        return $links;
×
457
    }
458

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

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

473
        return $headers;
×
474
    }
475

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

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

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