forked from cebe/php-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecurityScheme.php
More file actions
84 lines (78 loc) · 2.55 KB
/
Copy pathSecurityScheme.php
File metadata and controls
84 lines (78 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* @copyright Copyright (c) 2018 Carsten Brandt <mail@cebe.cc> and contributors
* @license https://github.com/cebe/php-openapi/blob/master/LICENSE
*/
namespace cebe\openapi\spec;
use cebe\openapi\SpecBaseObject;
/**
* Defines a security scheme that can be used by the operations.
*
* @link https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#securitySchemeObject
*
* @property string $type
* @property string $description
* @property string $name
* @property string $in
* @property string $scheme
* @property string $bearerFormat
* @property OAuthFlows|null $flows
* @property string $openIdConnectUrl
*/
class SecurityScheme extends SpecBaseObject
{
private $knownTypes = [
"apiKey",
"http",
"oauth2",
"openIdConnect"
];
/**
* @return array array of attributes available in this object.
*/
protected function attributes(): array
{
return [
'type' => Type::STRING,
'description' => Type::STRING,
'name' => Type::STRING,
'in' => Type::STRING,
'scheme' => Type::STRING,
'bearerFormat' => Type::STRING,
'flows' => OAuthFlows::class,
'openIdConnectUrl' => Type::STRING,
];
}
/**
* Perform validation on this object, check data against OpenAPI Specification rules.
*/
protected function performValidation()
{
$this->requireProperties(['type']);
if (isset($this->type)) {
if (!in_array($this->type, $this->knownTypes)) {
$this->addError("Unknown Security Scheme type: $this->type");
} else {
switch ($this->type) {
case "apiKey":
$this->requireProperties(['name', 'in']);
if (isset($this->in)) {
if (!in_array($this->in, ["query", "header", "cookie"])) {
$this->addError("Invalid value for Security Scheme property 'in': $this->in");
}
}
break;
case "http":
$this->requireProperties(['scheme']);
break;
case "oauth2":
$this->requireProperties(['flows']);
break;
case "openIdConnect":
$this->requireProperties(['openIdConnectUrl']);
break;
}
}
}
}
}