1 | <?php |
||
2 | |||
3 | declare(strict_types = 1); |
||
4 | |||
5 | namespace inroutephp\inroute\Compiler\OpenApi; |
||
6 | |||
7 | use inroutephp\inroute\Compiler\CompilerPassInterface; |
||
8 | use inroutephp\inroute\Runtime\RouteInterface; |
||
9 | use OpenApi\Annotations\Operation; |
||
10 | use const OpenApi\Annotations\UNDEFINED; |
||
11 | |||
12 | final class OpenApiCompilerPass implements CompilerPassInterface |
||
13 | { |
||
14 | public function processRoute(RouteInterface $route): RouteInterface |
||
15 | { |
||
16 | /** @var ?Operation $operation */ |
||
17 | $operation = $route->getAnnotation(Operation::CLASS); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
18 | |||
19 | if ($operation) { |
||
20 | $route = $route |
||
21 | ->withRoutable(true) |
||
22 | ->withHttpMethod($operation->method); |
||
23 | |||
24 | if ($operation->path != UNDEFINED) { |
||
25 | $route = $route->withPath($operation->path); |
||
26 | } |
||
27 | |||
28 | if ($operation->operationId != UNDEFINED) { |
||
29 | $route = $route->withName($operation->operationId); |
||
30 | } |
||
31 | } |
||
32 | |||
33 | return $route; |
||
34 | } |
||
35 | } |
||
36 |