jspg checkpoint

This commit is contained in:
2026-06-23 19:48:38 -04:00
parent 9900b3fc43
commit a1fb9ef650
24 changed files with 588 additions and 3801 deletions

View File

@ -25,9 +25,9 @@ impl Schema {
("identifier".to_string(), id.to_string()),
])),
details: ErrorDetails {
path: Some(path.to_string()),
schema: Some(root_id.to_string()),
..Default::default()
path: Some(path.to_string()),
schema: Some(root_id.to_string()),
..Default::default()
},
});
return;
@ -84,13 +84,6 @@ impl Schema {
}
}
if let Some(pattern_props) = &schema_arc.obj.pattern_properties {
for (k, v) in pattern_props.iter() {
let next_path = format!("{}/{}", path, k);
Self::collect_schemas(v, root_id, next_path, to_insert, errors);
}
}
let mut map_arr = |arr: &Vec<Arc<Schema>>, sub: &str| {
for (i, v) in arr.iter().enumerate() {
Self::collect_schemas(
@ -103,10 +96,6 @@ impl Schema {
}
};
if let Some(arr) = &schema_arc.obj.prefix_items {
map_arr(arr, "prefixItems");
}
if let Some(arr) = &schema_arc.obj.one_of {
map_arr(arr, "oneOf");
}
@ -123,11 +112,6 @@ impl Schema {
}
};
map_opt(
&schema_arc.obj.additional_properties,
false,
"additionalProperties",
);
map_opt(&schema_arc.obj.items, true, "items");
map_opt(&schema_arc.obj.not, false, "not");
map_opt(&schema_arc.obj.contains, false, "contains");

View File

@ -39,18 +39,6 @@ impl Schema {
}
}
if let Some(pattern_props) = &self.obj.pattern_properties {
let mut compiled = Vec::new();
for (k, v) in pattern_props {
if let Ok(re) = regex::Regex::new(k) {
compiled.push((crate::database::object::CompiledRegex(re), v.clone()));
}
}
if !compiled.is_empty() {
let _ = self.obj.compiled_pattern_properties.set(compiled);
}
}
let mut props = IndexMap::new();
// 1. Resolve INHERITANCE dependencies first
@ -78,10 +66,10 @@ impl Schema {
code: "MULTIPLE_INHERITANCE_PROHIBITED".to_string(),
values: Some(HashMap::from([("types".to_string(), types.join(", "))])),
details: ErrorDetails {
path: Some(path.clone()),
schema: Some(root_id.to_string()),
..Default::default()
}
path: Some(path.clone()),
schema: Some(root_id.to_string()),
..Default::default()
},
});
}
@ -140,29 +128,13 @@ impl Schema {
if let Some(items) = &self.obj.items {
items.compile(db, root_id, format!("{}/items", path), errors);
}
if let Some(pattern_props) = &self.obj.pattern_properties {
for (k, child) in pattern_props {
child.compile(db, root_id, format!("{}/{}", path, k), errors);
}
}
if let Some(additional_props) = &self.obj.additional_properties {
additional_props.compile(
db,
root_id,
format!("{}/additionalProperties", path),
errors,
);
}
if let Some(one_of) = &self.obj.one_of {
for (i, child) in one_of.iter().enumerate() {
child.compile(db, root_id, format!("{}/oneOf/{}", path, i), errors);
}
}
if let Some(arr) = &self.obj.prefix_items {
for (i, child) in arr.iter().enumerate() {
child.compile(db, root_id, format!("{}/prefixItems/{}", path, i), errors);
}
}
if let Some(child) = &self.obj.not {
child.compile(db, root_id, format!("{}/not", path), errors);
}

View File

@ -81,7 +81,6 @@ fn resolve_in_place(
let mut merged_required = HashSet::new();
let mut merged_display = HashSet::new();
let mut merged_dependencies = serde_json::Map::new();
let mut merged_pattern_props = serde_json::Map::new();
// Read current values first to let host override included properties
if let Some(req) = current.get("required").and_then(|v| v.as_array()) {
@ -103,11 +102,7 @@ fn resolve_in_place(
merged_dependencies.insert(k.clone(), v.clone());
}
}
if let Some(pat_props) = current.get("patternProperties").and_then(|v| v.as_object()) {
for (k, v) in pat_props {
merged_pattern_props.insert(k.clone(), v.clone());
}
}
if let Some(props) = current.get("properties").and_then(|v| v.as_object()) {
for (k, v) in props {
merged_props.insert(k.clone(), v.clone());
@ -119,7 +114,10 @@ fn resolve_in_place(
if visited.contains(inc_name) {
errors.push(Error {
code: "CIRCULAR_INCLUDE_DETECTED".to_string(),
values: Some(HashMap::from([("include".to_string(), inc_name.to_string())])),
values: Some(HashMap::from([(
"include".to_string(),
inc_name.to_string(),
)])),
details: ErrorDetails {
schema: Some(schema_id.to_string()),
path: Some(path.to_string()),
@ -156,18 +154,6 @@ fn resolve_in_place(
}
}
// Merge patternProperties (host overrides trait)
if let Some(target_pat_props) = resolved_target
.get("patternProperties")
.and_then(|v| v.as_object())
{
for (k, v) in target_pat_props {
if !merged_pattern_props.contains_key(k) {
merged_pattern_props.insert(k.clone(), v.clone());
}
}
}
// Merge required
if let Some(target_req) = resolved_target.get("required").and_then(|v| v.as_array()) {
for r in target_req {
@ -218,7 +204,6 @@ fn resolve_in_place(
if let Some(obj) = current.as_object_mut() {
for (k, v) in resolved_target.as_object().unwrap() {
if k != "properties"
&& k != "patternProperties"
&& k != "required"
&& k != "display"
&& k != "dependencies"
@ -233,7 +218,10 @@ fn resolve_in_place(
} else {
errors.push(Error {
code: "TRAIT_NOT_FOUND".to_string(),
values: Some(HashMap::from([("include".to_string(), inc_name.to_string())])),
values: Some(HashMap::from([(
"include".to_string(),
inc_name.to_string(),
)])),
details: ErrorDetails {
schema: Some(schema_id.to_string()),
path: Some(path.to_string()),
@ -248,12 +236,7 @@ fn resolve_in_place(
if !merged_props.is_empty() {
obj.insert("properties".to_string(), Value::Object(merged_props));
}
if !merged_pattern_props.is_empty() {
obj.insert(
"patternProperties".to_string(),
Value::Object(merged_pattern_props),
);
}
if !merged_required.is_empty() {
let mut req_vec: Vec<Value> = merged_required.into_iter().map(Value::String).collect();
req_vec.sort_by(|a, b| a.as_str().unwrap().cmp(b.as_str().unwrap()));
@ -289,22 +272,7 @@ fn resolve_in_place(
);
}
}
if let Some(pat_props) = obj
.get_mut("patternProperties")
.and_then(|v| v.as_object_mut())
{
for (k, v) in pat_props {
resolve_in_place(
v,
traits,
schemas,
errors,
schema_id,
&format!("{}/{}", path, k),
visited,
);
}
}
if let Some(items) = obj.get_mut("items") {
resolve_in_place(
items,
@ -316,30 +284,6 @@ fn resolve_in_place(
visited,
);
}
if let Some(prefix_items) = obj.get_mut("prefixItems").and_then(|v| v.as_array_mut()) {
for (i, v) in prefix_items.iter_mut().enumerate() {
resolve_in_place(
v,
traits,
schemas,
errors,
schema_id,
&format!("{}/prefixItems/{}", path, i),
visited,
);
}
}
if let Some(additional_props) = obj.get_mut("additionalProperties") {
resolve_in_place(
additional_props,
traits,
schemas,
errors,
schema_id,
&format!("{}/additionalProperties", path),
visited,
);
}
if let Some(one_of) = obj.get_mut("oneOf").and_then(|v| v.as_array_mut()) {
for (i, v) in one_of.iter_mut().enumerate() {
resolve_in_place(

View File

@ -32,12 +32,10 @@ pub struct SchemaObject {
// Object Keywords
#[serde(skip_serializing_if = "Option::is_none")]
pub properties: Option<IndexMap<String, Arc<Schema>>>,
#[serde(rename = "patternProperties")]
#[serde(rename = "keys")]
#[serde(skip_serializing_if = "Option::is_none")]
pub pattern_properties: Option<IndexMap<String, Arc<Schema>>>,
#[serde(rename = "additionalProperties")]
#[serde(skip_serializing_if = "Option::is_none")]
pub additional_properties: Option<Arc<Schema>>,
pub keys: Option<Arc<Schema>>,
#[serde(rename = "family")]
#[serde(skip_serializing_if = "Option::is_none")]
pub family: Option<String>,
@ -53,9 +51,6 @@ pub struct SchemaObject {
#[serde(rename = "items")]
#[serde(skip_serializing_if = "Option::is_none")]
pub items: Option<Arc<Schema>>,
#[serde(rename = "prefixItems")]
#[serde(skip_serializing_if = "Option::is_none")]
pub prefix_items: Option<Vec<Arc<Schema>>>,
// String Validation
#[serde(rename = "minLength")]
@ -189,8 +184,6 @@ pub struct SchemaObject {
pub compiled_format: OnceLock<CompiledFormat>,
#[serde(skip)]
pub compiled_pattern: OnceLock<CompiledRegex>,
#[serde(skip)]
pub compiled_pattern_properties: OnceLock<Vec<(CompiledRegex, Arc<Schema>)>>,
}
/// Represents a compiled format validator
@ -263,7 +256,7 @@ where
pub fn is_primitive_type(t: &str) -> bool {
matches!(
t,
"string" | "number" | "integer" | "boolean" | "object" | "array" | "null"
"string" | "number" | "integer" | "boolean" | "object" | "array" | "null" | "dict"
)
}

View File

@ -26,12 +26,10 @@ impl Schema {
/// Returns true if the schema acts purely as a type pointer (composition without overriding constraints)
pub fn is_proxy(&self) -> bool {
self.obj.properties.is_none()
&& self.obj.pattern_properties.is_none()
&& self.obj.additional_properties.is_none()
&& self.obj.keys.is_none()
&& self.obj.required.is_none()
&& self.obj.dependencies.is_none()
&& self.obj.items.is_none()
&& self.obj.prefix_items.is_none()
&& self.obj.contains.is_none()
&& self.obj.format.is_none()
&& self.obj.enum_.is_none()
@ -68,12 +66,10 @@ impl<'de> Deserialize<'de> for Schema {
// restrict additional properties natively
let is_empty = obj.type_.is_none()
&& obj.properties.is_none()
&& obj.pattern_properties.is_none()
&& obj.additional_properties.is_none()
&& obj.keys.is_none()
&& obj.required.is_none()
&& obj.dependencies.is_none()
&& obj.items.is_none()
&& obj.prefix_items.is_none()
&& obj.contains.is_none()
&& obj.format.is_none()
&& obj.enum_.is_none()

View File

@ -197,84 +197,6 @@ fn test_unique_items_0_14() {
crate::tests::runner::run_test_case(&path, 0, 14).unwrap();
}
#[test]
fn test_unique_items_0_15() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 15).unwrap();
}
#[test]
fn test_unique_items_0_16() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 16).unwrap();
}
#[test]
fn test_unique_items_0_17() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 17).unwrap();
}
#[test]
fn test_unique_items_0_18() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 18).unwrap();
}
#[test]
fn test_unique_items_0_19() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 19).unwrap();
}
#[test]
fn test_unique_items_0_20() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 20).unwrap();
}
#[test]
fn test_unique_items_0_21() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 21).unwrap();
}
#[test]
fn test_unique_items_0_22() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 22).unwrap();
}
#[test]
fn test_unique_items_0_23() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 23).unwrap();
}
#[test]
fn test_unique_items_0_24() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 24).unwrap();
}
#[test]
fn test_unique_items_0_25() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 25).unwrap();
}
#[test]
fn test_unique_items_0_26() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 26).unwrap();
}
#[test]
fn test_unique_items_0_27() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 27).unwrap();
}
#[test]
fn test_unique_items_1_0() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
@ -323,6 +245,48 @@ fn test_unique_items_1_7() {
crate::tests::runner::run_test_case(&path, 1, 7).unwrap();
}
#[test]
fn test_unique_items_1_8() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 8).unwrap();
}
#[test]
fn test_unique_items_1_9() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 9).unwrap();
}
#[test]
fn test_unique_items_1_10() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 10).unwrap();
}
#[test]
fn test_unique_items_1_11() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 11).unwrap();
}
#[test]
fn test_unique_items_1_12() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 12).unwrap();
}
#[test]
fn test_unique_items_1_13() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 13).unwrap();
}
#[test]
fn test_unique_items_1_14() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 14).unwrap();
}
#[test]
fn test_unique_items_2_0() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
@ -335,204 +299,6 @@ fn test_unique_items_2_1() {
crate::tests::runner::run_test_case(&path, 2, 1).unwrap();
}
#[test]
fn test_unique_items_2_2() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 2).unwrap();
}
#[test]
fn test_unique_items_2_3() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 3).unwrap();
}
#[test]
fn test_unique_items_2_4() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 4).unwrap();
}
#[test]
fn test_unique_items_3_0() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 0).unwrap();
}
#[test]
fn test_unique_items_3_1() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 1).unwrap();
}
#[test]
fn test_unique_items_3_2() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 2).unwrap();
}
#[test]
fn test_unique_items_3_3() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 3).unwrap();
}
#[test]
fn test_unique_items_3_4() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 4).unwrap();
}
#[test]
fn test_unique_items_3_5() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 5).unwrap();
}
#[test]
fn test_unique_items_3_6() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 6).unwrap();
}
#[test]
fn test_unique_items_3_7() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 7).unwrap();
}
#[test]
fn test_unique_items_3_8() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 8).unwrap();
}
#[test]
fn test_unique_items_3_9() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 9).unwrap();
}
#[test]
fn test_unique_items_3_10() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 10).unwrap();
}
#[test]
fn test_unique_items_3_11() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 11).unwrap();
}
#[test]
fn test_unique_items_3_12() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 12).unwrap();
}
#[test]
fn test_unique_items_3_13() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 13).unwrap();
}
#[test]
fn test_unique_items_3_14() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 14).unwrap();
}
#[test]
fn test_unique_items_4_0() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 0).unwrap();
}
#[test]
fn test_unique_items_4_1() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 1).unwrap();
}
#[test]
fn test_unique_items_4_2() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 2).unwrap();
}
#[test]
fn test_unique_items_4_3() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 3).unwrap();
}
#[test]
fn test_unique_items_4_4() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 4).unwrap();
}
#[test]
fn test_unique_items_4_5() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 5).unwrap();
}
#[test]
fn test_unique_items_4_6() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 6).unwrap();
}
#[test]
fn test_unique_items_4_7() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 7).unwrap();
}
#[test]
fn test_unique_items_5_0() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 0).unwrap();
}
#[test]
fn test_unique_items_5_1() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 1).unwrap();
}
#[test]
fn test_unique_items_5_2() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 2).unwrap();
}
#[test]
fn test_unique_items_5_3() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 3).unwrap();
}
#[test]
fn test_unique_items_5_4() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 4).unwrap();
}
#[test]
fn test_unique_items_6_0() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 6, 0).unwrap();
}
#[test]
fn test_unique_items_6_1() {
let path = format!("{}/fixtures/uniqueItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 6, 1).unwrap();
}
#[test]
fn test_filter_0_0() {
let path = format!("{}/fixtures/filter.json", env!("CARGO_MANIFEST_DIR"));
@ -581,54 +347,6 @@ fn test_min_items_2_0() {
crate::tests::runner::run_test_case(&path, 2, 0).unwrap();
}
#[test]
fn test_additional_properties_0_0() {
let path = format!("{}/fixtures/additionalProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 0).unwrap();
}
#[test]
fn test_additional_properties_0_1() {
let path = format!("{}/fixtures/additionalProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 1).unwrap();
}
#[test]
fn test_additional_properties_0_2() {
let path = format!("{}/fixtures/additionalProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 2).unwrap();
}
#[test]
fn test_additional_properties_1_0() {
let path = format!("{}/fixtures/additionalProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 0).unwrap();
}
#[test]
fn test_additional_properties_1_1() {
let path = format!("{}/fixtures/additionalProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 1).unwrap();
}
#[test]
fn test_additional_properties_2_0() {
let path = format!("{}/fixtures/additionalProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 0).unwrap();
}
#[test]
fn test_additional_properties_2_1() {
let path = format!("{}/fixtures/additionalProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 1).unwrap();
}
#[test]
fn test_additional_properties_2_2() {
let path = format!("{}/fixtures/additionalProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 2).unwrap();
}
#[test]
fn test_dependencies_0_0() {
let path = format!("{}/fixtures/dependencies.json", env!("CARGO_MANIFEST_DIR"));
@ -887,6 +605,72 @@ fn test_dependencies_10_0() {
crate::tests::runner::run_test_case(&path, 10, 0).unwrap();
}
#[test]
fn test_dict_0_0() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 0).unwrap();
}
#[test]
fn test_dict_0_1() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 1).unwrap();
}
#[test]
fn test_dict_0_2() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 2).unwrap();
}
#[test]
fn test_dict_0_3() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 3).unwrap();
}
#[test]
fn test_dict_1_0() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 0).unwrap();
}
#[test]
fn test_dict_1_1() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 1).unwrap();
}
#[test]
fn test_dict_2_0() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 0).unwrap();
}
#[test]
fn test_dict_2_1() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 1).unwrap();
}
#[test]
fn test_dict_3_0() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 0).unwrap();
}
#[test]
fn test_dict_3_1() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 1).unwrap();
}
#[test]
fn test_dict_3_2() {
let path = format!("{}/fixtures/dict.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 2).unwrap();
}
#[test]
fn test_exclusive_minimum_0_0() {
let path = format!("{}/fixtures/exclusiveMinimum.json", env!("CARGO_MANIFEST_DIR"));
@ -1979,72 +1763,18 @@ fn test_items_3_2() {
crate::tests::runner::run_test_case(&path, 3, 2).unwrap();
}
#[test]
fn test_items_3_3() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 3).unwrap();
}
#[test]
fn test_items_3_4() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 4).unwrap();
}
#[test]
fn test_items_3_5() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 5).unwrap();
}
#[test]
fn test_items_4_0() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 0).unwrap();
}
#[test]
fn test_items_4_1() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 1).unwrap();
}
#[test]
fn test_items_4_2() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 2).unwrap();
}
#[test]
fn test_items_5_0() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 0).unwrap();
}
#[test]
fn test_items_5_1() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 1).unwrap();
}
#[test]
fn test_items_5_2() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 2).unwrap();
}
#[test]
fn test_items_5_3() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 3).unwrap();
}
#[test]
fn test_items_5_4() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 4).unwrap();
}
#[test]
fn test_items_6_0() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
@ -2088,75 +1818,15 @@ fn test_items_9_0() {
}
#[test]
fn test_items_10_0() {
fn test_items_9_1() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 10, 0).unwrap();
crate::tests::runner::run_test_case(&path, 9, 1).unwrap();
}
#[test]
fn test_items_11_0() {
fn test_items_9_2() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 11, 0).unwrap();
}
#[test]
fn test_items_11_1() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 11, 1).unwrap();
}
#[test]
fn test_items_12_0() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 12, 0).unwrap();
}
#[test]
fn test_items_12_1() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 12, 1).unwrap();
}
#[test]
fn test_items_13_0() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 13, 0).unwrap();
}
#[test]
fn test_items_13_1() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 13, 1).unwrap();
}
#[test]
fn test_items_14_0() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 14, 0).unwrap();
}
#[test]
fn test_items_14_1() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 14, 1).unwrap();
}
#[test]
fn test_items_15_0() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 15, 0).unwrap();
}
#[test]
fn test_items_15_1() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 15, 1).unwrap();
}
#[test]
fn test_items_15_2() {
let path = format!("{}/fixtures/items.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 15, 2).unwrap();
crate::tests::runner::run_test_case(&path, 9, 2).unwrap();
}
#[test]
@ -3011,78 +2681,6 @@ fn test_exclusive_maximum_0_3() {
crate::tests::runner::run_test_case(&path, 0, 3).unwrap();
}
#[test]
fn test_prefix_items_0_0() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 0).unwrap();
}
#[test]
fn test_prefix_items_0_1() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 1).unwrap();
}
#[test]
fn test_prefix_items_0_2() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 2).unwrap();
}
#[test]
fn test_prefix_items_0_3() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 3).unwrap();
}
#[test]
fn test_prefix_items_0_4() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 4).unwrap();
}
#[test]
fn test_prefix_items_0_5() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 5).unwrap();
}
#[test]
fn test_prefix_items_1_0() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 0).unwrap();
}
#[test]
fn test_prefix_items_1_1() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 1).unwrap();
}
#[test]
fn test_prefix_items_1_2() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 2).unwrap();
}
#[test]
fn test_prefix_items_2_0() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 0).unwrap();
}
#[test]
fn test_prefix_items_3_0() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 0).unwrap();
}
#[test]
fn test_prefix_items_4_0() {
let path = format!("{}/fixtures/prefixItems.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 0).unwrap();
}
#[test]
fn test_primitive_types_0_0() {
let path = format!("{}/fixtures/primitiveTypes.json", env!("CARGO_MANIFEST_DIR"));
@ -4241,162 +3839,6 @@ fn test_multiple_of_3_0() {
crate::tests::runner::run_test_case(&path, 3, 0).unwrap();
}
#[test]
fn test_pattern_properties_0_0() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 0).unwrap();
}
#[test]
fn test_pattern_properties_0_1() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 1).unwrap();
}
#[test]
fn test_pattern_properties_0_2() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 2).unwrap();
}
#[test]
fn test_pattern_properties_0_3() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 3).unwrap();
}
#[test]
fn test_pattern_properties_0_4() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 4).unwrap();
}
#[test]
fn test_pattern_properties_0_5() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 5).unwrap();
}
#[test]
fn test_pattern_properties_0_6() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 6).unwrap();
}
#[test]
fn test_pattern_properties_0_7() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 0, 7).unwrap();
}
#[test]
fn test_pattern_properties_1_0() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 0).unwrap();
}
#[test]
fn test_pattern_properties_1_1() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 1).unwrap();
}
#[test]
fn test_pattern_properties_1_2() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 2).unwrap();
}
#[test]
fn test_pattern_properties_1_3() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 3).unwrap();
}
#[test]
fn test_pattern_properties_1_4() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 4).unwrap();
}
#[test]
fn test_pattern_properties_1_5() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 1, 5).unwrap();
}
#[test]
fn test_pattern_properties_2_0() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 0).unwrap();
}
#[test]
fn test_pattern_properties_2_1() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 1).unwrap();
}
#[test]
fn test_pattern_properties_2_2() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 2).unwrap();
}
#[test]
fn test_pattern_properties_2_3() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 2, 3).unwrap();
}
#[test]
fn test_pattern_properties_3_0() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 0).unwrap();
}
#[test]
fn test_pattern_properties_3_1() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 1).unwrap();
}
#[test]
fn test_pattern_properties_3_2() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 2).unwrap();
}
#[test]
fn test_pattern_properties_3_3() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 3).unwrap();
}
#[test]
fn test_pattern_properties_3_4() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 3, 4).unwrap();
}
#[test]
fn test_pattern_properties_4_0() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 4, 0).unwrap();
}
#[test]
fn test_pattern_properties_5_0() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 0).unwrap();
}
#[test]
fn test_pattern_properties_5_1() {
let path = format!("{}/fixtures/patternProperties.json", env!("CARGO_MANIFEST_DIR"));
crate::tests::runner::run_test_case(&path, 5, 1).unwrap();
}
#[test]
fn test_merge_0_0() {
let path = format!("{}/fixtures/merge.json", env!("CARGO_MANIFEST_DIR"));

View File

@ -37,6 +37,7 @@ impl Validator {
"number" => val.is_number(),
"integer" => is_integer(val),
"object" => val.is_object(),
"dict" => val.is_object(),
"array" => val.is_array(),
_ => true,
}

View File

@ -99,42 +99,10 @@ impl<'a> ValidationContext<'a> {
}
let len = arr.len();
let mut validation_index = 0;
if let Some(ref prefix) = self.schema.prefix_items {
for (i, sub_schema) in prefix.iter().enumerate() {
if i < len {
if let Some(child_instance) = arr.get(i) {
let mut item_path = self.join_path(&i.to_string());
let is_topological = sub_schema.obj.requires_uuid_path(self.db);
if is_topological {
if let Some(obj) = child_instance.as_object() {
if let Some(id_str) = obj.get("id").and_then(|v| v.as_str()) {
item_path = self.join_path(id_str);
}
}
}
let derived = self.derive(
sub_schema,
child_instance,
&item_path,
HashSet::new(),
self.extensible,
false,
Some(self.instance),
);
let item_res = derived.validate()?;
result.merge(item_res);
result.evaluated_indices.insert(i);
validation_index += 1;
}
}
}
}
if let Some(ref items_schema) = self.schema.items {
let is_topological = items_schema.obj.requires_uuid_path(self.db);
for i in validation_index..len {
for i in 0..len {
if let Some(child_instance) = arr.get(i) {
let mut item_path = self.join_path(&i.to_string());
if is_topological {

View File

@ -0,0 +1,76 @@
use std::collections::{HashMap, HashSet};
use serde_json::Value;
use crate::validator::context::ValidationContext;
use crate::validator::error::ValidationError;
use crate::validator::result::ValidationResult;
impl<'a> ValidationContext<'a> {
pub(crate) fn validate_dict(
&self,
result: &mut ValidationResult,
) -> Result<bool, ValidationError> {
let current = self.instance;
if let Some(obj) = current.as_object() {
let is_dict = match &self.schema.type_ {
Some(crate::database::object::SchemaTypeOrArray::Single(t)) => t == "dict",
Some(crate::database::object::SchemaTypeOrArray::Multiple(types)) => types.contains(&"dict".to_string()),
None => false,
};
if is_dict {
// Mark all keys as evaluated since a dictionary's keys are all dynamic parameters, not structured properties
result.evaluated_keys.extend(obj.keys().cloned());
// Validate keys
if let Some(ref keys_schema) = self.schema.keys {
for key in obj.keys() {
let _new_path = self.join_path(&format!("keys/{}", key));
let val_str = Value::String(key.to_string());
let ctx = self.derive(
keys_schema,
&val_str,
&_new_path,
HashSet::new(),
self.extensible,
self.reporter,
None,
);
result.merge(ctx.validate()?);
}
}
// Validate items (values)
if let Some(ref items_schema) = self.schema.items {
for (key, child_instance) in obj {
let new_path = self.join_path(key);
let is_ref = match &items_schema.type_ {
Some(crate::database::object::SchemaTypeOrArray::Single(ref_t)) => {
!crate::database::object::is_primitive_type(ref_t)
}
_ => false,
};
let next_extensible = if is_ref { false } else { self.extensible };
let derived = self.derive(
items_schema,
child_instance,
&new_path,
HashSet::new(),
next_extensible,
false,
Some(self.instance),
);
let item_res = derived.validate()?;
result.merge(item_res);
}
}
}
}
Ok(true)
}
}

View File

@ -1,5 +1,7 @@
use std::collections::HashMap;
use crate::database::object::{is_primitive_type, SchemaTypeOrArray};
use crate::database::schema::Schema;
use crate::validator::context::ValidationContext;
use crate::validator::error::ValidationError;
use crate::validator::result::ValidationResult;
@ -16,6 +18,49 @@ impl<'a> ValidationContext<'a> {
Ok(true)
}
pub(crate) fn schema_expects_primitive(&self, schema: &Schema, primitive: &str) -> bool {
match &schema.type_ {
None => true, // Any type is allowed
Some(SchemaTypeOrArray::Single(t)) => {
if t == primitive {
true
} else if !is_primitive_type(t) {
if primitive == "object" {
true
} else {
// Custom type - resolve recursively
if let Some(parent) = self.db.schemas.get(t) {
self.schema_expects_primitive(parent, primitive)
} else {
false
}
}
} else {
false
}
}
Some(SchemaTypeOrArray::Multiple(types)) => {
types.iter().any(|t| {
if t == primitive {
true
} else if !is_primitive_type(t) {
if primitive == "object" {
true
} else {
if let Some(parent) = self.db.schemas.get(t) {
self.schema_expects_primitive(parent, primitive)
} else {
false
}
}
} else {
false
}
})
}
}
}
pub(crate) fn validate_strictness(
&self,
result: &mut ValidationResult,
@ -24,38 +69,18 @@ impl<'a> ValidationContext<'a> {
return Ok(true);
}
if let Some(obj) = self.instance.as_object() {
for key in obj.keys() {
if !result.evaluated_keys.contains(key) && !self.overrides.contains(key) {
result.errors.push(ValidationError {
code: "STRICT_PROPERTY_VIOLATION".to_string(),
values: Some(HashMap::from([
("property_name".to_string(), key.to_string()),
])),
path: self.join_path(key),
});
}
}
}
if let Some(arr) = self.instance.as_array() {
for i in 0..arr.len() {
if !result.evaluated_indices.contains(&i) {
let mut item_path = self.join_path(&i.to_string());
if let Some(child_instance) = arr.get(i) {
if let Some(obj) = child_instance.as_object() {
if let Some(id_str) = obj.get("id").and_then(|v| v.as_str()) {
item_path = self.join_path(id_str);
}
}
if self.schema_expects_primitive(self.schema, "object") || self.schema_expects_primitive(self.schema, "dict") {
if let Some(obj) = self.instance.as_object() {
for key in obj.keys() {
if !result.evaluated_keys.contains(key) && !self.overrides.contains(key) {
result.errors.push(ValidationError {
code: "STRICT_PROPERTY_VIOLATION".to_string(),
values: Some(HashMap::from([
("property_name".to_string(), key.to_string()),
])),
path: self.join_path(key),
});
}
result.errors.push(ValidationError {
code: "STRICT_ITEM_VIOLATION".to_string(),
values: Some(HashMap::from([
("index".to_string(), i.to_string()),
])),
path: item_path,
});
}
}
}

View File

@ -6,6 +6,7 @@ use std::collections::HashMap;
pub mod array;
pub mod cases;
pub mod core;
pub mod dict;
pub mod extensible;
pub mod format;
pub mod not;
@ -43,6 +44,7 @@ impl<'a> ValidationContext<'a> {
// Complex Structures
self.validate_object(&mut result)?;
self.validate_array(&mut result)?;
self.validate_dict(&mut result)?;
// Multipliers & Conditionals
if !self.validate_one_of(&mut result)? {

View File

@ -211,80 +211,8 @@ impl<'a> ValidationContext<'a> {
}
}
if let Some(compiled_pp) = self.schema.compiled_pattern_properties.get() {
for (compiled_re, sub_schema) in compiled_pp {
for (key, child_instance) in obj {
if compiled_re.0.is_match(key) {
let new_path = self.join_path(key);
let is_ref = match &sub_schema.type_ {
Some(crate::database::object::SchemaTypeOrArray::Single(t)) => {
!crate::database::object::is_primitive_type(t)
}
_ => false,
};
let next_extensible = if is_ref { false } else { self.extensible };
let derived = self.derive(
sub_schema,
child_instance,
&new_path,
HashSet::new(),
next_extensible,
false,
Some(self.instance),
);
let item_res = derived.validate()?;
result.merge(item_res);
result.evaluated_keys.insert(key.to_string());
}
}
}
}
if let Some(ref additional_schema) = self.schema.additional_properties {
for (key, child_instance) in obj {
let mut locally_matched = false;
if let Some(props) = &self.schema.properties
&& props.contains_key(&key.to_string())
{
locally_matched = true;
}
if !locally_matched
&& let Some(compiled_pp) = self.schema.compiled_pattern_properties.get()
{
for (compiled_re, _) in compiled_pp {
if compiled_re.0.is_match(key) {
locally_matched = true;
break;
}
}
}
if !locally_matched {
let new_path = self.join_path(key);
let is_ref = match &additional_schema.type_ {
Some(crate::database::object::SchemaTypeOrArray::Single(t)) => {
!crate::database::object::is_primitive_type(t)
}
_ => false,
};
let next_extensible = if is_ref { false } else { self.extensible };
let derived = self.derive(
additional_schema,
child_instance,
&new_path,
HashSet::new(),
next_extensible,
false,
Some(self.instance),
);
let item_res = derived.validate()?;
result.merge(item_res);
result.evaluated_keys.insert(key.to_string());
}
}
}
if let Some(ref property_names) = self.schema.property_names {
for key in obj.keys() {

View File

@ -14,7 +14,6 @@ impl<'a> ValidationContext<'a> {
let conflicts = self.schema.type_.is_some()
|| self.schema.properties.is_some()
|| self.schema.required.is_some()
|| self.schema.additional_properties.is_some()
|| self.schema.items.is_some()
|| self.schema.cases.is_some()
|| self.schema.one_of.is_some()

View File

@ -42,6 +42,7 @@ impl<'a> ValidationContext<'a> {
code: "PATTERN_VIOLATED".to_string(),
values: Some(HashMap::from([
("pattern".to_string(), self.schema.pattern.clone().unwrap_or_default()),
("value".to_string(), s.to_string()),
])),
path: self.path.to_string(),
});
@ -54,6 +55,7 @@ impl<'a> ValidationContext<'a> {
code: "PATTERN_VIOLATED".to_string(),
values: Some(HashMap::from([
("pattern".to_string(), pattern.to_string()),
("value".to_string(), s.to_string()),
])),
path: self.path.to_string(),
});