pact-net: Matching rules against field name with a '.' character are not working
Hi,
I’m currently trying to test a contract with an Odata v4 endpoint.
As part of the Odata json format specifications the server usually includes information other than the raw data in the response called annotations.
Annotations are name/value pairs that have a dot (.) as part of the name, an example could be
"@odata.context": "http://localhost/$metadata#MyEntity/$entity"
Obviously I’m not interested in the exact value of the annotations field so I’m using type matchers and my pact looks something like:
{ "consumer": { "name": "OdataConsumer" }, "provider": { "name": "OdataProvider" }, "interactions": [ { "description": "A GET request to retrieve an Odata entity", "request": { "method": "get", "path": "/odata/MyEntity('1234')" }, "response": { "status": 200, "headers": { "Content-Type": "application/json; odata.metadata=minimal", "OData-Version": "4.0" }, "body": { "@odata.context": "http://localhost/$metadata#MyEntity/$entity", "anotherField": "someDataHere" }, "matchingRules": { "$.body.@odata.context": { "match": "type" }, "$.body.anotherField": { "match": "type" } } } } ], "metadata": { "pactSpecification": { "version": "2.0.0" } } }
As you can see the matching rule is not correctly escaping the annotation name and, as a result, it won’t be executed. My understanding is that the (.) is interpreted as a path separator.
Is there any way to fix this behavior having matching rules working against fields with a (.) as part of their names?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 41 (36 by maintainers)
Commits related to this issue
- fix(matching): use single quotes instead of double to escape keys with dots JsonPath gem does not correctly look up path when the key is quoted with double quotes. Not sure what to do if a key contai... — committed to pact-foundation/pact-support by bethesque 7 years ago
- chore: recreating https://github.com/SEEK-Jobs/pact-net/issues/103#issuecomment-325093953 — committed to pact-foundation/pact-ruby-standalone-e2e-example by bethesque 7 years ago
- fix: ensure Host header is correctly set Fixes: https://github.com/SEEK-Jobs/pact-net/issues/103#issuecomment-325072543 — committed to pact-foundation/pact-provider-verifier by bethesque 7 years ago
Thank @neilcampbell, @bethesque , @uglyog I just tested the new beta release and it’s working correctly, well done!
Also we are working on a library which makes producer tests trivial to implement and supports branching you can find it here
Let me know what you think!
Thanks
In Pact JVM there are the following values for JSON bodies:
"", Content-Length will probably = 2)nullvalue, Content-Length will probably = 4)true,false, a string, an array or an object.In the Pact file, we represent no body and empty body differently:
"body": ""to the pact file.Empty string bodies are a difficult one. The only way to represent it correctly is with escaped strings, e.g.
"\"\"".I’ve fixed the host problem in 1.4.4.
I’ve replicated the problem here
It’s actually the
@symbol causing the problem, as well as the dot. I’ll look into it.I’ve updated the code and released a new version of the ruby-standalone package (1.1.1).