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

api-platform / core / 10903050455

17 Sep 2024 12:29PM UTC coverage: 7.684% (+0.7%) from 6.96%
10903050455

push

github

web-flow
fix: swagger ui with route identifier (#6616)

2 of 6 new or added lines in 6 files covered. (33.33%)

9000 existing lines in 286 files now uncovered.

12668 of 164863 relevant lines covered (7.68%)

22.93 hits per line

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

94.44
/src/JsonSchema/DefinitionNameFactory.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
use ApiPlatform\Metadata\Util\ResourceClassInfoTrait;
18
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
19

20
final class DefinitionNameFactory implements DefinitionNameFactoryInterface
21
{
22
    use ResourceClassInfoTrait;
23

24
    public function __construct(private ?array $distinctFormats)
25
    {
UNCOV
26
    }
1,854✔
27

28
    public function create(string $className, string $format = 'json', ?string $inputOrOutputClass = null, ?Operation $operation = null, array $serializerContext = []): string
29
    {
UNCOV
30
        if ($operation) {
39✔
UNCOV
31
            $prefix = $operation->getShortName();
39✔
32
        }
33

UNCOV
34
        if (!isset($prefix)) {
39✔
UNCOV
35
            $prefix = (new \ReflectionClass($className))->getShortName();
39✔
36
        }
37

UNCOV
38
        if (null !== $inputOrOutputClass && $className !== $inputOrOutputClass) {
39✔
UNCOV
39
            $parts = explode('\\', $inputOrOutputClass);
39✔
UNCOV
40
            $shortName = end($parts);
39✔
UNCOV
41
            $prefix .= '.'.$shortName;
39✔
42
        }
43

UNCOV
44
        if ('json' !== $format && ($this->distinctFormats[$format] ?? false)) {
39✔
45
            // JSON is the default, and so isn't included in the definition name
UNCOV
46
            $prefix .= '.'.$format;
39✔
47
        }
48

UNCOV
49
        $definitionName = $serializerContext[SchemaFactory::OPENAPI_DEFINITION_NAME] ?? null;
39✔
UNCOV
50
        if ($definitionName) {
39✔
51
            $name = \sprintf('%s-%s', $prefix, $definitionName);
×
52
        } else {
UNCOV
53
            $groups = (array) ($serializerContext[AbstractNormalizer::GROUPS] ?? []);
39✔
UNCOV
54
            $name = $groups ? \sprintf('%s-%s', $prefix, implode('_', $groups)) : $prefix;
39✔
55
        }
56

UNCOV
57
        return $this->encodeDefinitionName($name);
39✔
58
    }
59

60
    private function encodeDefinitionName(string $name): string
61
    {
UNCOV
62
        return preg_replace('/[^a-zA-Z0-9.\-_]/', '.', $name);
39✔
63
    }
64
}
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