pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

pact_verifier_cli: min max matchers do not seem to work #240

Closed livinglogic-nl closed 1 year ago

livinglogic-nl commented 1 year ago

I'm using pact_verifier_cli 0.9.19 with a version 3 PACT file. I have matching rules as the following:

"matchingRules": {
  "body": {
    "$": {
      "matchers": [
        {
          "match": "type"
        },
        {
          "min": "0"
        },
        {
          "max": "0"
        }
      ]
    }
  }
}

When verifying this and the response has an array of multiple items, it still gets verified. Is this expected behaviour?

mefellows commented 1 year ago

You can't specify an array matcher that has a minimum of 0 or maximum of 0. See https://docs.pact.io/faq#why-is-there-no-support-for-specifying-optional-attributes and #optional. If you want the array to have 0 elements, you don't need to use a matcher at all - simply specify the value as [] (or whatever equivalent your language expresses an empty array as).