pub struct RequiredIfAbsentValidator;Expand description
Validates conditional requirement based on absence: if one field is missing, others must be provided.
§Example
use fraiseql_core::validation::mutual_exclusivity::RequiredIfAbsentValidator;
use serde_json::json;
// If addressId is not provided, then street, city, zip must all be provided
let input = json!({ "addressId": null, "street": "123 Main St", "city": "Springfield", "zip": "12345" });
assert!(
RequiredIfAbsentValidator::validate(&input, "addressId", &["street".to_string(), "city".to_string(), "zip".to_string()], None).is_ok(),
"required-if-absent constraint satisfied when absent field is null and all required fields present"
);Implementations§
Source§impl RequiredIfAbsentValidator
impl RequiredIfAbsentValidator
Sourcepub fn validate(
input: &Value,
absent_field: &str,
then_required: &[String],
context_path: Option<&str>,
) -> Result<()>
pub fn validate( input: &Value, absent_field: &str, then_required: &[String], context_path: Option<&str>, ) -> Result<()>
Validate that if absent_field is absent/null, all then_required fields must be provided.
§Errors
Returns FraiseQLError::Validation if the condition field is absent and any
required field is also missing.
Auto Trait Implementations§
impl Freeze for RequiredIfAbsentValidator
impl RefUnwindSafe for RequiredIfAbsentValidator
impl Send for RequiredIfAbsentValidator
impl Sync for RequiredIfAbsentValidator
impl Unpin for RequiredIfAbsentValidator
impl UnsafeUnpin for RequiredIfAbsentValidator
impl UnwindSafe for RequiredIfAbsentValidator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more