diff --git a/src/spec/Operation.php b/src/spec/Operation.php index d8b177a7..6ef76a08 100644 --- a/src/spec/Operation.php +++ b/src/spec/Operation.php @@ -51,6 +51,13 @@ protected function attributes(): array ]; } + protected function attributeDefaults(): array + { + return [ + 'security' => null, + ]; + } + /** * Perform validation on this object, check data against OpenAPI Specification rules. * diff --git a/tests/spec/SecuritySchemeTest.php b/tests/spec/SecuritySchemeTest.php index 6d4c9025..5e14d5f7 100644 --- a/tests/spec/SecuritySchemeTest.php +++ b/tests/spec/SecuritySchemeTest.php @@ -170,4 +170,39 @@ public function testSecurityRequirement() $this->assertSame(['write:pets', 'read:pets'], $securityRequirement->petstore_auth); } + + public function testDefaultSecurity() + { + $openapi = Reader::readFromYaml(<<assertSame([], $openapi->paths->getPath('/path/one')->post->security); + $this->assertSame(null, $openapi->paths->getPath('/path/two')->post->security); + + $this->assertCount(1, $openapi->security); + $this->assertSame([], $openapi->security[0]->Bearer); + } }