aviso_validators/
types.rs1use crate::point_cloud::DEFAULT_MAX_POINTS;
12use serde::Serialize;
13#[cfg(feature = "openapi")]
14use utoipa::ToSchema;
15
16#[derive(serde::Deserialize, Serialize, Clone, Debug)]
18#[cfg_attr(feature = "openapi", derive(ToSchema))]
19#[serde(tag = "type")]
20pub enum ValidationRules {
21 #[cfg_attr(feature = "openapi", schema(title = "StringHandler"))]
23 StringHandler {
24 max_length: Option<usize>,
25 required: bool,
26 },
27 #[cfg_attr(feature = "openapi", schema(title = "DateHandler"))]
29 DateHandler {
30 canonical_format: String,
31 required: bool,
32 },
33 #[cfg_attr(feature = "openapi", schema(title = "EnumHandler"))]
35 EnumHandler { values: Vec<String>, required: bool },
36 #[cfg_attr(feature = "openapi", schema(title = "ExpverHandler"))]
38 ExpverHandler {
39 default: Option<String>,
40 required: bool,
41 },
42 #[cfg_attr(feature = "openapi", schema(title = "IntHandler"))]
44 IntHandler {
45 range: Option<[i64; 2]>,
46 required: bool,
47 },
48 #[cfg_attr(feature = "openapi", schema(title = "FloatHandler"))]
50 FloatHandler {
51 range: Option<[f64; 2]>,
52 required: bool,
53 },
54 #[cfg_attr(feature = "openapi", schema(title = "TimeHandler"))]
56 TimeHandler { required: bool },
57 #[cfg_attr(feature = "openapi", schema(title = "PolygonHandler"))]
59 PolygonHandler { required: bool },
60 #[cfg_attr(feature = "openapi", schema(title = "PointCloudHandler"))]
62 PointCloudHandler {
63 required: bool,
64 #[serde(default = "default_max_points")]
65 max_points: usize,
66 },
67}
68
69impl ValidationRules {
70 pub fn is_required(&self) -> bool {
72 match self {
73 ValidationRules::StringHandler { required, .. } => *required,
74 ValidationRules::DateHandler { required, .. } => *required,
75 ValidationRules::EnumHandler { required, .. } => *required,
76 ValidationRules::ExpverHandler { required, .. } => *required,
77 ValidationRules::IntHandler { required, .. } => *required,
78 ValidationRules::FloatHandler { required, .. } => *required,
79 ValidationRules::TimeHandler { required } => *required,
80 ValidationRules::PolygonHandler { required } => *required,
81 ValidationRules::PointCloudHandler { required, .. } => *required,
82 }
83 }
84}
85
86const fn default_max_points() -> usize {
87 DEFAULT_MAX_POINTS
88}