diff --git a/src/core/jit/synth/synth.rs b/src/core/jit/synth/synth.rs index 629122fb5b..9dc1831ff9 100644 --- a/src/core/jit/synth/synth.rs +++ b/src/core/jit/synth/synth.rs @@ -117,30 +117,20 @@ impl<'a, Value: JsonLike<'a> + Clone + 'a> Synth { } } None => { - // IR exists, so there must be a value. - // if there is no value then we must return Null - Ok(Value::null()) + if node.type_of.is_nullable() || node.ir.is_some() { + // IR exists, so there must be a value. + // if there is no value then we must return Null + Ok(Value::null()) + } else { + Err(ValidationError::ValueRequired.into()) + .map_err(|e| self.to_location_error(e, node)) + } } } } } } - fn validate_field( - &'a self, - node: &'a Field, Value>, - obj: &'a Value::JsonObject, - ) -> Result> { - match obj.get_key(node.name.as_str()) { - Some(val) if val.is_null() && !node.type_of.is_nullable() && node.ir.is_none() => { - Err(self.to_location_error(ValidationError::ValueRequired.into(), node)) - } - Some(val) => Ok(val.to_owned()), - None if node.type_of.is_nullable() || node.ir.is_some() => Ok(Value::null()), - None => Err(self.to_location_error(ValidationError::ValueRequired.into(), node)), - } - } - #[inline(always)] fn iter_inner( &'a self, @@ -200,29 +190,30 @@ impl<'a, Value: JsonLike<'a> + Clone + 'a> Synth { self.iter_inner(child, val, data_path)?, ); } else { - let result = self.iter(child, None, data_path)?; - // TODO: Refactor to use `result.is_null()` when lifetime - // issues are resolved - let _null_ty = Value::null(); - let is_response_null = matches!(result.clone(), _null_ty); - if child.type_of.is_nullable() - || !is_response_null - || child.ir.is_some() - { - ans = ans.insert_key(child.name.as_str(), result); - } else { - return Err(ValidationError::ValueRequired.into()) - .map_err(|e| self.to_location_error(e, child)); - } + ans = ans.insert_key( + child.name.as_str(), + self.iter(child, None, data_path)?, + ); } } } } else { - ans = - ans.insert_key(node.name.as_str(), self.validate_field(node, obj)?); + let val = obj.get_key(node.name.as_str()); + // if it's a leaf node, then push the value + if let Some(val) = val { + ans = ans.insert_key(node.name.as_str(), val.to_owned()); + } else { + return Ok(Value::null()); + } } } else { - ans = ans.insert_key(node.name.as_str(), self.validate_field(node, obj)?); + let val = obj.get_key(node.name.as_str()); + // if it's a leaf node, then push the value + if let Some(val) = val { + ans = ans.insert_key(node.name.as_str(), val.to_owned()); + } else { + return Ok(Value::null()); + } } Ok(Value::object(ans)) }