From 590dd903122ed60bd4b7733de91539b3312cc8ab Mon Sep 17 00:00:00 2001 From: Siad Ardroumli Date: Mon, 4 May 2020 20:13:13 +0200 Subject: [PATCH] Fixed schema validation for defaults --- lib/avro/schema.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/avro/schema.php b/lib/avro/schema.php index 3b4bbcd..24c9d59 100644 --- a/lib/avro/schema.php +++ b/lib/avro/schema.php @@ -459,9 +459,11 @@ public static function is_valid_datum($expected_schema, $datum) case self::REQUEST_SCHEMA: if (is_array($datum)) { - foreach ($expected_schema->fields() as $field) - if (!array_key_exists($field->name(), $datum) || !self::is_valid_datum($field->type(), $datum[$field->name()])) - return false; + foreach ($expected_schema->fields() as $field) { + $value = isset($datum[$field->name()]) ? $datum[$field->name()] : $field->default_value(); + if (!self::is_valid_datum($field->type(), $value)) + return false; + } return true; } return false;