Repository navigation
Conversation
Matchers in integration JSON can now be combined with OR using the `pact:matcher:combine` attribute. The rules are written to the pact file as an existing rule list combined with OR, so the pact file format is unchanged.
|
Thanks @sergewar, this is a really useful addition: it closes the gap in #249 and gives the language DSLs a way to express OR (and nullable values) without each one resolving it themselves, which unblocks pact-foundation/pact-ruby#420 and my "or null" query from #399. Although I think this is a big ol' footgun for users (with great power comes great responsibility), it is in the spec, the other core (pact-jvm) so it needs to be in pact-reference and the client languages! I ran it locally, along with the consumer libraries, and pulled together some follow-ups as stacked PRs on my fork. They're all optional, happy for any of them to be pulled into your change: Fixes
I set claude on creating tests in the compatibility suite, as I am working in that area for plugin support, and broader support across the client libraries. Many of these are still running in CI, I'll pick up any failures probably tomorrow (or a couple of days 😂 due to contention limits Tests
End-to-end in the consumer libraries, against a
A few small things on this PR itself
If you fancy taking a stab at an RFC for your other proposed change, feel free, I think I will be trying to raise one soon about indexed header and query values as it caused me pain when migrating the pact_broker (a ruby app) from the pact-ruby core to pact-rust, and some of the workarounds that ensued. It's a big ol' nut to crack, with lots of places to address, but feel embolded with the use of AI to help build up the compatability suite, and ability to test big changes across multiple clients, which has always been a huge time sink for me! An enjoyable one, but one none the less. |
…h's rules with different logic add_rule_list_to_category used to append OR rules to an existing AND list (or the reverse), silently changing how the existing rules are combined. Rules with a different logic now replace the existing ones with a warning, as Pact-JVM's `or` DSL does, and rules with the same logic are appended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lues for pact:matcher:combine * The combine value is not case-sensitive, and an invalid value writes null. * Rules inside an object value still apply to its children (null-or-object). * An OR matcher whose value is another matcher replaces that matcher's rules, with a warning, as Pact-JVM's or matcher does. * Remove the V2 matching engine limitation, now that it supports OR. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* The `or` action folded its results from OK, so it never failed. It now folds from the first child result. * Errors from the branches of a successful `or` are no longer reported as mismatches. * An object with rules combined with OR that include a null matcher now accepts a null value, and only checks the object's entries when the value is not null (new `json:not-null` action). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An invalid `pact:matcher:combine` value wrote the body value as `null`, while headers and query parameters kept it. The rules are still ignored and the error logged, but the example value (and any rules nested in it) is now kept for bodies too. Also documents that a generator must be on the outer object of an OR list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@YOU54F Thank you for your review. I updated this PR with your changes and with your suggestions. Regarding RFC, I'll look how to do this, but if you can provide an instruction - it will be amazing. |
|
Thanks @sergewa, will take a look when I get a chance, will probably be some time next week regarding the RFC process, the first RFC provided instructions on how to raise one. Any questions feel free to reach out here or on slack.pact.io 👍🏾 https://github.com/pact-foundation/roadmap/blob/master/rfc/0000-rfc-process.md |
Add support
pact:matcher:combine: "OR"in integration JSONSplit out of #599, following the review feedback there.
Problem
Integration JSON can only combine matchers with
AND. The pact file format already supports rule lists combined withOR("combine": "OR"), but language implementations had no way to create one through the FFI.Solution
You can now set
pact:matcher:combinenext to an array of matchers. It takesAND(the default) orOR; any other value is an error.It's written to the pact file in the existing format, so the pact file format doesn't change and no RFC or major version bump is needed:
V2 pact files still write only the first rule for a path, as before.
Changes
rule_list_from_integration_json: builds aRuleListusing the logic frompact:matcher:combine, in the same style as Feat/composing matching rules #405.add_rule_list_to_category.AND.IntegrationJson.mddocumentsORand its limitations.compare_jsonused to report a type mismatch straight away (object vs non-object, array vs non-array). When the path has anORrule list, it now applies those rules first, sotype OR nullon an object acceptsnull.compare_mapspasses when at least one matcher in anORlist matches.Limitations
value. Matchers that compare against the example (liketype) can only describe the shape of that example. For example,type OR nullon an object accepts an object of the same shape ornull, but not an array.PACT_MATCHING_ENGINE=v2) doesn't supportOR.Alternatives with their own example values and nested rules (e.g. "an integer, or an object of this shape") need a pact file format change. That part goes in a separate PR for the RFC process.
Tests
pact:matcher:combine, including invalid valuesORon values, objects, arrays and scalarsORon a JSON body and on query parameters