pact-foundation / pact-js

JS version of Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.
https://pact.io
Other
1.59k stars 343 forks source link

Matchers not applied in the generated pact json file if response object keys contain forward slashes #1065

Open shubhankard34 opened 1 year ago

shubhankard34 commented 1 year ago

Software versions

Issue Checklist

Please confirm the following:

Expected behaviour

Consider this partial interaction:

const interaction = {
    ...
    willRespondWith: {
        body: {
            ...
            'someInteger': integer(20)
        }
    }
}

The corresponding generated JSON file has matchers applied as follows:

"response" {
    ...
    "body": {
        "someInteger": 20
    },
    "matchingRules": {
        "$.body.someInteger": {
            "match": "type"
          }
    }
}

But if the key includes a forward-slash (/) like so:

const interaction = {
    ...
    willRespondWith: {
        body: {
            ...
            '/someInteger': integer(20)
        }
    }
}

The generated JSON doesn't contain matchingRules like so:

"response" {
    ...
    "body": {
        "/someInteger": 20
    }
}

Steps to reproduce

Use a matcher for a property of an object with key that includes a forward slash.

mefellows commented 1 year ago

@uglyog I remember seeing a similar issue, perhaps it was with Pact JVM. Do you know if this is supported in the rust core?

rholshausen commented 1 year ago

I have never seen this issue before. If there is a slash in the key, it needs to be escaped. I.e, the matching rule in the Pact file should be something like:

"matchingRules": {
        "$.body['/someInteger']": {
            "match": "type"
          }
    }