Skip to content

Commit ccda21b

Browse files
authored
Merge pull request #113 from RonasIT/93-add-exception-for-invalid-documentation-viewer
feat: add exception for invalid documentation_viewer configuration.
2 parents 5e383d5 + 888439a commit ccda21b

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace RonasIT\Support\AutoDoc\Exceptions;
4+
5+
use Exception;
6+
7+
class UnsupportedDocumentationViewerException extends Exception
8+
{
9+
public function __construct(string $invalidViewer)
10+
{
11+
parent::__construct(
12+
"The documentation viewer '{$invalidViewer}' does not exists."
13+
. " Please check that the 'documentation_viewer' key of your auto-doc.php config has one of valid values."
14+
);
15+
}
16+
}

src/Services/SwaggerService.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use RonasIT\Support\AutoDoc\Exceptions\LegacyConfigException;
1616
use RonasIT\Support\AutoDoc\Exceptions\SpecValidation\InvalidSwaggerSpecException;
1717
use RonasIT\Support\AutoDoc\Exceptions\SwaggerDriverClassNotFoundException;
18+
use RonasIT\Support\AutoDoc\Exceptions\UnsupportedDocumentationViewerException;
1819
use RonasIT\Support\AutoDoc\Exceptions\WrongSecurityConfigException;
1920
use RonasIT\Support\AutoDoc\Interfaces\SwaggerDriverInterface;
2021
use RonasIT\Support\AutoDoc\Traits\GetDependenciesTrait;
@@ -94,6 +95,12 @@ protected function initConfig()
9495
if (version_compare($packageConfigs['config_version'], $version, '>')) {
9596
throw new LegacyConfigException();
9697
}
98+
99+
$documentationViewer = (string) Arr::get($this->config, 'documentation_viewer');
100+
101+
if (!view()->exists("auto-doc::documentation-{$documentationViewer}")) {
102+
throw new UnsupportedDocumentationViewerException($documentationViewer);
103+
}
97104
}
98105

99106
protected function setDriver()

tests/SwaggerServiceTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use RonasIT\Support\AutoDoc\Exceptions\SpecValidation\MissingPathPlaceholderException;
2222
use RonasIT\Support\AutoDoc\Exceptions\SpecValidation\MissingRefFileException;
2323
use RonasIT\Support\AutoDoc\Exceptions\SwaggerDriverClassNotFoundException;
24+
use RonasIT\Support\AutoDoc\Exceptions\UnsupportedDocumentationViewerException;
2425
use RonasIT\Support\AutoDoc\Exceptions\WrongSecurityConfigException;
2526
use RonasIT\Support\AutoDoc\Services\SwaggerService;
2627
use RonasIT\Support\Tests\Support\Mock\TestNotificationSetting;
@@ -649,4 +650,30 @@ public function testAddDataWithoutBoundContract()
649650

650651
$service->addData($request, $response);
651652
}
653+
654+
public function testSetInvalidDocumentationViewer()
655+
{
656+
config(['auto-doc.documentation_viewer' => 'invalid']);
657+
658+
$this->expectException(UnsupportedDocumentationViewerException::class);
659+
$this->expectExceptionMessage(
660+
"The documentation viewer 'invalid' does not exists."
661+
. " Please check that the 'documentation_viewer' key of your auto-doc.php config has one of valid values."
662+
);
663+
664+
app(SwaggerService::class);
665+
}
666+
667+
public function testSetNullableDocumentationViewer()
668+
{
669+
config(['auto-doc.documentation_viewer' => null]);
670+
671+
$this->expectException(UnsupportedDocumentationViewerException::class);
672+
$this->expectExceptionMessage(
673+
"The documentation viewer '' does not exists."
674+
. " Please check that the 'documentation_viewer' key of your auto-doc.php config has one of valid values."
675+
);
676+
677+
app(SwaggerService::class);
678+
}
652679
}

0 commit comments

Comments
 (0)