File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,22 +86,22 @@ public function __construct(array $data)
8686 } else {
8787 // array
8888 $ this ->_properties [$ property ] = [];
89- foreach ($ data [$ property ] as $ item ) {
89+ foreach ($ data [$ property ] as $ key => $ item ) {
9090 if ($ type [0 ] === Type::STRING ) {
9191 if (!is_string ($ item )) {
9292 $ this ->_errors [] = "property ' $ property' must be array of strings, but array has " . gettype ($ item ) . " element. " ;
9393 }
94- $ this ->_properties [$ property ][] = $ item ;
94+ $ this ->_properties [$ property ][$ key ] = $ item ;
9595 } elseif (Type::isScalar ($ type [0 ])) {
96- $ this ->_properties [$ property ][] = $ item ;
96+ $ this ->_properties [$ property ][$ key ] = $ item ;
9797 } elseif ($ type [0 ] === Type::ANY ) {
9898 if (is_array ($ item ) && isset ($ item ['$ref ' ])) {
99- $ this ->_properties [$ property ][] = new Reference ($ item , null );
99+ $ this ->_properties [$ property ][$ key ] = new Reference ($ item , null );
100100 } else {
101- $ this ->_properties [$ property ][] = $ item ;
101+ $ this ->_properties [$ property ][$ key ] = $ item ;
102102 }
103103 } else {
104- $ this ->_properties [$ property ][] = $ this ->instantiate ($ type [0 ], $ item );
104+ $ this ->_properties [$ property ][$ key ] = $ this ->instantiate ($ type [0 ], $ item );
105105 }
106106 }
107107 }
Original file line number Diff line number Diff line change @@ -420,4 +420,31 @@ public function testPropertyNameRef()
420420 $ this ->assertEquals ('string ' , $ person ->properties ['name ' ]->type );
421421 $ this ->assertEquals ('string ' , $ person ->properties ['$ref ' ]->type );
422422 }
423+
424+ public function testArrayKeyIsPerseveredInPropertiesThatAreArrays ()
425+ {
426+ $ json = <<<'JSON'
427+ {
428+ "webhooks": {
429+ "branch-protection-rule-created": {
430+ "post": {
431+ "description": "A branch protection rule was created.",
432+ "requestBody": {
433+ "required": true,
434+ "content": {
435+ "application/json": {
436+ "schema": {
437+ "type": "string"
438+ }
439+ }
440+ }
441+ }
442+ }
443+ }
444+ }
445+ }
446+ JSON;
447+ $ openApi = Reader::readFromJson ($ json );
448+ self ::assertArrayHasKey ('branch-protection-rule-created ' , $ openApi ->webhooks );
449+ }
423450}
You can’t perform that action at this time.
0 commit comments