Skip to content

Commit 9ee5be9

Browse files
committed
only allow $ref in array, a map may have a $ref property
1 parent e9521ee commit 9ee5be9

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

src/SpecBaseObject.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,30 @@ public function __construct(array $data)
7373
$this->_errors[] = "property '$property' must be array, but " . gettype($data[$property]) . " given.";
7474
continue;
7575
}
76-
if (isset($data[$property]['$ref'])) {
77-
$this->_properties[$property] = new Reference($data[$property], null);
78-
unset($data[$property]);
79-
continue;
80-
}
8176
switch (\count($type)) {
8277
case 1:
83-
// array
84-
$this->_properties[$property] = [];
85-
foreach ($data[$property] as $item) {
86-
if ($type[0] === Type::STRING) {
87-
if (!is_string($item)) {
88-
$this->_errors[] = "property '$property' must be array of strings, but array has " . gettype($item) . " element.";
89-
}
90-
$this->_properties[$property][] = $item;
91-
} elseif (Type::isScalar($type[0])) {
92-
$this->_properties[$property][] = $item;
93-
} elseif ($type[0] === Type::ANY) {
94-
if (is_array($item) && isset($item['$ref'])) {
95-
$this->_properties[$property][] = new Reference($item, null);
96-
} else {
78+
if (isset($data[$property]['$ref'])) {
79+
$this->_properties[$property] = new Reference($data[$property], null);
80+
} else {
81+
// array
82+
$this->_properties[$property] = [];
83+
foreach ($data[$property] as $item) {
84+
if ($type[0] === Type::STRING) {
85+
if (!is_string($item)) {
86+
$this->_errors[] = "property '$property' must be array of strings, but array has " . gettype($item) . " element.";
87+
}
88+
$this->_properties[$property][] = $item;
89+
} elseif (Type::isScalar($type[0])) {
9790
$this->_properties[$property][] = $item;
91+
} elseif ($type[0] === Type::ANY) {
92+
if (is_array($item) && isset($item['$ref'])) {
93+
$this->_properties[$property][] = new Reference($item, null);
94+
} else {
95+
$this->_properties[$property][] = $item;
96+
}
97+
} else {
98+
$this->_properties[$property][] = $this->instantiate($type[0], $item);
9899
}
99-
} else {
100-
$this->_properties[$property][] = $this->instantiate($type[0], $item);
101100
}
102101
}
103102
break;

tests/spec/OpenApiTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ public function specProvider()
171171
$nexmoExamples
172172
);
173173
foreach($all as $path) {
174-
yield [substr($path, strlen(__DIR__ . '/../../vendor/')), basename($path)];
174+
yield [
175+
substr($path, strlen(__DIR__ . '/../../vendor/')),
176+
basename(dirname($path, 2)) . DIRECTORY_SEPARATOR . basename(dirname($path, 1)) . DIRECTORY_SEPARATOR . basename($path)
177+
];
175178
}
176179
}
177180

0 commit comments

Comments
 (0)