• 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

100.0
/src/Validator/Metadata/Resource/Factory/ParameterValidationResourceMetadataCollectionFactory.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\Validator\Metadata\Resource\Factory;
15

16
use ApiPlatform\Metadata\HttpOperation;
17
use ApiPlatform\Metadata\Parameter;
18
use ApiPlatform\Metadata\Parameters;
19
use ApiPlatform\Metadata\QueryParameter;
20
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
21
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
22
use ApiPlatform\OpenApi\Model\Parameter as OpenApiParameter;
23
use ApiPlatform\Validator\Util\ParameterValidationConstraints;
24
use Psr\Container\ContainerInterface;
25

26
final class ParameterValidationResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
27
{
28
    use ParameterValidationConstraints;
29

30
    public function __construct(
31
        private readonly ?ResourceMetadataCollectionFactoryInterface $decorated = null,
32
        private readonly ?ContainerInterface $filterLocator = null,
33
    ) {
UNCOV
34
    }
1,520✔
35

36
    public function create(string $resourceClass): ResourceMetadataCollection
37
    {
UNCOV
38
        $resourceMetadataCollection = $this->decorated?->create($resourceClass) ?? new ResourceMetadataCollection($resourceClass);
63✔
39

UNCOV
40
        foreach ($resourceMetadataCollection as $i => $resource) {
63✔
UNCOV
41
            $operations = $resource->getOperations();
57✔
42

UNCOV
43
            foreach ($operations as $operationName => $operation) {
57✔
UNCOV
44
                $parameters = $operation->getParameters() ?? new Parameters();
57✔
UNCOV
45
                foreach ($parameters as $key => $parameter) {
57✔
UNCOV
46
                    $parameters->add($key, $this->addSchemaValidation($parameter));
3✔
47
                }
48

49
                // As we deprecate the parameter validator, we declare a parameter for each filter transfering validation to the new system
UNCOV
50
                if ($operation->getFilters() && 0 === $parameters->count()) {
57✔
UNCOV
51
                    $parameters = $this->addFilterValidation($operation);
23✔
52
                }
53

UNCOV
54
                if (\count($parameters) > 0) {
57✔
UNCOV
55
                    $operations->add($operationName, $operation->withParameters($parameters));
22✔
56
                }
57
            }
58

UNCOV
59
            $resourceMetadataCollection[$i] = $resource->withOperations($operations->sort());
57✔
60

UNCOV
61
            if (!$graphQlOperations = $resource->getGraphQlOperations()) {
57✔
UNCOV
62
                continue;
22✔
63
            }
64

UNCOV
65
            foreach ($graphQlOperations as $operationName => $operation) {
53✔
UNCOV
66
                $parameters = $operation->getParameters() ?? new Parameters();
53✔
UNCOV
67
                foreach ($operation->getParameters() ?? [] as $key => $parameter) {
53✔
UNCOV
68
                    $parameters->add($key, $this->addSchemaValidation($parameter));
2✔
69
                }
70

UNCOV
71
                if (\count($parameters) > 0) {
53✔
UNCOV
72
                    $graphQlOperations[$operationName] = $operation->withParameters($parameters);
2✔
73
                }
74
            }
75

UNCOV
76
            $resourceMetadataCollection[$i] = $resource->withGraphQlOperations($graphQlOperations);
53✔
77
        }
78

UNCOV
79
        return $resourceMetadataCollection;
63✔
80
    }
81

82
    private function addSchemaValidation(Parameter $parameter, ?array $schema = null, ?bool $required = null, ?OpenApiParameter $openApi = null): Parameter
83
    {
UNCOV
84
        if (null !== $parameter->getConstraints()) {
22✔
UNCOV
85
            return $parameter;
2✔
86
        }
87

UNCOV
88
        $assertions = $this->getParameterValidationConstraints($parameter, $schema, $required, $openApi);
22✔
UNCOV
89
        if (!$assertions) {
22✔
UNCOV
90
            return $parameter;
20✔
91
        }
92

UNCOV
93
        if (1 === \count($assertions)) {
10✔
UNCOV
94
            return $parameter->withConstraints($assertions[0]);
10✔
95
        }
96

UNCOV
97
        return $parameter->withConstraints($assertions);
2✔
98
    }
99

100
    private function addFilterValidation(HttpOperation $operation): Parameters
101
    {
UNCOV
102
        $parameters = new Parameters();
23✔
UNCOV
103
        $internalPriority = -1;
23✔
104

UNCOV
105
        foreach ($operation->getFilters() as $filter) {
23✔
UNCOV
106
            if (!$this->filterLocator->has($filter)) {
23✔
107
                continue;
2✔
108
            }
109

UNCOV
110
            $filter = $this->filterLocator->get($filter);
23✔
UNCOV
111
            foreach ($filter->getDescription($operation->getClass()) as $parameterName => $definition) {
23✔
UNCOV
112
                $key = $parameterName;
22✔
UNCOV
113
                $required = $definition['required'] ?? false;
22✔
UNCOV
114
                $schema = $definition['schema'] ?? null;
22✔
115

UNCOV
116
                $openApi = null;
22✔
UNCOV
117
                if (isset($definition['openapi']) && $definition['openapi'] instanceof OpenApiParameter) {
22✔
UNCOV
118
                    $openApi = $definition['openapi'];
10✔
119
                }
120

121
                // The query parameter validator forced this, lets maintain BC on filters
UNCOV
122
                if (true === $required && !$openApi) {
22✔
123
                    $openApi = new OpenApiParameter(name: $key, in: 'query', allowEmptyValue: false);
4✔
124
                }
125

UNCOV
126
                $parameters->add($key, $this->addSchemaValidation(
22✔
127
                    // we disable openapi and hydra on purpose as their docs comes from filters see the condition for addFilterValidation above
UNCOV
128
                    new QueryParameter(key: $key, property: $definition['property'] ?? null, priority: $internalPriority--, schema: $schema, openApi: false, hydra: false),
22✔
UNCOV
129
                    $schema,
22✔
UNCOV
130
                    $required,
22✔
UNCOV
131
                    $openApi
22✔
UNCOV
132
                ));
22✔
133
            }
134
        }
135

UNCOV
136
        return $parameters;
23✔
137
    }
138
}
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