aviso_validators/
types.rs1use serde::Serialize;
12#[cfg(feature = "openapi")]
13use utoipa::ToSchema;
14
15#[derive(serde::Deserialize, Serialize, Clone, Debug)]
17#[cfg_attr(feature = "openapi", derive(ToSchema))]
18#[serde(tag = "type")]
19pub enum ValidationRules {
20 #[cfg_attr(feature = "openapi", schema(title = "StringHandler"))]
22 StringHandler {
23 max_length: Option<usize>,
24 required: bool,
25 },
26 #[cfg_attr(feature = "openapi", schema(title = "DateHandler"))]
28 DateHandler {
29 canonical_format: String,
30 required: bool,
31 },
32 #[cfg_attr(feature = "openapi", schema(title = "EnumHandler"))]
34 EnumHandler { values: Vec<String>, required: bool },
35 #[cfg_attr(feature = "openapi", schema(title = "ExpverHandler"))]
37 ExpverHandler {
38 default: Option<String>,
39 required: bool,
40 },
41 #[cfg_attr(feature = "openapi", schema(title = "IntHandler"))]
43 IntHandler {
44 range: Option<[i64; 2]>,
45 required: bool,
46 },
47 #[cfg_attr(feature = "openapi", schema(title = "FloatHandler"))]
49 FloatHandler {
50 range: Option<[f64; 2]>,
51 required: bool,
52 },
53 #[cfg_attr(feature = "openapi", schema(title = "TimeHandler"))]
55 TimeHandler { required: bool },
56 #[cfg_attr(feature = "openapi", schema(title = "PolygonHandler"))]
58 PolygonHandler { required: bool },
59}
60
61impl ValidationRules {
62 pub fn is_required(&self) -> bool {
64 match self {
65 ValidationRules::StringHandler { required, .. } => *required,
66 ValidationRules::DateHandler { required, .. } => *required,
67 ValidationRules::EnumHandler { required, .. } => *required,
68 ValidationRules::ExpverHandler { required, .. } => *required,
69 ValidationRules::IntHandler { required, .. } => *required,
70 ValidationRules::FloatHandler { required, .. } => *required,
71 ValidationRules::TimeHandler { required } => *required,
72 ValidationRules::PolygonHandler { required } => *required,
73 }
74 }
75}