protected function checkProperty($element, Property $schema)
{
$propertyName = $schema->getObjectName();
//TODO:ape: check element don't empty because pagination type is string AND default is NULL
if (!empty($element)) {
switch ($schema->type) {
case 'string':
$error = !is_string($element);
break;
case 'integer':
$error = !is_numeric($element);
break;
case 'boolean':
$error = !(is_bool($element) || 1 == $element || 0 == $element);
break;
case 'array':
$error = !is_array($element);
break;
default:
$error = false;
}
if ($error) {
$this->appendError($propertyName, sprintf('This type is\'t not consistency with Api. Type should be %s.', $schema->type));
}
}
if (isset($schema->enum)) {
if ($schema->getObjectName() == 'builtinAutomation' && empty(static::$ignoreEnumVal['builtinAutomation'])) {
static::$ignoreEnumVal['builtinAutomation'] = array_merge([null], array_flip(ROLE_BEHAVIORS::GetName(null, true)));
}
$enumVal = $schema->enum;
if (isset(static::$ignoreEnumVal[$propertyName])) {
$enumVal = array_merge($enumVal, static::$ignoreEnumVal[$propertyName]);
}
// check enum properties
if (!in_array($element, $enumVal)) {
$this->appendError($propertyName, sprintf('[%s] is not valid allowed value %s %s.', $element, ...count($schema->enum) === 1 ? ['is', array_shift($schema->enum)] : ['are', implode(', ', $schema->enum)]));
}
}
}