Skip to content

Commit

Permalink
Merge pull request #47 from localheinz/fix/one-of-has-reference
Browse files Browse the repository at this point in the history
Fix: Resolve referenced schema in oneOf combination
  • Loading branch information
localheinz authored Feb 15, 2018
2 parents 432ccef + c91a39b commit 39c3a43
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/SchemaNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ private function resolveSchema($data, \stdClass $schema): \stdClass
if (\property_exists($schema, 'oneOf') && \is_array($schema->oneOf)) {
foreach ($schema->oneOf as $oneOfSchema) {
if ($this->schemaValidator->isValid($data, $oneOfSchema)) {
return $oneOfSchema;
return $this->resolveSchema(
$data,
$oneOfSchema
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"type": "Website",
"url": "https://localheinz.com"
},
"https://github.com/localheinz",
{
"type": "Twitter",
"url": "https://twitter.com/localheinz"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"url": "https://localheinz.com",
"type": "Website"
},
"https://github.com/localheinz",
{
"url": "https://twitter.com/localheinz",
"type": "Twitter"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/definitions/url-object"
},
{
"$ref": "#/definitions/url-string"
}
]
},
"definitions": {
"url-object": {
"type": "object",
"additionalProperties": false,
"properties": {
"type": {
"type": "string"
},
"url": {
"type": "string"
}
}
},
"url-string": {
"type": "string"
}
}
}

0 comments on commit 39c3a43

Please sign in to comment.