-
-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wildcards in keys #313
Comments
I have updated the DSLs to support wildcard keys, but it is not going to be pretty ;-) To match you JSON requires something like: DslPart body = new PactDslJsonBody()
.eachLike("articles")
.object("variants")
.eachKeyLike("001")
.object("bundles")
.eachKeyLike("001-A")
.stringType("description", "Some Description")
.eachLike("referencedArticles")
.id("bundleId", 23456L)
.closeObject()
.closeArray()
.closeObject()
.closeObject()
.closeObject()
.closeObject()
.closeObject()
.closeArray(); and this generates a pact file with the following body and matchers: {
"body": {
"articles": [
{
"variants": {
"001": {
"bundles": {
"001-A": {
"description": "Some Description",
"referencedArticles": [
{
"bundleId": 23456
}
]
}
}
}
}
}
]
},
"matchingRules": {
"$.body.articles": {
"min": 0,
"match": "type"
},
"$.body.articles[*].variants.*.bundles.*.referencedArticles": {
"min": 0,
"match": "type"
},
"$.body.articles[*].variants.*.bundles.*.description": {
"match": "type"
},
"$.body.articles[*].variants.*.bundles.*.referencedArticles[*].bundleId": {
"match": "type"
}
}
} |
Thanks, much appreciated! |
Hi Ronald, In our test, we generate the following pact:
The json provided by our simple mock service is:
And the test results in failures:
The key below "variants" is matched based on its value "0032". Is there a way to match it based on its type only? We started looking into Could you please point us into the right direction where to adapt the matcher? Thank you, |
Aah, yeah, sorry I missed that. I'll need to have another look, probably The line that needs to change is On 14 September 2016 at 01:16, Wolf Schlegel notifications@github.com
|
…o the expected one ignoring the keys #313
Ok, should work for you now. That was more complex than I initially envisioned, but I think we now have a good implementation. |
Hi Ronald, thanks for working on the issue and for your prompt answers! Unfortunately our test case still does not work. We created a pull request (#318) with the exact test setup mentioned by @WolfSchlegel above. Could you please have a look? Thanks. Best regards, |
I got your tests passing (it just needed a really small change), sorry for the inconvience. |
Hi Ronald, thanks a lot for your changes; they fixed the test for us as well. Have a nice weekend! Best regards, |
Please see #401 |
Please see #500 |
Parallel nested object mapping i am trying on that one please see the issue #500 |
Yes, please look at #500 |
Fixed link to issue #313 in consumer README.md
There should be a way to use wildcards on JSON object's keys, as it is possible for values (e.g. strings).
Twitter convo w/ @uglyog on this topic
Background
This is a part of the JSON API we're writing a CDC for:
There's one or more objects being used like an array (
001
,002
, ... and001-A
,001-B
, ...). Not pretty, but not possible to change that.I need something like this:
$.body.articles[*].variants.*.bundles.*.description
. Pact-JVM seems to allow wildcards (see README ), but I've not been able to do that in Java via the API. Also, I'm not trying to manually add it to the JSON as it is auto-generated. But the only API that does anything like this is for arrays (.eachLike()
, etc.).The text was updated successfully, but these errors were encountered: