Skip to content

Commit 371b1df

Browse files
authored
Merge pull request #38 from cebe/fix-security-semantics
Ensure semantics of empty array and null are correctly presented
2 parents 6189637 + cce8383 commit 371b1df

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/spec/Operation.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ protected function attributes(): array
5151
];
5252
}
5353

54+
protected function attributeDefaults(): array
55+
{
56+
return [
57+
'security' => null,
58+
];
59+
}
60+
5461
/**
5562
* Perform validation on this object, check data against OpenAPI Specification rules.
5663
*

tests/spec/SecuritySchemeTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,39 @@ public function testSecurityRequirement()
170170

171171
$this->assertSame(['write:pets', 'read:pets'], $securityRequirement->petstore_auth);
172172
}
173+
174+
public function testDefaultSecurity()
175+
{
176+
$openapi = Reader::readFromYaml(<<<YAML
177+
paths:
178+
/path/one:
179+
post:
180+
description: path one
181+
# [...]
182+
security: [] # default security
183+
184+
/path/two:
185+
post:
186+
description: path two
187+
# [...]
188+
# No security entry defined there
189+
190+
components:
191+
securitySchemes:
192+
Bearer:
193+
type: http
194+
scheme: bearer
195+
bearerFormat: JWT
196+
197+
security:
198+
- Bearer: []
199+
YAML
200+
);
201+
202+
$this->assertSame([], $openapi->paths->getPath('/path/one')->post->security);
203+
$this->assertSame(null, $openapi->paths->getPath('/path/two')->post->security);
204+
205+
$this->assertCount(1, $openapi->security);
206+
$this->assertSame([], $openapi->security[0]->Bearer);
207+
}
173208
}

0 commit comments

Comments
 (0)