pub struct ConditionalRequiredValidator;Expand description
Validates conditional requirement: if one field is present, others must be too.
§Example
use fraiseql_core::validation::mutual_exclusivity::ConditionalRequiredValidator;
use serde_json::json;
// If isPremium is true, then paymentMethod is required
let input = json!({ "isPremium": true, "paymentMethod": "credit_card" });
assert!(
ConditionalRequiredValidator::validate(&input, "isPremium", &["paymentMethod".to_string()], None).is_ok(),
"conditional requirement satisfied when condition field is true and required field present"
);Implementations§
Source§impl ConditionalRequiredValidator
impl ConditionalRequiredValidator
Sourcepub fn validate(
input: &Value,
if_field_present: &str,
then_required: &[String],
context_path: Option<&str>,
) -> Result<()>
pub fn validate( input: &Value, if_field_present: &str, then_required: &[String], context_path: Option<&str>, ) -> Result<()>
Validate that if if_field_present is present, all then_required fields must be too.
§Errors
Returns FraiseQLError::Validation if the condition field is present but any
required field is missing.
Auto Trait Implementations§
impl Freeze for ConditionalRequiredValidator
impl RefUnwindSafe for ConditionalRequiredValidator
impl Send for ConditionalRequiredValidator
impl Sync for ConditionalRequiredValidator
impl Unpin for ConditionalRequiredValidator
impl UnsafeUnpin for ConditionalRequiredValidator
impl UnwindSafe for ConditionalRequiredValidator
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more