Skip to content

Commit 613b7bd

Browse files
authored
feat: add pactffi_message_with_metadata_v2 (#493)
Supports metadata with matching rules Fixes pact-foundation/pact-js#1133 Fixes pact-foundation/pact-js#745
1 parent 8a909f0 commit 613b7bd

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

native/consumer.cc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,15 +1661,28 @@ Napi::Value PactffiMessageWithContents(const Napi::CallbackInfo& info) {
16611661
return env.Undefined();
16621662
}
16631663

1664+
16641665
/**
16651666
* Adds expected metadata to the Message
16661667
*
16671668
* * `key` - metadata key
1668-
* * `value` - metadata value.
1669+
* * `value` - metadata value, supports JSON structures with matchers and generators
1670+
*
1671+
* To include matching rules for the value, include the
1672+
* matching rule JSON format with the value as a single JSON document. I.e.
1673+
*
1674+
* ```c
1675+
* const char* value = "{\"value\": { \"ID\": \"sjhdjkshsdjh\", \"weight\": 100.5 }, \"pact:matcher:type\":\"type\"}";
1676+
* pactffi_message_with_metadata_v2(handle, "TagData", value);
1677+
* ```
1678+
* See [IntegrationJson.md](https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/IntegrationJson.md)
1679+
*
1680+
* # Safety
1681+
* The key and value parameters must be valid pointers to NULL terminated strings.
16691682
*
16701683
* C interface:
16711684
*
1672-
* void pactffi_message_with_metadata(MessageHandle message_handle,
1685+
* void pactffi_message_with_metadata_v2(MessageHandle message_handle,
16731686
* const char *key,
16741687
* const char *value);
16751688
*/
@@ -1696,7 +1709,7 @@ Napi::Value PactffiMessageWithMetadata(const Napi::CallbackInfo& info) {
16961709
std::string key = info[1].As<Napi::String>().Utf8Value();
16971710
std::string value = info[2].As<Napi::String>().Utf8Value();
16981711

1699-
pactffi_message_with_metadata(handle, key.c_str(), value.c_str());
1712+
pactffi_message_with_metadata_v2(handle, key.c_str(), value.c_str());
17001713

17011714
return env.Undefined();
17021715
}

0 commit comments

Comments
 (0)