Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| OpenApiDocumentationRouteDefinition | |
100.00% |
10 / 10 |
|
100.00% |
7 / 7 |
9 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getOperationId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| getMethod | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getUrl | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| getController | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getRouteAttributes | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getUrlPrefixes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\RestApi\RouteDefinitions; |
| 3 | |
| 4 | use Apie\Common\Enums\UrlPrefix; |
| 5 | use Apie\Common\Interfaces\HasRouteDefinition; |
| 6 | use Apie\Common\Lists\UrlPrefixList; |
| 7 | use Apie\Core\BoundedContext\BoundedContextId; |
| 8 | use Apie\Core\Enums\RequestMethod; |
| 9 | use Apie\Core\ValueObjects\UrlRouteDefinition; |
| 10 | use Apie\RestApi\Controllers\OpenApiDocumentationController; |
| 11 | |
| 12 | class OpenApiDocumentationRouteDefinition implements HasRouteDefinition |
| 13 | { |
| 14 | public function __construct(private readonly bool $yamlFormat, private BoundedContextId $boundedContextId) |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | public function getOperationId(): string |
| 19 | { |
| 20 | return 'openapi_spec.' . ($this->yamlFormat ? 'yaml' : 'json'); |
| 21 | } |
| 22 | |
| 23 | public function getMethod(): RequestMethod |
| 24 | { |
| 25 | return RequestMethod::GET; |
| 26 | } |
| 27 | |
| 28 | public function getUrl(): UrlRouteDefinition |
| 29 | { |
| 30 | return new UrlRouteDefinition('/openapi.' . ($this->yamlFormat ? 'yaml' : 'json')); |
| 31 | } |
| 32 | |
| 33 | public function getController(): string |
| 34 | { |
| 35 | return OpenApiDocumentationController::class; |
| 36 | } |
| 37 | |
| 38 | public function getRouteAttributes(): array |
| 39 | { |
| 40 | return [ |
| 41 | 'boundedContextId' => $this->boundedContextId->toNative(), |
| 42 | 'yaml' => $this->yamlFormat, |
| 43 | ]; |
| 44 | } |
| 45 | |
| 46 | public function getUrlPrefixes(): UrlPrefixList |
| 47 | { |
| 48 | return new UrlPrefixList([UrlPrefix::API]); |
| 49 | } |
| 50 | } |