use serde::Serialize;
#[cfg(feature = "openapi")]
use utoipa::ToSchema;
#[derive(serde::Deserialize, Serialize, Clone, Debug)]
#[cfg_attr(feature = "openapi", derive(ToSchema))]
#[serde(tag = "type")]
pub enum ValidationRules {
#[cfg_attr(feature = "openapi", schema(title = "StringHandler"))]
StringHandler {
max_length: Option<usize>,
required: bool,
},
#[cfg_attr(feature = "openapi", schema(title = "DateHandler"))]
DateHandler {
canonical_format: String,
required: bool,
},
#[cfg_attr(feature = "openapi", schema(title = "EnumHandler"))]
EnumHandler { values: Vec<String>, required: bool },
#[cfg_attr(feature = "openapi", schema(title = "ExpverHandler"))]
ExpverHandler {
default: Option<String>,
required: bool,
},
#[cfg_attr(feature = "openapi", schema(title = "IntHandler"))]
IntHandler {
range: Option<[i64; 2]>,
required: bool,
},
#[cfg_attr(feature = "openapi", schema(title = "FloatHandler"))]
FloatHandler {
range: Option<[f64; 2]>,
required: bool,
},
#[cfg_attr(feature = "openapi", schema(title = "TimeHandler"))]
TimeHandler { required: bool },
#[cfg_attr(feature = "openapi", schema(title = "PolygonHandler"))]
PolygonHandler { required: bool },
}
impl ValidationRules {
pub fn is_required(&self) -> bool {
match self {
ValidationRules::StringHandler { required, .. } => *required,
ValidationRules::DateHandler { required, .. } => *required,
ValidationRules::EnumHandler { required, .. } => *required,
ValidationRules::ExpverHandler { required, .. } => *required,
ValidationRules::IntHandler { required, .. } => *required,
ValidationRules::FloatHandler { required, .. } => *required,
ValidationRules::TimeHandler { required } => *required,
ValidationRules::PolygonHandler { required } => *required,
}
}
}