File tree Expand file tree Collapse file tree 3 files changed +62
-8
lines changed Expand file tree Collapse file tree 3 files changed +62
-8
lines changed Original file line number Diff line number Diff line change 2525 */
2626class SecurityScheme extends SpecBaseObject
2727{
28+ public $ name ;
29+ public $ scheme ;
2830 private $ knownTypes = [
2931 "apiKey " ,
3032 "http " ,
3133 "oauth2 " ,
3234 "openIdConnect "
3335 ];
3436
37+ public function __construct (array $ data )
38+ {
39+ parent ::__construct ($ data );
40+ $ this ->name = array_keys ($ data )[0 ];
41+ $ this ->scheme = array_values ($ data )[0 ];
42+ }
43+
3544 /**
3645 * @return array array of attributes available in this object.
3746 */
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * @copyright Copyright (c) 2018 Carsten Brandt <mail@cebe.cc> and contributors
5+ * @license https://github.com/cebe/php-openapi/blob/master/LICENSE
6+ */
7+
8+ namespace cebe \openapi \spec ;
9+
10+ use cebe \openapi \SpecBaseObject ;
11+
12+ class SecuritySchemes extends SpecBaseObject
13+ {
14+ private $ _securitySchemes = [];
15+
16+ public function __construct (array $ data )
17+ {
18+ parent ::__construct ($ data );
19+ $ this ->_securitySchemes = $ data ;
20+ }
21+
22+ protected function attributes (): array
23+ {
24+ return [];
25+ }
26+
27+ public function performValidation ()
28+ {
29+ }
30+
31+ /**
32+ * @return mixed returns the serializable data of this object for converting it
33+ * to JSON or YAML.
34+ */
35+ public function getSerializableData ()
36+ {
37+ $ data = [];
38+ foreach ($ this ->_securitySchemes as $ securityScheme ) {
39+ /** @var $securityScheme SecurityScheme */
40+ $ data [$ securityScheme ->name ] = $ securityScheme ->scheme ;
41+ }
42+ return (object ) $ data ;
43+ }
44+ }
Original file line number Diff line number Diff line change 11<?php
22
33use cebe \openapi \spec \Components ;
4- use cebe \openapi \spec \OpenApi ;
54use cebe \openapi \spec \Operation ;
65use cebe \openapi \spec \PathItem ;
76use cebe \openapi \spec \Response ;
87use cebe \openapi \spec \Responses ;
98use cebe \openapi \spec \SecurityRequirement ;
10- use cebe \openapi \spec \SecurityRequirements ;
119use cebe \openapi \spec \SecurityScheme ;
10+ use cebe \openapi \spec \SecuritySchemes ;
1211
1312class WriterTest extends \PHPUnit \Framework \TestCase
1413{
@@ -200,13 +199,15 @@ public function testSecurityAtPathOperationLevel()
200199 {
201200 $ openapi = $ this ->createOpenAPI ([
202201 'components ' => new Components ([
203- 'securitySchemes ' => [
204- 'BearerAuth ' => new SecurityScheme ([
205- 'type ' => 'http ' ,
206- 'scheme ' => 'bearer ' ,
207- 'bearerFormat ' => 'AuthToken and JWT Format ' # optional, arbitrary value for documentation purposes
202+ 'securitySchemes ' => new SecuritySchemes ([
203+ new SecurityScheme ([
204+ 'BearerAuth ' => [
205+ 'type ' => 'http ' ,
206+ 'scheme ' => 'bearer ' ,
207+ 'bearerFormat ' => 'AuthToken and JWT Format ' # optional, arbitrary value for documentation purposes
208+ ]
208209 ])
209- ],
210+ ]) ,
210211 ]),
211212 'paths ' => [
212213 '/test ' => new PathItem ([
You can’t perform that action at this time.
0 commit comments