Skip to content

Commit b46de76

Browse files
committed
Complete the implementation
1 parent 29f5bbb commit b46de76

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

src/spec/SecurityRequirements.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
*/
1818
class SecurityRequirements extends SpecBaseObject
1919
{
20+
private $_securityRequirements;
21+
22+
public function __construct(array $data)
23+
{
24+
parent::__construct($data);
25+
$this->_securityRequirements = $data;
26+
}
27+
2028
/**
2129
* @return array array of attributes available in this object.
2230
*/
@@ -37,4 +45,19 @@ protected function attributes(): array
3745
protected function performValidation()
3846
{
3947
}
48+
49+
/**
50+
* @return mixed returns the serializable data of this object for converting it
51+
* to JSON or YAML.
52+
* TODO
53+
*/
54+
public function getSerializableData()
55+
{
56+
$data = [];
57+
foreach ($this->_securityRequirements as $name => $securityRequirement) {
58+
/** @var SecurityRequirement $securityRequirement */
59+
$data[] = [$name => json_decode(json_encode($securityRequirement->getSerializableData()), true)];
60+
}
61+
return $data;
62+
}
4063
}

src/spec/SecuritySchemes.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class SecuritySchemes extends SpecBaseObject
1313
{
14-
private $_securitySchemes = [];
14+
private $_securitySchemes;
1515

1616
public function __construct(array $data)
1717
{
@@ -31,14 +31,15 @@ public function performValidation()
3131
/**
3232
* @return mixed returns the serializable data of this object for converting it
3333
* to JSON or YAML.
34+
* TODO
3435
*/
3536
public function getSerializableData()
3637
{
3738
$data = [];
38-
foreach ($this->_securitySchemes as $securityScheme) {
39-
/** @var $securityScheme SecurityScheme */
40-
$data[$securityScheme->name] = $securityScheme->scheme;
39+
foreach ($this->_securitySchemes as $name => $securityScheme) {
40+
/** @var SecurityScheme $securityScheme */
41+
$data[$name] = $securityScheme->getSerializableData();
4142
}
4243
return (object) $data;
4344
}
44-
}
45+
}

tests/WriterTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use cebe\openapi\spec\Response;
77
use cebe\openapi\spec\Responses;
88
use cebe\openapi\spec\SecurityRequirement;
9+
use cebe\openapi\spec\SecurityRequirements;
910
use cebe\openapi\spec\SecurityScheme;
1011
use cebe\openapi\spec\SecuritySchemes;
1112

@@ -200,19 +201,19 @@ public function testSecurityAtPathOperationLevel()
200201
$openapi = $this->createOpenAPI([
201202
'components' => new Components([
202203
'securitySchemes' => new SecuritySchemes([
203-
new SecurityScheme([
204-
'BearerAuth' => [
205-
'type' => 'http',
206-
'scheme' => 'bearer',
207-
'bearerFormat' => 'AuthToken and JWT Format' # optional, arbitrary value for documentation purposes
208-
]
209-
])
204+
'BearerAuth' => new SecurityScheme([
205+
'type' => 'http',
206+
'scheme' => 'bearer',
207+
'bearerFormat' => 'AuthToken and JWT Format' # optional, arbitrary value for documentation purposes
208+
]),
210209
]),
211210
]),
212211
'paths' => [
213212
'/test' => new PathItem([
214213
'get' => new Operation([
215-
'security' => [new SecurityRequirement(['BearerAuth' => []])],
214+
'security' => new SecurityRequirements([
215+
'BearerAuth' => new SecurityRequirement([]),
216+
]),
216217
'responses' => new Responses([
217218
200 => new Response(['description' => 'OK']),
218219
])

0 commit comments

Comments
 (0)