Skip to content

Commit

Permalink
only allow $ref in array, a map may have a $ref property
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Dec 4, 2019
1 parent fc0cee6 commit 0158fec
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
41 changes: 20 additions & 21 deletions src/SpecBaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,31 +73,30 @@ public function __construct(array $data)
$this->_errors[] = "property '$property' must be array, but " . gettype($data[$property]) . " given.";
continue;
}
if (isset($data[$property]['$ref'])) {
$this->_properties[$property] = new Reference($data[$property], null);
unset($data[$property]);
continue;
}
switch (\count($type)) {
case 1:
// array
$this->_properties[$property] = [];
foreach ($data[$property] as $item) {
if ($type[0] === Type::STRING) {
if (!is_string($item)) {
$this->_errors[] = "property '$property' must be array of strings, but array has " . gettype($item) . " element.";
}
$this->_properties[$property][] = $item;
} elseif (Type::isScalar($type[0])) {
$this->_properties[$property][] = $item;
} elseif ($type[0] === Type::ANY) {
if (is_array($item) && isset($item['$ref'])) {
$this->_properties[$property][] = new Reference($item, null);
} else {
if (isset($data[$property]['$ref'])) {
$this->_properties[$property] = new Reference($data[$property], null);
} else {
// array
$this->_properties[$property] = [];
foreach ($data[$property] as $item) {
if ($type[0] === Type::STRING) {
if (!is_string($item)) {
$this->_errors[] = "property '$property' must be array of strings, but array has " . gettype($item) . " element.";
}
$this->_properties[$property][] = $item;
} elseif (Type::isScalar($type[0])) {
$this->_properties[$property][] = $item;
} elseif ($type[0] === Type::ANY) {
if (is_array($item) && isset($item['$ref'])) {
$this->_properties[$property][] = new Reference($item, null);
} else {
$this->_properties[$property][] = $item;
}
} else {
$this->_properties[$property][] = $this->instantiate($type[0], $item);
}
} else {
$this->_properties[$property][] = $this->instantiate($type[0], $item);
}
}
break;
Expand Down
5 changes: 4 additions & 1 deletion tests/spec/OpenApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ public function specProvider()
$nexmoExamples
);
foreach($all as $path) {
yield [substr($path, strlen(__DIR__ . '/../../vendor/')), basename($path)];
yield [
substr($path, strlen(__DIR__ . '/../../vendor/')),
basename(dirname($path, 2)) . DIRECTORY_SEPARATOR . basename(dirname($path, 1)) . DIRECTORY_SEPARATOR . basename($path)
];
}
}

Expand Down

0 comments on commit 0158fec

Please sign in to comment.