Hello! I've just started working with Pact, and I apologize if there's something obvious that I've missed. But I've run into what could possibly be a bug, or maybe just something that's not supported. Here's what I'm trying to do:
I have a provider that returns a JSON array in the following format:
[ {
"clearedDate" : "07/22/2015",
"status" : "C",
"amount" : 15.0
}, {
"clearedDate" : "07/22/2015",
"status" : "C",
"amount" : 15.0
}, {
"clearedDate" : "07/22/2015",
"status" : "C",
"amount" : 15.0
} ]
So I'm writing a consumer pact for this endpoint. Now, since the array is the entire http body, it doesn't have a label/name - which means I can't use the arrayLike(String name) method on a PactDslJsonBody. The closest I've managed to get is this:
DslPart body = new PactDslJsonArray()
.eachLike()
.date("clearedDate", "mm/dd/yyyy")
.stringType("status")
.realType("amount")
.closeObject()
.closeArray();
However, this returns a pact file looking like this:
"response" : {
"status" : 200,
"headers" : {
"Content-Type" : "application/json"
},
"body" : [ [ {
"amount" : 6.709851646E9,
"status" : "MNDJHNtmnzGNiBIIQyOF",
"clearedDate" : "22/23/2015"
} ] ],
"matchingRules" : {
"$.body[0][*].status" : {
"match" : "type"
},
"$.headers.Content-Type" : {
"regex" : "application/json"
},
"$.body[0][*].clearedDate" : {
"date" : "mm/dd/yyyy"
},
"$.body[0][*].amount" : {
"match" : "real"
},
"$.body[0]" : {
"min" : 0
}
}
}
Obviously, the extra [ ] around the body are a problem. But the matchers also don't look right -- should that [0] be there before the wildcard [*]? From digging around in the code, it also looks like there's another matcher that should have been added and isn't there - "$.body" : { "match" : "type" }
I realized I could get the format of the body correct if I just dropped the final closeArray() in my code, but that results in this pact file:
"response" : {
"status" : 200,
"headers" : {
"Content-Type" : "application/json"
},
"body" : [ {
"amount" : 9.329956477E9,
"status" : "qzDcbvVfZAiXnYNTuabk",
"clearedDate" : "38/23/2015"
} ],
"matchingRules" : {
"$.body[*].clearedDate" : {
"date" : "mm/dd/yyyy"
},
"$.headers.Content-Type" : {
"regex" : "application/json"
},
"$.body[*].status" : {
"match" : "type"
},
"$.body[*].amount" : {
"match" : "real"
}
}
}
Now the body is right, but I'm missing the matchers "$.body" : { "match" : "type" } and "$.body" : { "min" : 0 }. The "min" is especially necessary, as the provider test will fail without it. I have tried both ways with minArrayLike() as well, with the same results.
So in conclusion, I'm stumped. Is this a bug? Or am I doing something wrong or unsupported? I very much appreciate any guidance you can offer. Thanks!