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)
| 43 | /// The OCSF schema stores attributes as an object where each key is a field name |
| 44 | /// and the value contains a `requirement` field. |
| 45 | pub 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 | /// |