Matching rules against field name with a '.' character are not working
See original GitHub issueHi,
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?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:41 (36 by maintainers)
Top GitHub Comments
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)null
value, 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.
"\"\""
.