From f15e808d4c066b9261d3f7882c7ee11b1976f232 Mon Sep 17 00:00:00 2001 From: drbh Date: Mon, 29 Jul 2024 10:07:25 -0400 Subject: [PATCH] fix: reject grammars without properties (#2309) --- router/src/validation.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/router/src/validation.rs b/router/src/validation.rs index 07ad14c9..1913a2ce 100644 --- a/router/src/validation.rs +++ b/router/src/validation.rs @@ -353,6 +353,14 @@ impl Validation { .compile(&json) .map_err(|e| ValidationError::InvalidGrammar(e.to_string()))?; + // The schema can be valid but lack properties. + // We need properties for the grammar to be successfully parsed in Python. + // Therefore, we must check and throw an error if properties are missing. + json.get("properties") + .ok_or(ValidationError::InvalidGrammar( + "Grammar must have a 'properties' field".to_string(), + ))?; + // Serialize json to string ValidGrammar::Json( serde_json::to_string(&json)