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

api-platform / core / 20832557808

08 Jan 2026 09:35PM UTC coverage: 18.991% (-9.9%) from 28.875%
20832557808

Pull #7658

github

web-flow
Merge c8402145f into 39c55837e
Pull Request #7658: fix(openapi): properly document list parameters

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

14885 existing lines in 487 files now uncovered.

10912 of 57460 relevant lines covered (18.99%)

21.79 hits per line

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

88.24
/src/Metadata/Resource/Factory/ObjectMapperMetadataCollectionFactory.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\Resource\Factory;
15

16
use ApiPlatform\Doctrine\Odm\State\Options as OdmOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options;
18
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
19
use Symfony\Component\ObjectMapper\Metadata\Mapping;
20
use Symfony\Component\ObjectMapper\Metadata\ObjectMapperMetadataFactoryInterface;
21

22
class ObjectMapperMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
23
{
24
    public function __construct(
25
        private readonly ResourceMetadataCollectionFactoryInterface $decorated,
26
        private readonly ObjectMapperMetadataFactoryInterface $objectMapperMetadata,
27
    ) {
UNCOV
28
    }
694✔
29

30
    public function create(string $resourceClass): ResourceMetadataCollection
31
    {
UNCOV
32
        $resourceMetadataCollection = $this->decorated->create($resourceClass);
30✔
33

UNCOV
34
        foreach ($resourceMetadataCollection as $key => $resourceMetadata) {
30✔
UNCOV
35
            $operations = $resourceMetadata->getOperations();
27✔
36

UNCOV
37
            if (!$operations) {
27✔
38
                continue;
×
39
            }
40

UNCOV
41
            foreach ($operations as $operationKey => $operation) {
27✔
UNCOV
42
                if (null !== $operation->canMap()) {
27✔
UNCOV
43
                    continue;
1✔
44
                }
45

UNCOV
46
                $entityClass = null;
27✔
UNCOV
47
                if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
27✔
UNCOV
48
                    $entityClass = $options->getEntityClass();
1✔
49
                }
50

UNCOV
51
                if (($options = $operation->getStateOptions()) && $options instanceof OdmOptions && $options->getDocumentClass()) {
27✔
UNCOV
52
                    $entityClass = $options->getDocumentClass();
2✔
53
                }
54

UNCOV
55
                $class = $operation->getInput()['class'] ?? $operation->getClass();
27✔
UNCOV
56
                $outputClass = $operation->getOutput()['class'] ?? null;
27✔
UNCOV
57
                $entityMap = null;
27✔
58

59
                // Look for Mapping metadata
UNCOV
60
                if ($this->canBeMapped($class) || ($outputClass && $this->canBeMapped($outputClass)) || ($entityClass && ($entityMap = $this->canBeMapped($entityClass)))) {
27✔
UNCOV
61
                    $found = true;
1✔
UNCOV
62
                    if ($entityMap) {
1✔
UNCOV
63
                        foreach ($entityMap as $mapping) {
1✔
UNCOV
64
                            if ($found = ($mapping->source === $operation->getClass() || $mapping->target === $operation->getClass())) {
1✔
65
                                break;
×
66
                            }
67
                        }
68
                    }
69

UNCOV
70
                    if (!$found) {
1✔
UNCOV
71
                        continue;
1✔
72
                    }
73

UNCOV
74
                    $operations->add($operationKey, $operation->withMap(true));
1✔
75
                }
76
            }
77

UNCOV
78
            $resourceMetadataCollection[$key] = $resourceMetadata->withOperations($operations);
27✔
79
        }
80

UNCOV
81
        return $resourceMetadataCollection;
30✔
82
    }
83

84
    /**
85
     * @return bool|list<Mapping>
86
     */
87
    private function canBeMapped(string $class): bool|array
88
    {
89
        try {
UNCOV
90
            $r = new \ReflectionClass($class);
27✔
UNCOV
91
            if (!$r->isInstantiable() || !($mapping = $this->objectMapperMetadata->create($r->newInstanceWithoutConstructor(), null, ['_api_check_can_be_mapped' => true]))) {
27✔
UNCOV
92
                return false;
27✔
93
            }
94
        } catch (\ReflectionException $e) {
×
95
            return false;
×
96
        }
97

UNCOV
98
        return $mapping;
1✔
99
    }
100
}
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