Skip to content

Commit f651b78

Browse files
Copilotmefellows
andauthored
refactor: extract effective_path in from_integration_json_v2 and remove redundant condition in bodies.rs
Agent-Logs-Url: https://github.com/pact-foundation/pact-reference/sessions/fb2a6dd6-ef83-46ac-af88-f8edd5445fc0 Co-authored-by: mefellows <53900+mefellows@users.noreply.github.com>
1 parent a56efcf commit f651b78

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

rust/pact_ffi/src/mock_server/bodies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn process_object(
6767
let result = if let Some(matcher_type) = obj.get("pact:matcher:type") {
6868
debug!("detected pact:matcher:type, will configure a matcher");
6969
process_matcher(obj, matching_rules, generators, &path, type_matcher, &matcher_type.clone())
70-
} else if obj.contains_key("expression") && !obj.contains_key("pact:matcher:type") {
70+
} else if obj.contains_key("expression") {
7171
debug!("detected 'expression' without 'pact:matcher:type', configuring ProviderStateGenerator");
7272
if let Some(generator) = Generator::from_map("ProviderState", obj) {
7373
let category = generator_category(matching_rules);

rust/pact_ffi/src/mock_server/handles.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,12 @@ fn from_integration_json_v2(
999999
let matching_rules = rules.add_category(category);
10001000
let path_or_status = [Category::PATH, Category::STATUS].contains(&matching_rules.name);
10011001
let query_or_header = [Category::QUERY, Category::HEADER].contains(&matching_rules.name);
1002+
// Compute the effective generator/rule path once: for PATH/STATUS, use the parent path
1003+
let effective_path = if path_or_status {
1004+
path.parent().unwrap_or(DocPath::root())
1005+
} else {
1006+
path.clone()
1007+
};
10021008

10031009
match serde_json::from_str(value) {
10041010
Ok(json) => match &json {
@@ -1059,12 +1065,7 @@ fn from_integration_json_v2(
10591065
debug!("detected pact:generator:type, will configure a generators");
10601066
if let Some(generator) = Generator::from_map(&json_to_string(gen), map) {
10611067
let category = generator_category(matching_rules);
1062-
let path = if path_or_status {
1063-
path.parent().unwrap_or(DocPath::root())
1064-
} else {
1065-
path.clone()
1066-
};
1067-
generators.add_generator_with_subcategory(category, path.clone(), generator);
1068+
generators.add_generator_with_subcategory(category, effective_path.clone(), generator);
10681069
}
10691070
}
10701071

@@ -1073,12 +1074,7 @@ fn from_integration_json_v2(
10731074
debug!("detected 'expression' without 'pact:matcher:type', configuring ProviderStateGenerator");
10741075
if let Some(generator) = Generator::from_map("ProviderState", map) {
10751076
let category = generator_category(matching_rules);
1076-
let gen_path = if path_or_status {
1077-
path.parent().unwrap_or(DocPath::root())
1078-
} else {
1079-
path.clone()
1080-
};
1081-
generators.add_generator_with_subcategory(category, gen_path, generator);
1077+
generators.add_generator_with_subcategory(category, effective_path.clone(), generator);
10821078
}
10831079
map.get("value").cloned().unwrap_or_default()
10841080
} else {

0 commit comments

Comments
 (0)