diff --git a/rust/crates/runtime/src/g004_conformance.rs b/rust/crates/runtime/src/g004_conformance.rs index 93621de5..88d42be7 100644 --- a/rust/crates/runtime/src/g004_conformance.rs +++ b/rust/crates/runtime/src/g004_conformance.rs @@ -63,12 +63,27 @@ fn validate_lane_events(value: Option<&Value>, path: &str, errors: &mut Vec { @@ -89,7 +104,12 @@ fn validate_lane_events(value: Option<&Value>, path: &str, errors: &mut Vec, path: &str, errors: &mut Vec, path: &str, errors: &mut Vec, ) { - match get_path(root, path).and_then(Value::as_str) { + require_string_eq_at(root, path, path, expected, errors); +} + +fn require_string_eq_at( + root: &Value, + pointer: &str, + error_path: &str, + expected: &str, + errors: &mut Vec, +) { + match get_path(root, pointer).and_then(Value::as_str) { Some(actual) if actual == expected => {} Some(actual) => errors.push(G004ConformanceError::new( - path, + error_path, format!("expected '{expected}', got '{actual}'"), )), None => errors.push(G004ConformanceError::new( - path, + error_path, "required string field missing", )), } } -fn require_non_empty_string(root: &Value, path: &str, errors: &mut Vec) { - match get_path(root, path).and_then(Value::as_str) { - Some(value) if !value.trim().is_empty() => {} - Some(_) => errors.push(G004ConformanceError::new(path, "string must not be empty")), - None => errors.push(G004ConformanceError::new( - path, - "required string field missing", - )), - } -} - -fn require_one_of( +fn require_non_empty_string_at( root: &Value, - path: &str, + pointer: &str, + error_path: &str, + errors: &mut Vec, +) { + match get_path(root, pointer).and_then(Value::as_str) { + Some(value) if !value.trim().is_empty() => {} + Some(_) => errors.push(G004ConformanceError::new( + error_path, + "string must not be empty", + )), + None => errors.push(G004ConformanceError::new( + error_path, + "required string field missing", + )), + } +} + +fn require_one_of_at( + root: &Value, + pointer: &str, + error_path: &str, allowed: &[&str], errors: &mut Vec, ) { - match get_path(root, path).and_then(Value::as_str) { + match get_path(root, pointer).and_then(Value::as_str) { Some(value) if allowed.contains(&value) => {} Some(value) => errors.push(G004ConformanceError::new( - path, + error_path, format!("'{value}' is not one of {}", allowed.join(", ")), )), None => errors.push(G004ConformanceError::new( - path, + error_path, "required string field missing", )), } } -fn require_bool_true(root: &Value, path: &str, errors: &mut Vec) { - match get_path(root, path).and_then(Value::as_bool) { +fn require_bool_true_at( + root: &Value, + pointer: &str, + error_path: &str, + errors: &mut Vec, +) { + match get_path(root, pointer).and_then(Value::as_bool) { Some(true) => {} - Some(false) => errors.push(G004ConformanceError::new(path, "must be true")), + Some(false) => errors.push(G004ConformanceError::new(error_path, "must be true")), None => errors.push(G004ConformanceError::new( - path, + error_path, "required boolean field missing", )), }