MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / validate_required_fields

Function validate_required_fields

crates/openshell-ocsf/src/validation/schema.rs:45–57  ·  view source on GitHub ↗

Validate that all required fields from the schema are present in the event JSON. The OCSF schema stores attributes as an object where each key is a field name and the value contains a `requirement` field.

(event: &Value, schema: &Value)

Source from the content-addressed store, hash-verified

43/// The OCSF schema stores attributes as an object where each key is a field name
44/// and the value contains a `requirement` field.
45pub fn validate_required_fields(event: &Value, schema: &Value) {
46 if let Some(attrs) = schema.get("attributes").and_then(|a| a.as_object()) {
47 for (name, def) in attrs {
48 if def.get("requirement").and_then(|r| r.as_str()) == Some("required") {
49 assert!(
50 event.get(name).is_some(),
51 "Missing required field '{name}' in OCSF event. Event keys: {:?}",
52 event.as_object().map(|o| o.keys().collect::<Vec<_>>())
53 );
54 }
55 }
56 }
57}
58
59/// Validate that an enum field in the event has a valid value per the schema.
60///

Callers 1

Calls 2

getMethod · 0.45
as_strMethod · 0.45

Tested by 1