Skip to content

Commit 236a47e

Browse files
committed
Cleanup and fix issue and complete the implementation
1 parent 219813f commit 236a47e

File tree

5 files changed

+15
-62
lines changed

5 files changed

+15
-62
lines changed

src/spec/SecurityRequirements.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function __construct(array $data)
2424
parent::__construct($data);
2525

2626
$read = true;
27-
foreach($data as $index => $value) {
27+
foreach ($data as $index => $value) {
2828
if (is_numeric($index)) { // read
2929
$requirements = $value;
3030
$this->_securityRequirements[array_keys($value)[0]] = new SecurityRequirement(array_values($value)[0]);
@@ -34,6 +34,9 @@ public function __construct(array $data)
3434
$this->_securityRequirements[$index] = $value;
3535
}
3636
}
37+
if ($data === []) {
38+
$this->_securityRequirements = [];
39+
}
3740
}
3841

3942
/**
@@ -71,6 +74,11 @@ public function getSerializableData()
7174

7275
public function getRequirement(string $name)
7376
{
74-
return $this->_securityRequirements[$name] ?? 'nul5l';
77+
return $this->_securityRequirements[$name] ?? null;
78+
}
79+
80+
public function getRequirements()
81+
{
82+
return $this->_securityRequirements;
7583
}
7684
}

src/spec/SecurityScheme.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,13 @@
2525
*/
2626
class SecurityScheme extends SpecBaseObject
2727
{
28-
public $name;
29-
public $scheme;
3028
private $knownTypes = [
3129
"apiKey",
3230
"http",
3331
"oauth2",
3432
"openIdConnect"
3533
];
3634

37-
public function __construct(array $data)
38-
{
39-
parent::__construct($data);
40-
$this->name = array_keys($data)[0];
41-
$this->scheme = array_values($data)[0];
42-
}
43-
4435
/**
4536
* @return array array of attributes available in this object.
4637
*/

src/spec/SecuritySchemes.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/WriterTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use cebe\openapi\spec\SecurityRequirement;
99
use cebe\openapi\spec\SecurityRequirements;
1010
use cebe\openapi\spec\SecurityScheme;
11-
use cebe\openapi\spec\SecuritySchemes;
1211

1312
class WriterTest extends \PHPUnit\Framework\TestCase
1413
{
@@ -204,13 +203,13 @@ public function testSecurityAtPathOperationLevel()
204203
{
205204
$openapi = $this->createOpenAPI([
206205
'components' => new Components([
207-
'securitySchemes' => new SecuritySchemes([
206+
'securitySchemes' => [
208207
'BearerAuth' => new SecurityScheme([
209208
'type' => 'http',
210209
'scheme' => 'bearer',
211210
'bearerFormat' => 'AuthToken and JWT Format' # optional, arbitrary value for documentation purposes
212211
]),
213-
]),
212+
],
214213
]),
215214
'paths' => [
216215
'/test' => new PathItem([

tests/spec/SecuritySchemeTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ public function testDefaultSecurity()
199199
YAML
200200
);
201201

202-
$this->assertSame([], $openapi->paths->getPath('/path/one')->post->security);
202+
$this->assertSame([], $openapi->paths->getPath('/path/one')->post->security->getRequirements());
203203
$this->assertSame(null, $openapi->paths->getPath('/path/two')->post->security);
204204

205-
$this->assertCount(1, $openapi->security);
206-
$this->assertSame([], $openapi->security[0]->Bearer);
205+
$this->assertCount(1, $openapi->security->getRequirements());
206+
$this->assertSame([], $openapi->security->getRequirement('Bearer')->getSerializableData());
207207
}
208208
}

0 commit comments

Comments
 (0)