Skip to content

Commit 8a32316

Browse files
committed
chore(v2-matching-engine): Support for-each over an array at the root of JSON document
1 parent 5adada1 commit 8a32316

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • rust/pact_matching/src/engine/bodies

rust/pact_matching/src/engine/bodies/json.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl JsonPlanBuilder {
4545
if !matchers.is_empty() {
4646
root_node.add(ExecutionPlanNode::annotation(format!("{} {}", path.last_field().unwrap_or_default(), matchers.generate_description(false))));
4747
root_node.add(build_matching_rule_node(&ExecutionPlanNode::value_node(json),
48-
&ExecutionPlanNode::resolve_current_value(path), &matchers, false));
48+
&ExecutionPlanNode::resolve_current_value(path), &matchers, false));
4949
} else {
5050
let mut match_node = ExecutionPlanNode::action("match:equality");
5151
match_node
@@ -130,8 +130,13 @@ impl JsonPlanBuilder {
130130

131131
if let Some(template) = items.first() {
132132
let mut for_each_node = ExecutionPlanNode::action("for-each");
133-
let marker = format!("{}*", path.last_field().unwrap_or_default());
133+
let marker = if path.is_root() {
134+
"$*".to_string()
135+
} else {
136+
format!("{}*", path.last_field().unwrap_or_default())
137+
};
134138
for_each_node.add(ExecutionPlanNode::value_node(marker.as_str()));
139+
135140
let item_path = path.parent()
136141
.unwrap_or_else(|| path.clone())
137142
.join_field(marker);

0 commit comments

Comments
 (0)