1use openapiv3::*;
2
3pub trait TypeExt {
5 fn is_bool(&self) -> bool;
7
8 fn is_integer(&self) -> bool;
10
11 fn is_number(&self) -> bool;
13
14 fn is_string(&self) -> bool;
16}
17
18impl TypeExt for Type {
19 fn is_bool(&self) -> bool {
20 matches!(self, Type::Boolean(_))
21 }
22
23 fn is_integer(&self) -> bool {
24 matches!(self, Type::Integer(_))
25 }
26
27 fn is_number(&self) -> bool {
28 matches!(self, Type::Number(_))
29 }
30
31 fn is_string(&self) -> bool {
32 matches!(self, Type::String(_))
33 }
34}
35
36pub trait IntegerTypeExt {
38 fn min_max(&self) -> (i64, i64);
41}
42
43impl IntegerTypeExt for IntegerType {
44 fn min_max(&self) -> (i64, i64) {
45 let the_min = match self.minimum {
46 Some(minimum) => {
47 if self.exclusive_minimum {
48 minimum + 1
49 } else {
50 minimum
51 }
52 }
53 None => i64::min_value(),
54 };
55
56 let the_max = match self.maximum {
57 Some(maximum) => {
58 if self.exclusive_maximum {
59 maximum - 1
60 } else {
61 maximum
62 }
63 }
64 None => i64::max_value(),
65 };
66 (the_min, the_max)
67 }
68}
69
70
71pub trait NumberTypeExt {
73 fn min_max(&self) -> (f64, f64);
76}
77
78impl NumberTypeExt for NumberType {
79 fn min_max(&self) -> (f64, f64) {
80 let the_min = match self.minimum {
81 Some(minimum) => {
82 if self.exclusive_minimum {
83 minimum + 1.0
84 } else {
85 minimum
86 }
87 }
88 None => core::f64::MIN,
89 };
90
91 let the_max = match self.maximum {
92 Some(maximum) => {
93 if self.exclusive_maximum {
94 maximum - 1.0
95 } else {
96 maximum
97 }
98 }
99 None => core::f64::MAX,
100 };
101 (the_min, the_max)
102 }
103}