forked from vyuldashev/laravel-openapi
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move security requirements to a dedicated attribute
- Loading branch information
Showing
3 changed files
with
53 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Vyuldashev\LaravelOpenApi\Attributes; | ||
|
||
use Attribute; | ||
use InvalidArgumentException; | ||
use Vyuldashev\LaravelOpenApi\Factories\SecuritySchemeFactory; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] | ||
class SecurityRequirement | ||
{ | ||
public ?string $scheme; | ||
|
||
/** @var array<string> */ | ||
public ?array $scopes; | ||
|
||
/** | ||
* @param string|null $scheme | ||
* @param array $scopes | ||
* | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function __construct(string|null $scheme, array $scopes = []) | ||
{ | ||
if ($scheme) { | ||
$factory = class_exists($scheme) ? $scheme : app()->getNamespace().'OpenApi\\SecuritySchemes\\'.$scheme; | ||
|
||
if (! is_a($factory, SecuritySchemeFactory::class, true)) { | ||
throw new InvalidArgumentException( | ||
sprintf('Security class is either not declared or is not an instance of %s', SecuritySchemeFactory::class) | ||
); | ||
} | ||
} | ||
|
||
$this->scheme = $scheme; | ||
$this->scopes = $scopes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters