Skip to content

Commit 16c20be

Browse files
committed
[openapi v3.1] Preserve property item keys
This is mainly useful when dealing with webhooks to use the array index as a name for the given webhook as the spec uses it as a unique identifier: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object
1 parent 684aac0 commit 16c20be

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/SpecBaseObject.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)