cooplan_definition_schema_validator/
validations.rs1use serde_json::Value;
2
3use crate::error::{Error, ErrorKind};
4
5pub fn validate_string(attribute_value: &Value) -> Result<(), Error> {
6 match attribute_value.as_str() {
7 Some(_) => Ok(()),
8 None => Err(Error::new(
9 ErrorKind::InvalidValue,
10 "failed to convert attribute value to string".to_string(),
11 )),
12 }
13}
14
15pub fn validate_integer(attribute_value: &Value) -> Result<(), Error> {
16 match attribute_value.as_i64() {
17 Some(_) => Ok(()),
18 None => Err(Error::new(
19 ErrorKind::InvalidValue,
20 "failed to convert attribute value to integer".to_string(),
21 )),
22 }
23}
24
25pub fn validate_decimal(attribute_value: &Value) -> Result<(), Error> {
26 match attribute_value.as_f64() {
27 Some(_) => Ok(()),
28 None => Err(Error::new(
29 ErrorKind::InvalidValue,
30 "failed to convert attribute value to decimal".to_string(),
31 )),
32 }
33}
34
35pub fn validate_boolean(attribute_value: &Value) -> Result<(), Error> {
36 match attribute_value.as_bool() {
37 Some(_) => Ok(()),
38 None => Err(Error::new(
39 ErrorKind::InvalidValue,
40 "failed to convert attribute value to boolean".to_string(),
41 )),
42 }
43}