File tree 5 files changed +33
-2
lines changed
5 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -484,4 +484,21 @@ public function getDocumentPosition(): ?JsonPointer
484
484
{
485
485
return $ this ->_jsonPointer ;
486
486
}
487
+
488
+ /**
489
+ * Handle extension properties with `x-` prefix.
490
+ * See https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#specificationExtensions
491
+ * @return array<string, mixed>
492
+ */
493
+ public function getExtensions (): array
494
+ {
495
+ $ extensions = [];
496
+ foreach ($ this ->_properties as $ propertyKey => $ extension ) {
497
+ if (mb_strpos ($ propertyKey , 'x- ' ) !== 0 ) {
498
+ continue ;
499
+ }
500
+ $ extensions [$ propertyKey ] = $ extension ;
501
+ }
502
+ return $ extensions ;
503
+ }
487
504
}
Original file line number Diff line number Diff line change @@ -190,6 +190,12 @@ public function resolveReferences(ReferenceContext $context = null)
190
190
}
191
191
}
192
192
}
193
+
194
+ if ($ pathItem instanceof SpecBaseObject) {
195
+ foreach ($ pathItem ->getExtensions () as $ extensionKey => $ extension ) {
196
+ $ this ->{$ extensionKey } = $ extension ;
197
+ }
198
+ }
193
199
}
194
200
parent ::resolveReferences ($ context );
195
201
}
Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ public function testInvalidPath()
137
137
public function testPathItemReference ()
138
138
{
139
139
$ file = __DIR__ . '/data/paths/openapi.yaml ' ;
140
- /** @var $openapi OpenApi */
140
+ /** @var $openapi \cebe\openapi\spec\ OpenApi */
141
141
$ openapi = Reader::readFromYamlFile ($ file , \cebe \openapi \spec \OpenApi::class, false );
142
142
143
143
$ result = $ openapi ->validate ();
@@ -147,6 +147,10 @@ public function testPathItemReference()
147
147
$ this ->assertInstanceOf (Paths::class, $ openapi ->paths );
148
148
$ this ->assertInstanceOf (PathItem::class, $ fooPath = $ openapi ->paths ['/foo ' ]);
149
149
$ this ->assertInstanceOf (PathItem::class, $ barPath = $ openapi ->paths ['/bar ' ]);
150
+ $ this ->assertSame ([
151
+ 'x-extension-1 ' => 'Extension1 ' ,
152
+ 'x-extension-2 ' => 'Extension2 '
153
+ ], $ openapi ->getExtensions ());
150
154
151
155
$ this ->assertEmpty ($ fooPath ->getOperations ());
152
156
$ this ->assertEmpty ($ barPath ->getOperations ());
Original file line number Diff line number Diff line change @@ -508,7 +508,7 @@ enum:
508
508
/something:
509
509
get:
510
510
responses:
511
- 200:
511
+ ' 200' :
512
512
description: 'OK if common params can be references'
513
513
parameters:
514
514
-
Original file line number Diff line number Diff line change @@ -3,6 +3,10 @@ openapi: 3.0.2
3
3
info :
4
4
title : My API
5
5
version : 1.0.0
6
+ x-extension-1 : Extension1
7
+ x-extension-2 : Extension2
8
+ X-EXTENSION : Invalid because of Uppercase X-
9
+ xyz-extension : invalid extension
6
10
paths :
7
11
/foo :
8
12
$ref : ' path-items.yaml#/~1foo'
You can’t perform that action at this time.
0 commit comments