From bd6e256b318ba936c1121ff11f4d070ec764b252 Mon Sep 17 00:00:00 2001 From: Matt Fellows <53900+mefellows@users.noreply.github.com> Date: Wed, 28 Feb 2024 10:08:22 +1100 Subject: [PATCH] feat: add pactffi_message_with_metadata_v2 Supports metadata with matching rules Fixes https://github.com/pact-foundation/pact-js/issues/1133 Fixes https://github.com/pact-foundation/pact-js/issues/745 --- native/consumer.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/native/consumer.cc b/native/consumer.cc index a1dcd4e4..98b6a5e8 100644 --- a/native/consumer.cc +++ b/native/consumer.cc @@ -1661,15 +1661,28 @@ Napi::Value PactffiMessageWithContents(const Napi::CallbackInfo& info) { return env.Undefined(); } + /** * Adds expected metadata to the Message * * * `key` - metadata key - * * `value` - metadata value. + * * `value` - metadata value, supports JSON structures with matchers and generators + * + * To include matching rules for the value, include the + * matching rule JSON format with the value as a single JSON document. I.e. + * + * ```c + * const char* value = "{\"value\": { \"ID\": \"sjhdjkshsdjh\", \"weight\": 100.5 }, \"pact:matcher:type\":\"type\"}"; + * pactffi_message_with_metadata_v2(handle, "TagData", value); + * ``` + * See [IntegrationJson.md](https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_ffi/IntegrationJson.md) + * + * # Safety + * The key and value parameters must be valid pointers to NULL terminated strings. * * C interface: * - * void pactffi_message_with_metadata(MessageHandle message_handle, + * void pactffi_message_with_metadata_v2(MessageHandle message_handle, * const char *key, * const char *value); */ @@ -1696,7 +1709,7 @@ Napi::Value PactffiMessageWithMetadata(const Napi::CallbackInfo& info) { std::string key = info[1].As().Utf8Value(); std::string value = info[2].As().Utf8Value(); - pactffi_message_with_metadata(handle, key.c_str(), value.c_str()); + pactffi_message_with_metadata_v2(handle, key.c_str(), value.c_str()); return env.Undefined(); }