1
|
|
|
<?php |
2
|
|
|
namespace gossi\swagger; |
3
|
|
|
|
4
|
|
|
use phootwork\lang\Arrayable; |
5
|
|
|
use gossi\swagger\parts\DescriptionPart; |
6
|
|
|
use phootwork\collection\Map; |
7
|
|
|
use phootwork\collection\CollectionUtils; |
8
|
|
|
|
9
|
|
|
class SecurityScheme extends AbstractModel implements Arrayable { |
10
|
|
|
|
11
|
|
|
use DescriptionPart; |
12
|
|
|
|
13
|
|
|
/** @var string */ |
14
|
|
|
private $id; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
private $name; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
private $type; |
21
|
1 |
|
|
22
|
1 |
|
/** @var string */ |
23
|
1 |
|
private $in; |
24
|
1 |
|
|
25
|
|
|
/** @var string */ |
26
|
|
|
private $flow; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
1 |
|
private $authorizationUrl; |
30
|
1 |
|
|
31
|
1 |
|
/** @var string */ |
32
|
1 |
|
private $tokenUrl; |
33
|
|
|
|
34
|
|
|
/** @var Map */ |
35
|
|
|
private $scopes; |
36
|
|
|
|
37
|
1 |
|
/** |
38
|
1 |
|
* @param string $id |
39
|
|
|
* @param array $contents |
40
|
|
|
*/ |
41
|
|
|
public function __construct($id, $contents = []) { |
42
|
|
|
$this->id = $id; |
43
|
|
|
$this->parse($contents); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array $contents |
48
|
|
|
*/ |
49
|
|
|
private function parse($contents = []) { |
50
|
|
|
$data = CollectionUtils::toMap($contents); |
51
|
|
|
|
52
|
|
|
$this->type = $data->get('type'); |
53
|
|
|
$this->name = $data->get('name'); |
54
|
|
|
$this->in = $data->get('in'); |
55
|
|
|
$this->flow = $data->get('flow'); |
56
|
|
|
$this->authorizationUrl = $data->get('authorizationUrl'); |
57
|
|
|
$this->tokenUrl = $data->get('tokenUrl'); |
58
|
|
|
$this->scopes = $data->get('scopes', new Map()); |
59
|
|
|
|
60
|
|
|
$this->parseDescription($data); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
public function toArray() { |
67
|
|
|
return $this->export('type', 'description', 'name', 'in', 'flow', |
68
|
|
|
'authorizationUrl', 'tokenUrl', 'scopes'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Returns the id for this security scheme |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getId() { |
77
|
|
|
return $this->id; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Return the name of the header or query parameter to be used |
82
|
|
|
* |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function getName() { |
86
|
|
|
return $this->name; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Sets the name of the header or query parameter to be used |
91
|
|
|
* |
92
|
|
|
* @param string $name |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function setName($name) { |
96
|
|
|
$this->name = $name; |
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the type of the security scheme |
102
|
|
|
* |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function getType() { |
106
|
|
|
return $this->type; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Sets the type of the security scheme |
111
|
|
|
* |
112
|
|
|
* @param string $type Valid values are "basic", "apiKey" or "oauth2" |
113
|
|
|
* @return $this |
114
|
|
|
*/ |
115
|
|
|
public function setType($type) { |
116
|
|
|
$this->type = $type; |
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Returns the location of the API key |
122
|
|
|
* |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function getIn() { |
126
|
|
|
return $this->in; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Sets the location of the API key |
131
|
|
|
* |
132
|
|
|
* @param string $in Valid values are "query" or "header" |
133
|
|
|
* @return $this |
134
|
|
|
*/ |
135
|
|
|
public function setIn($in) { |
136
|
|
|
$this->in = $in; |
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Retunrs the flow used by the OAuth2 security scheme |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getFlow() { |
146
|
|
|
return $this->flow; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Sets the flow used by the OAuth2 security scheme |
151
|
|
|
* |
152
|
|
|
* @param string $flow Valid values are "implicit", "password", "application" or "accessCode" |
153
|
|
|
* @return $this |
154
|
|
|
*/ |
155
|
|
|
public function setFlow($flow) { |
156
|
|
|
$this->flow = $flow; |
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Returns the authorization URL to be used for this flow |
162
|
|
|
* |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
|
|
public function getAuthorizationUrl() { |
166
|
|
|
return $this->authorizationUrl; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Sets the authorization URL to be used for this flow |
171
|
|
|
* |
172
|
|
|
* @param string $authorizationUrl |
173
|
|
|
* @return $this |
174
|
|
|
*/ |
175
|
|
|
public function setAuthorizationUrl($authorizationUrl) { |
176
|
|
|
$this->authorizationUrl = $authorizationUrl; |
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Returns the token URL to be used for this flow |
182
|
|
|
* |
183
|
|
|
* @return string |
184
|
|
|
*/ |
185
|
|
|
public function getTokenUrl() { |
186
|
|
|
return $this->tokenUrl; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Sets the token URL to be used for this flow |
191
|
|
|
* |
192
|
|
|
* @param string $tokenUrl |
193
|
|
|
* @return $this |
194
|
|
|
*/ |
195
|
|
|
public function setTokenUrl($tokenUrl) { |
196
|
|
|
$this->tokenUrl = $tokenUrl; |
197
|
|
|
return $this; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Returns the scopes |
202
|
|
|
* |
203
|
|
|
* @return Map |
204
|
|
|
*/ |
205
|
|
|
public function getScopes() { |
206
|
|
|
return $this->scopes; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
} |
210
|
|
|
|