Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions v-api/src/context/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ where

pub fn validate(&self, value: &Value) -> bool {
match &self.engine {
Some(engine) => engine.validate_mapping_data(value),
None => false,
Some(engine) => {
tracing::trace!(?value, "Validating mapping rule");
engine.validate_mapping_data(value)
}
None => {
tracing::warn!("No mapping rule is installed to validate rules");
false
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion v-api/src/mapper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::{collections::BTreeSet, error::Error as StdError, fmt::Debug};
use tap::TapFallible;
use thiserror::Error;
use v_model::{
AccessGroupId, Mapper,
Expand Down Expand Up @@ -138,6 +139,10 @@ where
}

fn validate_mapping_data(&self, value: &Value) -> bool {
serde_json::from_value::<MappingRulesData<T>>(value.clone()).is_ok()
serde_json::from_value::<MappingRulesData<T>>(value.clone())
.tap_err(|err| {
tracing::warn!(?value, ?err, "Failed to parse mapping rule");
})
.is_ok()
}
}
Loading