Closed nlandjev closed 1 month ago
The problem is that eachKeyLike
doesn't do what you think. It applies the matching rules to the values, not the keys.
I'm going to deprecate those methods, and add ones that actually act on the keys.
I've added two new methods, so you can do something like
newJsonBody(body ->
body.object("a", aObj -> {
aObj.eachKeyMatching(Matchers.regexp("prop\\d+", "prop1"));
aObj.eachValueMatching("prop1", propObj -> propObj.stringType("value", "x"));
}))
I think this is what you want.
Hey @nlandjev, are you able to test with the current version and confirm?
Hi,
Thanks for the quick fix. It looks correct but I can't get the project to build, so I'm waiting for the next 4.6 release. When is it planned for?
I'll release it soon (some time this week). I have one more change I want to get into the release first.
4.6.12 is released
Thank you, I will check it out next week and close the issue.
We've tested this and it works as expected. I'm closing the issue. Thanks for implementing :)
We are using Pact to verify a JSON response payload that satisfies the following properties:
For example this object is valid (provided prop1 and prop2 match the regular expression):
We use the following code to generate the Pact JSON file (snippet just for the object):
This generates the following Pact file (snippet just for the object):
This leads to a problem on the producer side that the body in the example above get accepted even if prop1 and prop2 don't match the regular expression. If we change the matchers in line 7 and 10 in the Pact JSON above to "match": "type", then the body gets rejected as expected. Is there a way to specify this with eachKeyLike? Or is there another way to specify a regex for the keys to match?
Regards, Nikolay
Relevant versions from the pom file: au.com.dius.pact.consumer:junit5 -> 4.6.6 au.com.dius.pact.provider:junit5spring -> 4.6.6