generating pact contract: how to create PactDslJsonBody that matches anything

740 views Asked by At

I am using Java to generate the Pact contract as a consumer. Here is an example of the response body that I would like the provider to verify

{
  "metadata": {
    "href": "${host}",
    "id": 40964176,
    "updated_at": {}
  },
  "record": {
     //Anything...
  },
  "id": "40964176",
  "type": "record",
  "record_number": 40964176
}

The value of record can be anything. I want the verification to pass as long as the value of record is an object. How should I do that?

1

There are 1 answers

0
Matthew Fellows On BEST ANSWER

Have you tried just passing it an empty object? Pact is generally accepting of objects having keys that weren't in the expected response, it only fails if keys that were expected are not present in the actual API.

So passing an empty object is essentially saying what you want.