Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/spec/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
35 changes: 35 additions & 0 deletions tests/spec/SecuritySchemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,39 @@ public function testSecurityRequirement()

$this->assertSame(['write:pets', 'read:pets'], $securityRequirement->petstore_auth);
}

public function testDefaultSecurity()
{
$openapi = Reader::readFromYaml(<<<YAML
paths:
/path/one:
post:
description: path one
# [...]
security: [] # default security

/path/two:
post:
description: path two
# [...]
# No security entry defined there

components:
securitySchemes:
Bearer:
type: http
scheme: bearer
bearerFormat: JWT

security:
- Bearer: []
YAML
);

$this->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);
}
}