Skip to content

Commit

Permalink
Merge pull request geraintluff#2 from jdesrosiers/fix-normalize-schema
Browse files Browse the repository at this point in the history
Fix normali[sz]eSchema when schema is an array
  • Loading branch information
geraintluff committed Jan 15, 2014
2 parents 342deae + 4c069ce commit fea6b47
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 4 additions & 4 deletions schema-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function add($url, $schema, $trusted=FALSE) {
$trustBase = $trustBase[0];

$this->schemas[$url] =& $schema;
$this->normaliseSchema($url, $schema, $trusted ? TRUE : $trustBase);
$this->normalizeSchema($url, $schema, $trusted ? TRUE : $trustBase);
if ($fragment == "") {
$this->schemas[$baseUrl] = $schema;
}
Expand All @@ -137,7 +137,7 @@ public function add($url, $schema, $trusted=FALSE) {
}
}

private function normaliseSchema($url, &$schema, $trustPrefix) {
private function normalizeSchema($url, &$schema, $trustPrefix) {
if (is_array($schema) && !self::isNumericArray($schema)) {
$schema = (object)$schema;
}
Expand Down Expand Up @@ -168,12 +168,12 @@ private function normaliseSchema($url, &$schema, $trustPrefix) {
}
foreach ($schema as $key => &$value) {
if ($key != "enum") {
self::normaliseSchema($url, $value, $trustPrefix);
self::normalizeSchema($url, $value, $trustPrefix);
}
}
} else if (is_array($schema)) {
foreach ($schema as &$value) {
self::normaliseSchema($value);
self::normalizeSchema($url, $value, $trustPrefix);
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions tests/03 - schema store/03 - references.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@

$otherSchema = json_decode('{
"title": "Somewhere else",
"items": {"$ref": "'.$urlBase."test-schema-2".'"}
"items": [
{"$ref": "'.$urlBase."test-schema-2".'"}
]
}');
$store->add($urlBase."somewhere-else", $otherSchema);
$fooSchema = $schema->properties->foo;
Expand All @@ -54,7 +56,7 @@
if ($fooSchema->title != "Somewhere else") {
throw new Exception('$ref does not point to correct place');
}
if ($fooSchema->items->title != "Test schema 2") {
if ($fooSchema->items[0]->title != "Test schema 2") {
throw new Exception('$ref in somewhere-else was not resolved');
}
if (count($store->missing())) {
Expand Down

0 comments on commit fea6b47

Please sign in to comment.