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

Most upvoted 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:

  • Empty body (the Content-Length header will have a value of 0)
  • Empty string body (represented by the empty JSON string "", Content-Length will probably = 2)
  • Null body (represented by the JSON null value, Content-Length will probably = 4)
  • JSON body, which could be a number, true, false, a string, an array or an object.

In the Pact file, we represent no body and empty body differently:

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).