all jspg tests now passing
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::validator::context::ValidationContext;
|
||||
@ -11,23 +13,23 @@ impl<'a> ValidationContext<'a> {
|
||||
) -> Result<bool, ValidationError> {
|
||||
let current = self.instance;
|
||||
if let Some(arr) = current.as_array() {
|
||||
if let Some(min) = self.schema.min_items {
|
||||
if (arr.len() as f64) < min {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MIN_ITEMS".to_string(),
|
||||
message: "Too few items".to_string(),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
if let Some(min) = self.schema.min_items
|
||||
&& (arr.len() as f64) < min
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MIN_ITEMS".to_string(),
|
||||
message: "Too few items".to_string(),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
if let Some(max) = self.schema.max_items {
|
||||
if (arr.len() as f64) > max {
|
||||
result.errors.push(ValidationError {
|
||||
code: "MAX_ITEMS".to_string(),
|
||||
message: "Too many items".to_string(),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
if let Some(max) = self.schema.max_items
|
||||
&& (arr.len() as f64) > max
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "MAX_ITEMS".to_string(),
|
||||
message: "Too many items".to_string(),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
if self.schema.unique_items.unwrap_or(false) {
|
||||
@ -52,7 +54,7 @@ impl<'a> ValidationContext<'a> {
|
||||
contains_schema,
|
||||
child_instance,
|
||||
&self.path,
|
||||
std::collections::HashSet::new(),
|
||||
HashSet::new(),
|
||||
self.extensible,
|
||||
false,
|
||||
);
|
||||
@ -72,14 +74,14 @@ impl<'a> ValidationContext<'a> {
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
if let Some(max) = self.schema.max_contains {
|
||||
if _match_count > max as usize {
|
||||
result.errors.push(ValidationError {
|
||||
code: "CONTAINS_VIOLATED".to_string(),
|
||||
message: format!("Contains matches {} > max {}", _match_count, max),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
if let Some(max) = self.schema.max_contains
|
||||
&& _match_count > max as usize
|
||||
{
|
||||
result.errors.push(ValidationError {
|
||||
code: "CONTAINS_VIOLATED".to_string(),
|
||||
message: format!("Contains matches {} > max {}", _match_count, max),
|
||||
path: self.path.to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +97,7 @@ impl<'a> ValidationContext<'a> {
|
||||
sub_schema,
|
||||
child_instance,
|
||||
&path,
|
||||
std::collections::HashSet::new(),
|
||||
HashSet::new(),
|
||||
self.extensible,
|
||||
false,
|
||||
);
|
||||
@ -116,7 +118,7 @@ impl<'a> ValidationContext<'a> {
|
||||
items_schema,
|
||||
child_instance,
|
||||
&path,
|
||||
std::collections::HashSet::new(),
|
||||
HashSet::new(),
|
||||
self.extensible,
|
||||
false,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user