How do I write PACT contract for { 'idList": [5, 6...
# pact-jvm
p
How do I write PACT contract for { 'idList": [5, 6] } where idList could vary in size I tried
Copy code
DslPart requestBody = LambdaDsl.newJsonBody((o) -> {
  o.array("idList", (arr)-> {
     arr.numberType(6);
});
This would work if I am passing only one value. If more than value need to be in the list then I have to add something like this...
Copy code
arr.numberType(6).numberType(7);
How can this be made generalized (like minArrayLike) so that one or more could be passed and contract is still valid
m
p
nope. When I use minArrayLike I get array of an array whereas i need just an array. Also each array is an jsonObj requiring key(name). In my case I just have list of values.
m
That doesn’t sound write to me
You should be able to add values to that, I’m sure
p
message has been deleted
b
I think
eachLike
,
minArrayLike
and
maxArrayLike
open a new object, so you can't use them for primitive types.
arr
in your example is the object for the
like
, not an array
p
yes, that's the problem. I was just showing Matt that I can't just add values only.
b
Yeah, it's just that calling it
arr
gives you misleading DSL expectations 🙂
p
I am looking for a generalized way to write contract for { 'idList": [5, 6] } where the list size could vary
b
Off the top of my head, I have no idea what the Java DSL has for matching arrays by primitive type. (Using both Java and the old DSL also won't be helping discoverability, but that's a little beside the point.)
I guess, from a higher philosophical level, do you have test cases where you really don't care about the values in that list (you might, just confirming)?
p
I could do this
Copy code
o.minArrayLike("categoryIds", 1, PactDslJsonRootValue.numberType(7), 2);
But this would pass [7,7] to provider. Is there a way to specify actual Ids that I would like to pass to provider.
b
Your original example does that, I think?
Copy code
arr.numberType(6).numberType(7);
The separate question I thought you were asking was for something like
eachLike
that works with primitives instead of objects 🤔