use openapiv3::*;
pub trait TypeExt {
fn is_bool(&self) -> bool;
fn is_integer(&self) -> bool;
fn is_number(&self) -> bool;
fn is_string(&self) -> bool;
}
impl TypeExt for Type {
fn is_bool(&self) -> bool {
matches!(self, Type::Boolean(_))
}
fn is_integer(&self) -> bool {
matches!(self, Type::Integer(_))
}
fn is_number(&self) -> bool {
matches!(self, Type::Number(_))
}
fn is_string(&self) -> bool {
matches!(self, Type::String(_))
}
}
pub trait IntegerTypeExt {
fn min_max(&self) -> (i64, i64);
}
impl IntegerTypeExt for IntegerType {
fn min_max(&self) -> (i64, i64) {
let the_min = match self.minimum {
Some(minimum) => {
if self.exclusive_minimum {
minimum + 1
} else {
minimum
}
}
None => i64::min_value(),
};
let the_max = match self.maximum {
Some(maximum) => {
if self.exclusive_maximum {
maximum - 1
} else {
maximum
}
}
None => i64::max_value(),
};
(the_min, the_max)
}
}
pub trait NumberTypeExt {
fn min_max(&self) -> (f64, f64);
}
impl NumberTypeExt for NumberType {
fn min_max(&self) -> (f64, f64) {
let the_min = match self.minimum {
Some(minimum) => {
if self.exclusive_minimum {
minimum + 1.0
} else {
minimum
}
}
None => core::f64::MIN,
};
let the_max = match self.maximum {
Some(maximum) => {
if self.exclusive_maximum {
maximum - 1.0
} else {
maximum
}
}
None => core::f64::MAX,
};
(the_min, the_max)
}
}