-
Notifications
You must be signed in to change notification settings - Fork 96
How to use Security and SecurityRequirement #225
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
cebe
merged 27 commits into
cebe:master
from
SOHELAHMED7:how-to-use-security-and-securityrequirement-75
May 7, 2025
Merged
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e33b410
Create PR
SOHELAHMED7 e5751c2
Implementation in progress
SOHELAHMED7 2f65031
In progress...
SOHELAHMED7 0c532a7
Remove comments
SOHELAHMED7 2876e4a
Finish the test
SOHELAHMED7 dc0863c
Changes
SOHELAHMED7 5186b46
Add `SecurityRequirements` class and more
SOHELAHMED7 a455e6e
In Progress
SOHELAHMED7 6fd4971
Apply same changes to other file
SOHELAHMED7 49f1164
Merge branches 'master' and 'how-to-use-security-and-securityrequirem…
SOHELAHMED7 b7c0a6d
Revert changes
SOHELAHMED7 29f5bbb
Change design of SecurityScheme
SOHELAHMED7 b46de76
Complete the implementation
SOHELAHMED7 219813f
Fix failing test
SOHELAHMED7 236a47e
Cleanup and fix issue and complete the implementation
SOHELAHMED7 55f3e1f
Complete the test
SOHELAHMED7 23a5377
Covers SecurityRequirements
SOHELAHMED7 565c183
Put back removed Composer Package
SOHELAHMED7 c1db324
Fix failing tests
SOHELAHMED7 c911987
Fix failing tests 2
SOHELAHMED7 98b3ef3
Fix failing tests 3
SOHELAHMED7 15ef5f6
Add more assertions in tests and refactor
SOHELAHMED7 19e68bf
Add more test
SOHELAHMED7 e8711e1
Resolve TODOs
SOHELAHMED7 29e7095
Merge branch 'master' of github.com:SOHELAHMED7/php-openapi into how-…
SOHELAHMED7 2a66059
Remove redundant method call
SOHELAHMED7 aa73b3d
Remove redundant method call 2
SOHELAHMED7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (c) 2018 Carsten Brandt <[email protected]> and contributors | ||
* @license https://github.com/cebe/php-openapi/blob/master/LICENSE | ||
*/ | ||
|
||
namespace cebe\openapi\spec; | ||
|
||
use cebe\openapi\SpecBaseObject; | ||
|
||
/** | ||
* Lists the required security schemes to execute this operation. | ||
* | ||
* @link https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#securityRequirementObject | ||
* | ||
*/ | ||
class SecurityRequirements extends SpecBaseObject | ||
{ | ||
private $_securityRequirements; | ||
|
||
public function __construct(array $data) | ||
{ | ||
parent::__construct($data); | ||
|
||
foreach ($data as $index => $value) { | ||
if (is_numeric($index)) { // read | ||
$this->_securityRequirements[array_keys($value)[0]] = new SecurityRequirement(array_values($value)[0]); | ||
} else { // write | ||
$this->_securityRequirements[$index] = $value; | ||
} | ||
} | ||
if ($data === []) { | ||
$this->_securityRequirements = []; | ||
} | ||
} | ||
|
||
/** | ||
* @return array array of attributes available in this object. | ||
*/ | ||
protected function attributes(): array | ||
{ | ||
// this object does not have a fixed set of attribute names | ||
return []; | ||
} | ||
|
||
/** | ||
* Perform validation on this object, check data against OpenAPI Specification rules. | ||
* | ||
* Call `addError()` in case of validation errors. | ||
*/ | ||
protected function performValidation() | ||
{ | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getSerializableData() | ||
{ | ||
parent::getSerializableData(); | ||
|
||
$data = []; | ||
foreach ($this->_securityRequirements ?? [] as $name => $securityRequirement) { | ||
/** @var SecurityRequirement $securityRequirement */ | ||
$data[] = [$name => $securityRequirement->getSerializableData()]; | ||
} | ||
return $data; | ||
} | ||
|
||
public function getRequirement(string $name) | ||
{ | ||
return $this->_securityRequirements[$name] ?? null; | ||
} | ||
|
||
public function getRequirements() | ||
{ | ||
return $this->_securityRequirements; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.