Skip to content

Commit ea6eefb

Browse files
Copilotmefellows
andauthored
docs: clarify ProviderStateGenerator shorthand format in IntegrationJson.md; add warn log for missing value
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 f651b78 commit ea6eefb

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

rust/pact_ffi/IntegrationJson.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pactffi_with_request(handle, "PUT", "{\"value\": \"/path/to/100\", \"pact:matche
3535
The `ProviderState` generator allows values to be sourced from provider state parameters during provider verification.
3636
There are two formats for specifying a `ProviderState` generator:
3737

38-
### Shorthand format (expression only)
38+
### Shorthand format (expression only, no matching rule)
3939

4040
When you only need a `ProviderState` generator (without any matching rule), you can use the shorthand format with just
4141
the `expression` and `value` keys:
@@ -47,8 +47,10 @@ the `expression` and `value` keys:
4747
}
4848
```
4949

50-
This sets up a `ProviderStateGenerator` with the given expression and uses the `value` as the example value. This
51-
shorthand is supported for query parameters, headers, path, and request/response bodies.
50+
This sets up a `ProviderStateGenerator` with the given expression and uses the `value` as the example value. **No
51+
matching rule is configured** — the example value is used as-is during consumer test execution, and the generator
52+
replaces it with the resolved provider state value during provider verification. This shorthand is supported for query
53+
parameters, headers, path, and request/response bodies.
5254

5355
### Full format (with matcher)
5456

rust/pact_ffi/src/mock_server/bodies.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use lazy_static::lazy_static;
99
use multipart_2021 as multipart;
1010
use regex::Regex;
1111
use serde_json::{Map, Value};
12-
use tracing::{debug, error, trace};
12+
use tracing::{debug, error, trace, warn};
1313

1414
use pact_models::bodies::OptionalBody;
1515
use pact_models::content_types::ContentTypeHint;
@@ -73,7 +73,10 @@ pub fn process_object(
7373
let category = generator_category(matching_rules);
7474
generators.add_generator_with_subcategory(category, path.clone(), generator);
7575
}
76-
obj.get("value").cloned().unwrap_or(Value::Null)
76+
if !obj.contains_key("value") {
77+
warn!("ProviderStateGenerator shorthand at path '{}' has no 'value' key; example value will be null", path);
78+
}
79+
obj.get("value").cloned().unwrap_or_default()
7780
} else {
7881
debug!("Configuring a normal object");
7982
Value::Object(obj.iter()

rust/pact_ffi/src/mock_server/handles.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,9 @@ fn from_integration_json_v2(
10761076
let category = generator_category(matching_rules);
10771077
generators.add_generator_with_subcategory(category, effective_path.clone(), generator);
10781078
}
1079+
if !map.contains_key("value") {
1080+
warn!("ProviderStateGenerator shorthand at path '{}' has no 'value' key; example value will be null", path);
1081+
}
10791082
map.get("value").cloned().unwrap_or_default()
10801083
} else {
10811084
debug!("Configuring a normal value using the 'value' attribute");

0 commit comments

Comments
 (0)