From 9cc38a2f3da5b24cce9a9e39073799b7d05fe8c1 Mon Sep 17 00:00:00 2001 From: Ronald Holshausen Date: Tue, 27 Aug 2024 11:23:43 +1000 Subject: [PATCH] chore: do not write empty matching rules to the Pact file --- rust/pact_models/src/matchingrules/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rust/pact_models/src/matchingrules/mod.rs b/rust/pact_models/src/matchingrules/mod.rs index 18bd1ec2..606766df 100644 --- a/rust/pact_models/src/matchingrules/mod.rs +++ b/rust/pact_models/src/matchingrules/mod.rs @@ -1260,7 +1260,12 @@ impl MatchingRules { map.insert(name.to_string(), rules.to_v3_json()); } _ => { - map.insert(name.to_string(), sub_category.to_v3_json()); + let value = sub_category.to_v3_json(); + if let Some(values) = value.as_object() { + if !values.is_empty() { + map.insert(name.to_string(), value); + } + } } } map @@ -1922,7 +1927,8 @@ mod tests { "header" => { "item1" => [ MatchingRule::Regex("5".to_string()) ], "$['principal_identifier[account_id]']" => [ MatchingRule::Regex("\\w+".to_string()) ] - } + }, + "metadata" => {} }; }