Closed
Description
As pointed out by @madman-81 in #770 and confirmed in #770 (comment) the oneOf
alters the data when type coercion is enabled which ultimatly is correct. However the altered version of $value
is passed to the subsequent subschemas that are part of the oneOf
this can cause failing validation while with the original inputted $value
it might validate.
This can be reproduced by the following:
<?php
namespace Tests\Unit\Validation;
use JsonSchema\Constraints\Constraint;
use JsonSchema\Validator;
use PHPUnit\Framework\TestCase;
class JsonValidateV6Test extends TestCase
{
public function testJsonCompare()
{
$schema = <<<JSON
{
"title": "Location",
"type": "object",
"properties": {
"id": {
"type": "string"
},
"related_locations": {
"oneOf": [
{
"type": "null"
},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"latitude": {
"type": "string"
},
"longitude": {
"type": "string"
}
}
}
}
]
}
}
}
JSON;
$json = <<<JSON
{
"id": "LOC1",
"related_locations": [
{
"latitude": "51.047598",
"longitude": "3.729943"
}
]
}
JSON;
$jsonObj = json_decode($json);
$schemaObj = json_decode($schema);
$jsonSchemaValidation = new Validator();
$jsonSchemaValidation->validate($jsonObj, $schemaObj, Constraint::CHECK_MODE_COERCE_TYPES);
$this->assertTrue($jsonSchemaValidation->isValid());
}
}
Metadata
Metadata
Assignees
Labels
No labels