Repository navigation
Conversation
|
This PR changes the Pact file format, which is more that the original issue asked for. Changing the Pact file format requires changes for all language implementations, so has much larger implications. I think this PR needs to be split, with just the Integration JSON changes the original issue asked for in one. The other changes require an RFC process to be adopted. @YOU54F @mefellows what do you think? |
|
Yes, agree I think we should split it so that we can have support for OR in the existing frameworks now without requiring a major version bump. Most already support 4.0 format today, so could benefit from it right away. |
|
Created a new one PR #601 |
|
Yes to OR sooner, rather than later. RFC's take ages and I am near retirement (😂), seriously though, I would be up for an RFC raising as mentioned in your follow up PR. I would suggest closing this one down for now, or splitting it the change, building on top of your existing PR and maybe marking as a draft, so any viewers/reviewers are aware! |
Add support
ORcombined matchers with per-alternative values and rulesCloses #249
Problem
"combine": "OR"already exists in the pact file format, but it only works for a list of plain rules on one path, such asregex OR number. You can't write "this field is either an integer or an object with this shape", because each alternative needs its own example value and its own nested rules.Solution
Pact file format (V3/V4)
A matcher inside an
ORlist can now carry avariantattribute. It holds the alternative's examplevalueand the matchingrulesthat apply under that path:
json "$.a": { "combine": "OR", "matchers": [ { "match": "integer", "variant": { "value": 1, "rules": {} } }, { "match": "type", "variant": { "value": { "d": ["x"] }, "rules": { "$.d": { "matchers": [{ "match": "type", "min": 1 }] }, "$.d[*]": { "combine": "OR", "matchers": [{ "match": "type" }, { "match": "number" }] } } } } ] } ORinside an alternative.ORlist.Integration JSON (FFI)
pact:matcher:combine: "OR"is accepted on apact:matcher:typearray. Any matcher in that array with its ownvaluebecomes a variant, and its value is processed like a normal body, so nested matchers produce the alternative's rules:
json "a": { "pact:matcher:type": [ { "pact:matcher:type": "integer", "value": 1 }, { "pact:matcher:type": "type", "value": { "d": { "pact:matcher:type": "type", "min": 1, "value": [ ... ] } } } ], "pact:matcher:combine": "OR", "value": 1 } Bodies (JSON and XML text/attributes), headers and query parameters are supported.
Changes
MatchingRule::Variant(Box<MatchingRule>, Box<MatchingRuleVariant>)andMatchingRuleVariant { value, rules }, with JSON read/write, hash and equality.RuleList::to_v2_jsonwrites only the inner rule.compare_jsonmatchesORlists that contain variants by trying each alternative with its own rules. Mismatch paths are rebased onto the original path.ORis honoured on type mismatches and incompare_maps.Variantthroughmatches_variant_with.rule_list_from_integration_jsonis the single entry point for building aRuleListfrom integration JSON. It follows the style of Feat/composing matching rules #405.add_rule_list_to_category.matchers_from_integration_jsonnow contains the logic of the removedmatchers_from_jsonand is not deprecated.IntegrationJson.mddocumentsOR, including its limitations.Limitations
ORalternatives with values; text and attributes can.value.PACT_MATCHING_ENGINE=v2) doesn't supportORvariants. All V2 engine changes from this branch have been reverted.Tests
Variantround trip (V3/V4), V2 output, hash/equality and invalid inputOR, root$andNoUnexpectedKeysinteger() OR { d: eachLike(string() OR number()) }