Description
Data type map does not work as expected when all fields are optional and I submit empty array for validation. See steps to reproduce for more details. I expected that this will be valid.
Steps to reproduce
If I will use following schema for validator:
$schema = [
'type' => 'map',
'properties' => [
'test' => [
'enum' => [
"val1",
true,
"415646",
],
'optional' => true,
],
],
];
$validator = new Validator($schema);
and then call
$res = $schema->validate([]);
var_dump($res->getErrors());
I will get "Wrong data type in '/'; expected 'map'; got 'array'"
Suggested fix
- Update
Validator::validate to handle empty array as map as well as array
- use
oneOf directive over schema (have not tried).
First approach makes more sence for me.
PS: I can fix this issue and propose PR to schematicon/validator-php repo. This PR will come probably in next week if approved
Description
Data type
mapdoes not work as expected when all fields are optional and I submit empty array for validation. See steps to reproduce for more details. I expected that this will be valid.Steps to reproduce
If I will use following schema for validator:
and then call
I will get
"Wrong data type in '/'; expected 'map'; got 'array'"Suggested fix
Validator::validateto handle empty array as map as well as arrayoneOfdirective over schema (have not tried).First approach makes more sence for me.
PS: I can fix this issue and propose PR to schematicon/validator-php repo. This PR will come probably in next week if approved