File tree Expand file tree Collapse file tree 5 files changed +33
-2
lines changed Expand file tree Collapse file tree 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
484484 {
485485 return $ this ->_jsonPointer ;
486486 }
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+ }
487504}
Original file line number Diff line number Diff line change @@ -190,6 +190,12 @@ public function resolveReferences(ReferenceContext $context = null)
190190 }
191191 }
192192 }
193+
194+ if ($ pathItem instanceof SpecBaseObject) {
195+ foreach ($ pathItem ->getExtensions () as $ extensionKey => $ extension ) {
196+ $ this ->{$ extensionKey } = $ extension ;
197+ }
198+ }
193199 }
194200 parent ::resolveReferences ($ context );
195201 }
Original file line number Diff line number Diff line change @@ -137,7 +137,7 @@ public function testInvalidPath()
137137 public function testPathItemReference ()
138138 {
139139 $ file = __DIR__ . '/data/paths/openapi.yaml ' ;
140- /** @var $openapi OpenApi */
140+ /** @var $openapi \cebe\openapi\spec\ OpenApi */
141141 $ openapi = Reader::readFromYamlFile ($ file , \cebe \openapi \spec \OpenApi::class, false );
142142
143143 $ result = $ openapi ->validate ();
@@ -147,6 +147,10 @@ public function testPathItemReference()
147147 $ this ->assertInstanceOf (Paths::class, $ openapi ->paths );
148148 $ this ->assertInstanceOf (PathItem::class, $ fooPath = $ openapi ->paths ['/foo ' ]);
149149 $ this ->assertInstanceOf (PathItem::class, $ barPath = $ openapi ->paths ['/bar ' ]);
150+ $ this ->assertSame ([
151+ 'x-extension-1 ' => 'Extension1 ' ,
152+ 'x-extension-2 ' => 'Extension2 '
153+ ], $ openapi ->getExtensions ());
150154
151155 $ this ->assertEmpty ($ fooPath ->getOperations ());
152156 $ this ->assertEmpty ($ barPath ->getOperations ());
Original file line number Diff line number Diff line change @@ -508,7 +508,7 @@ enum:
508508 /something:
509509 get:
510510 responses:
511- 200:
511+ ' 200' :
512512 description: 'OK if common params can be references'
513513 parameters:
514514 -
Original file line number Diff line number Diff line change @@ -3,6 +3,10 @@ openapi: 3.0.2
33info :
44 title : My API
55 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
610paths :
711 /foo :
812 $ref : ' path-items.yaml#/~1foo'
You can’t perform that action at this time.
0 commit comments