|
1 | 1 | use crate::{ |
2 | | - compiler, error::ValidationError, ext::cmp, keywords::CompilationResult, paths::Location, |
| 2 | + compiler, |
| 3 | + error::ValidationError, |
| 4 | + ext::cmp, |
| 5 | + keywords::CompilationResult, |
| 6 | + paths::Location, |
| 7 | + types::{JsonType, JsonTypeSet}, |
3 | 8 | validator::Validate, |
4 | 9 | }; |
5 | 10 | use serde_json::{Map, Number, Value}; |
@@ -45,6 +50,10 @@ impl Validate for ConstArrayValidator { |
45 | 50 | false |
46 | 51 | } |
47 | 52 | } |
| 53 | + |
| 54 | + fn applicable_types(&self) -> JsonTypeSet { |
| 55 | + JsonTypeSet::empty().insert(JsonType::Array) |
| 56 | + } |
48 | 57 | } |
49 | 58 |
|
50 | 59 | struct ConstBooleanValidator { |
@@ -83,6 +92,10 @@ impl Validate for ConstBooleanValidator { |
83 | 92 | false |
84 | 93 | } |
85 | 94 | } |
| 95 | + |
| 96 | + fn applicable_types(&self) -> JsonTypeSet { |
| 97 | + JsonTypeSet::empty().insert(JsonType::Boolean) |
| 98 | + } |
86 | 99 | } |
87 | 100 |
|
88 | 101 | struct ConstNullValidator { |
@@ -114,6 +127,10 @@ impl Validate for ConstNullValidator { |
114 | 127 | fn is_valid(&self, instance: &Value) -> bool { |
115 | 128 | instance.is_null() |
116 | 129 | } |
| 130 | + |
| 131 | + fn applicable_types(&self) -> JsonTypeSet { |
| 132 | + JsonTypeSet::empty().insert(JsonType::Null) |
| 133 | + } |
117 | 134 | } |
118 | 135 |
|
119 | 136 | struct ConstNumberValidator { |
@@ -157,6 +174,14 @@ impl Validate for ConstNumberValidator { |
157 | 174 | false |
158 | 175 | } |
159 | 176 | } |
| 177 | + |
| 178 | + fn applicable_types(&self) -> JsonTypeSet { |
| 179 | + let mut set = JsonTypeSet::empty().insert(JsonType::Number); |
| 180 | + if self.original_value.is_i64() || self.original_value.is_u64() { |
| 181 | + set = set.insert(JsonType::Integer); |
| 182 | + } |
| 183 | + set |
| 184 | + } |
160 | 185 | } |
161 | 186 |
|
162 | 187 | pub(crate) struct ConstObjectValidator { |
@@ -198,6 +223,10 @@ impl Validate for ConstObjectValidator { |
198 | 223 | false |
199 | 224 | } |
200 | 225 | } |
| 226 | + |
| 227 | + fn applicable_types(&self) -> JsonTypeSet { |
| 228 | + JsonTypeSet::empty().insert(JsonType::Object) |
| 229 | + } |
201 | 230 | } |
202 | 231 |
|
203 | 232 | pub(crate) struct ConstStringValidator { |
@@ -239,6 +268,10 @@ impl Validate for ConstStringValidator { |
239 | 268 | false |
240 | 269 | } |
241 | 270 | } |
| 271 | + |
| 272 | + fn applicable_types(&self) -> JsonTypeSet { |
| 273 | + JsonTypeSet::empty().insert(JsonType::String) |
| 274 | + } |
242 | 275 | } |
243 | 276 |
|
244 | 277 | #[inline] |
|
0 commit comments