• 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

90.48
/src/JsonSchema/BackwardCompatibleSchemaFactory.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\JsonSchema;
15

16
use ApiPlatform\Metadata\Operation;
17

18
/**
19
 * This factory decorates range integer and number properties to keep Draft 4 backward compatibility.
20
 *
21
 * @see https://github.com/api-platform/core/issues/6041
22
 *
23
 * @internal
24
 */
25
final class BackwardCompatibleSchemaFactory implements SchemaFactoryInterface, SchemaFactoryAwareInterface
26
{
27
    public const SCHEMA_DRAFT4_VERSION = 'draft_4';
28

29
    public function __construct(private readonly SchemaFactoryInterface $decorated)
30
    {
UNCOV
31
    }
824✔
32

33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function buildSchema(string $className, string $format = 'json', string $type = Schema::TYPE_OUTPUT, ?Operation $operation = null, ?Schema $schema = null, ?array $serializerContext = null, bool $forceCollection = false): Schema
37
    {
UNCOV
38
        $schema = $this->decorated->buildSchema($className, $format, $type, $operation, $schema, $serializerContext, $forceCollection);
61✔
39

UNCOV
40
        if (!($serializerContext[self::SCHEMA_DRAFT4_VERSION] ?? false)) {
61✔
UNCOV
41
            return $schema;
42✔
42
        }
43

UNCOV
44
        foreach ($schema->getDefinitions() as $definition) {
19✔
UNCOV
45
            foreach ($definition['properties'] ?? [] as $property) {
19✔
UNCOV
46
                if (!isset($property['type'])) {
19✔
UNCOV
47
                    continue;
8✔
48
                }
49

UNCOV
50
                foreach ((array) $property['type'] as $type) {
19✔
UNCOV
51
                    if ('integer' !== $type && 'number' !== $type) {
19✔
UNCOV
52
                        continue;
19✔
53
                    }
54

UNCOV
55
                    if (isset($property['exclusiveMinimum'])) {
6✔
UNCOV
56
                        $property['minimum'] = $property['exclusiveMinimum'];
1✔
UNCOV
57
                        $property['exclusiveMinimum'] = true;
1✔
58
                    }
UNCOV
59
                    if (isset($property['exclusiveMaximum'])) {
6✔
UNCOV
60
                        $property['maximum'] = $property['exclusiveMaximum'];
1✔
UNCOV
61
                        $property['exclusiveMaximum'] = true;
1✔
62
                    }
63

UNCOV
64
                    break;
6✔
65
                }
66
            }
67
        }
68

UNCOV
69
        return $schema;
19✔
70
    }
71

72
    public function setSchemaFactory(SchemaFactoryInterface $schemaFactory): void
73
    {
74
        if ($this->decorated instanceof SchemaFactoryAwareInterface) {
×
75
            $this->decorated->setSchemaFactory($schemaFactory);
×
76
        }
77
    }
78
}
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