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

onmoon / openapi-server-bundle / 15881876638

25 Jun 2025 04:28PM UTC coverage: 80.585% (-0.5%) from 81.095%
15881876638

Pull #196

github

web-flow
Merge 90ce8070d into c35fba5f2
Pull Request #196: Fix minimum versions install

9 of 29 new or added lines in 5 files covered. (31.03%)

44 existing lines in 12 files now uncovered.

1378 of 1710 relevant lines covered (80.58%)

3.8 hits per line

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

88.46
/src/Router/RouteLoader.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace OnMoon\OpenApiServerBundle\Router;
6

7
use OnMoon\OpenApiServerBundle\Controller\ApiController;
8
use OnMoon\OpenApiServerBundle\Specification\SpecificationLoader;
9
use OnMoon\OpenApiServerBundle\Types\ArgumentResolver;
10
use Stringable;
11
use Symfony\Component\Config\Loader\Loader;
12
use Symfony\Component\Routing\Route;
13
use Symfony\Component\Routing\RouteCollection;
14

15
use function array_key_exists;
16

17
/** @psalm-suppress ClassMustBeFinal */
18
class RouteLoader extends Loader
19
{
20
    private SpecificationLoader $loader;
21
    private ArgumentResolver $argumentResolver;
22
    public const OPENAPI_TYPE      = 'open_api';
23
    public const OPENAPI_SPEC      = '_openapi_spec';
24
    public const OPENAPI_OPERATION = '_openapi_operation';
25

26
    public function __construct(SpecificationLoader $loader, ArgumentResolver $argumentResolver)
27
    {
28
        $this->loader           = $loader;
11✔
29
        $this->argumentResolver = $argumentResolver;
11✔
30
    }
31

32
    public function load(mixed $resource, ?string $type = null): RouteCollection
33
    {
34
        $specName      = (string) $resource;
6✔
35
        $specification = $this->loader->load($specName);
6✔
36

37
        $routes = new RouteCollection();
6✔
38

39
        foreach ($specification->getOperations() as $operationId => $operation) {
6✔
40
            /** @psalm-var array<(string|Stringable)> $requirements */
41
            $requirements = [];
6✔
42

43
            $parameters = $operation->getRequestParameters();
6✔
44
            if (array_key_exists('path', $parameters)) {
6✔
45
                $argumentPatterns = $this->argumentResolver->resolveArgumentPatterns($parameters['path']);
6✔
46
                foreach ($argumentPatterns as $name => $pattern) {
6✔
NEW
47
                    if ($pattern === null) {
×
NEW
48
                        continue;
×
49
                    }
50

NEW
51
                    $requirements[$name] = $pattern;
×
52
                }
53
            }
54

55
            $defaults  = [
6✔
56
                '_controller' => ApiController::class . '::handle',
6✔
57
            ];
6✔
58
            $options   = [
6✔
59
                self::OPENAPI_SPEC => $specName,
6✔
60
                self::OPENAPI_OPERATION => $operationId,
6✔
61
            ];
6✔
62
            $route     = new Route($operation->getUrl(), $defaults, $requirements, $options, '', [], [$operation->getMethod()]);
6✔
63
            $routeName = $operationId;
6✔
64
            $routes->add($routeName, $route);
6✔
65
        }
66

67
        return $routes;
6✔
68
    }
69

70
    /** @inheritDoc */
71
    public function supports($resource, ?string $type = null): bool
72
    {
73
        return $type === self::OPENAPI_TYPE;
5✔
74
    }
75
}
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