Skip to content

Ensure semantics of empty array and null are correctly presented #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2019
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);
}
}