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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

59.03
/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\Elasticsearch\State\Options;
17
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
18
use ApiPlatform\Metadata\GetCollection;
19
use ApiPlatform\Metadata\HeaderParameter;
20
use ApiPlatform\Metadata\Post;
21
use ApiPlatform\Metadata\QueryParameter;
22
use ApiPlatform\OpenApi\Model\ExternalDocumentation;
23
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
24
use ApiPlatform\OpenApi\Model\Parameter;
25
use ApiPlatform\OpenApi\Model\RequestBody;
26
use ApiPlatform\State\OptionsInterface;
27
use Symfony\Component\WebLink\Link;
28
use Symfony\Component\Yaml\Exception\ParseException;
29
use Symfony\Component\Yaml\Yaml;
30

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

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

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

UNCOV
56
        if (null === $resourcesYaml = $resourcesYaml['resources'] ?? $resourcesYaml) {
69✔
57
            return;
×
58
        }
59

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

UNCOV
64
        $this->buildResources($resourcesYaml, $path);
69✔
65
    }
66

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

UNCOV
72
            if (null === $resourceYaml) {
69✔
UNCOV
73
                $resourceYaml = [[]];
69✔
74
            }
75

UNCOV
76
            if (!\array_key_exists(0, $resourceYaml)) {
69✔
UNCOV
77
                $resourceYaml = [$resourceYaml];
69✔
78
            }
79

UNCOV
80
            foreach ($resourceYaml as $key => $resourceYamlDatum) {
69✔
UNCOV
81
                if (null === $resourceYamlDatum) {
69✔
UNCOV
82
                    $resourceYamlDatum = [];
69✔
83
                }
84

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

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

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

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

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

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

UNCOV
217
        return $uriVariables;
69✔
218
    }
219

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

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

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

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

UNCOV
243
            $resource['openapi']['extensionProperties'][$key] = $value;
69✔
UNCOV
244
            unset($resource['openapi'][$key]);
69✔
245
        }
246

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

UNCOV
269
        return new OpenApiOperation(...$resource['openapi']);
69✔
270
    }
271

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

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

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

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

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

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

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

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

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

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

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

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

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

UNCOV
352
        return $data;
69✔
353
    }
354

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

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

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

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

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

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

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

UNCOV
404
        return $data ?: null;
69✔
405
    }
406

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

UNCOV
414
        if (!$stateOptions) {
69✔
UNCOV
415
            return null;
69✔
416
        }
417

418
        $configuration = reset($stateOptions);
×
419
        switch (key($stateOptions)) {
×
420
            case 'elasticsearchOptions':
×
421
                if (class_exists(Options::class)) {
×
422
                    return new Options($configuration['index'] ?? null, $configuration['type'] ?? null);
×
423
                }
424
        }
425

426
        return null;
×
427
    }
428

429
    /**
430
     * @return Link[]
431
     */
432
    private function buildLinks(array $resource): ?array
433
    {
UNCOV
434
        if (!isset($resource['links']) || !\is_array($resource['links'])) {
69✔
UNCOV
435
            return null;
69✔
436
        }
437

438
        $links = [];
×
439
        foreach ($resource['links'] as $link) {
×
440
            $links[] = new Link(rel: $link['rel'], href: $link['href']);
×
441
        }
442

443
        return $links;
×
444
    }
445

446
    /**
447
     * @return array<string, string>
448
     */
449
    private function buildHeaders(array $resource): ?array
450
    {
UNCOV
451
        if (!isset($resource['headers']) || !\is_array($resource['headers'])) {
69✔
UNCOV
452
            return null;
69✔
453
        }
454

455
        $headers = [];
×
456
        foreach ($resource['headers'] as $key => $value) {
×
457
            $headers[$key] = $value;
×
458
        }
459

460
        return $headers;
×
461
    }
462

463
    /**
464
     * @return array<string, \ApiPlatform\Metadata\Parameter>
465
     */
466
    private function buildParameters(array $resource): ?array
467
    {
UNCOV
468
        if (!isset($resource['parameters']) || !\is_array($resource['parameters'])) {
69✔
UNCOV
469
            return null;
69✔
470
        }
471

472
        $parameters = [];
×
473
        foreach ($resource['parameters'] as $key => $parameter) {
×
474
            $cl = ($parameter['in'] ?? 'query') === 'header' ? HeaderParameter::class : QueryParameter::class;
×
475
            $parameters[$key] = new $cl(
×
476
                key: $key,
×
477
                required: $this->phpize($parameter, 'required', 'bool'),
×
478
                schema: $parameter['schema'] ?? null,
×
479
                openApi: ($parameter['openapi'] ?? null) ? new Parameter(
×
480
                    name: $parameter['openapi']['name'],
×
481
                    in: $parameter['in'] ?? 'query',
×
482
                    description: $parameter['openapi']['description'] ?? '',
×
483
                    required: $parameter['openapi']['required'] ?? $parameter['required'] ?? false,
×
484
                    deprecated: $parameter['openapi']['deprecated'] ?? false,
×
485
                    allowEmptyValue: $parameter['openapi']['allowEmptyValue'] ?? false,
×
486
                    schema: $parameter['openapi']['schema'] ?? $parameter['schema'] ?? [],
×
487
                    style: $parameter['openapi']['style'] ?? null,
×
488
                    explode: $parameter['openapi']['explode'] ?? false,
×
489
                    allowReserved: $parameter['openapi']['allowReserved '] ?? false,
×
490
                    example: $parameter['openapi']['example'] ?? null,
×
491
                    examples: isset($parameter['openapi']['examples']) ? new \ArrayObject($parameter['openapi']['examples']) : null,
×
492
                    content: isset($parameter['openapi']['content']) ? new \ArrayObject($parameter['openapi']['content']) : null
×
493
                ) : null,
×
494
                provider: $this->phpize($parameter, 'provider', 'string'),
×
495
                filter: $this->phpize($parameter, 'filter', 'string'),
×
496
                property: $this->phpize($parameter, 'property', 'string'),
×
497
                description: $this->phpize($parameter, 'description', 'string'),
×
498
                priority: $this->phpize($parameter, 'priority', 'integer'),
×
499
                extraProperties: $this->buildArrayValue($parameter, 'extraProperties') ?? [],
×
500
            );
×
501
        }
502

503
        return $parameters;
×
504
    }
505
}
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