| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
/** |
| 4 |
* @license Apache 2.0 |
| 5 |
*/ |
| 6 |
|
| 7 |
namespace OpenApi\Annotations; |
| 8 |
|
| 9 |
use OpenApi\Generator; |
| 10 |
|
| 11 |
/** |
| 12 |
* @see [Security Scheme Object](https://spec.openapis.org/oas/v3.1.1.html#security-scheme-object-0) |
| 13 |
* |
| 14 |
* @Annotation |
| 15 |
*/ |
| 16 |
class SecurityScheme extends AbstractAnnotation |
| 17 |
{ |
| 18 |
/** |
| 19 |
* The relative or absolute path to a security scheme. |
| 20 |
* |
| 21 |
* @see [Reference Object](https://spec.openapis.org/oas/v3.1.1.html#reference-object) |
| 22 |
* |
| 23 |
* @var string|class-string|object |
| 24 |
*/ |
| 25 |
public $ref = Generator::UNDEFINED; |
| 26 |
|
| 27 |
/** |
| 28 |
* The key into OpenApi->security array. |
| 29 |
* |
| 30 |
* @var string |
| 31 |
*/ |
| 32 |
public $securityScheme = Generator::UNDEFINED; |
| 33 |
|
| 34 |
/** |
| 35 |
* The type of the security scheme. |
| 36 |
* |
| 37 |
* @var string|non-empty-array<string> |
| 38 |
*/ |
| 39 |
public $type = Generator::UNDEFINED; |
| 40 |
|
| 41 |
/** |
| 42 |
* A short description for security scheme. |
| 43 |
* |
| 44 |
* @var string |
| 45 |
*/ |
| 46 |
public $description = Generator::UNDEFINED; |
| 47 |
|
| 48 |
/** |
| 49 |
* The name of the header or query parameter to be used. |
| 50 |
* |
| 51 |
* @var string |
| 52 |
*/ |
| 53 |
public $name = Generator::UNDEFINED; |
| 54 |
|
| 55 |
/** |
| 56 |
* Required The location of the API key. |
| 57 |
* |
| 58 |
* @var string |
| 59 |
*/ |
| 60 |
public $in = Generator::UNDEFINED; |
| 61 |
|
| 62 |
/** |
| 63 |
* The flow used by the OAuth2 security scheme. |
| 64 |
* |
| 65 |
* @var list<Flow> |
| 66 |
*/ |
| 67 |
public $flows = Generator::UNDEFINED; |
| 68 |
|
| 69 |
/** |
| 70 |
* A hint to the client to identify how the bearer token is formatted. |
| 71 |
* |
| 72 |
* Bearer tokens are usually generated by an authorization server, so this information is primarily for documentation purposes. |
| 73 |
* |
| 74 |
* @var string |
| 75 |
*/ |
| 76 |
public $bearerFormat = Generator::UNDEFINED; |
| 77 |
|
| 78 |
/** |
| 79 |
* The name of the HTTP Authorization scheme. |
| 80 |
* |
| 81 |
* @see [RFC7235](https://tools.ietf.org/html/rfc7235#section-5.1) |
| 82 |
* |
| 83 |
* @var string |
| 84 |
*/ |
| 85 |
public $scheme = Generator::UNDEFINED; |
| 86 |
|
| 87 |
/** |
| 88 |
* OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL. |
| 89 |
* |
| 90 |
* @var string |
| 91 |
*/ |
| 92 |
public $openIdConnectUrl = Generator::UNDEFINED; |
| 93 |
|
| 94 |
/** |
| 95 |
* @inheritdoc |
| 96 |
*/ |
| 97 |
public static $_required = ['securityScheme', 'type']; |
| 98 |
|
| 99 |
/** |
| 100 |
* @inheritdoc |
| 101 |
*/ |
| 102 |
public static $_types = [ |
| 103 |
'type' => ['http', 'apiKey', 'oauth2', 'openIdConnect'], |
| 104 |
'description' => 'string', |
| 105 |
'name' => 'string', |
| 106 |
'bearerFormat' => 'string', |
| 107 |
'in' => ['query', 'header', 'cookie'], |
| 108 |
]; |
| 109 |
|
| 110 |
/** |
| 111 |
* @inheritdoc |
| 112 |
*/ |
| 113 |
public static $_nested = [ |
| 114 |
Flow::class => ['flows', 'flow'], |
| 115 |
Attachable::class => ['attachables'], |
| 116 |
]; |
| 117 |
|
| 118 |
/** |
| 119 |
* @inheritdoc |
| 120 |
*/ |
| 121 |
public static $_parents = [ |
| 122 |
Components::class, |
| 123 |
]; |
| 124 |
|
| 125 |
/** |
| 126 |
* @inheritdoc |
| 127 |
*/ |
| 128 |
public function merge(array $annotations, bool $ignore = false): array |
| 129 |
{ |
| 130 |
$unmerged = parent::merge($annotations, $ignore); |
| 131 |
|
| 132 |
if ($this->type === 'oauth2') { |
| 133 |
$this->name = Generator::UNDEFINED; |
| 134 |
} |
| 135 |
|
| 136 |
return $unmerged; |
| 137 |
} |
| 138 |
} |