I have a service that will respond to a request with a json blob, such as this:
{
"field1": 1,
"field2": "2",
"array": [1,2,3]
}
I know that I can test array
by using EachLike
, like this:
expected = {
"field1": Like(1),
"field2": Like("2"),
"array": EachLike(1)
}
The issue is that "array" is an optional field in the response. It may not exist at all, and if it doesn't, I still need the contract to validate. How do I define that a field in the response body must match a type if it exists, but that it may not exist at all?