Skip to content
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

PATH is not resolving correctly #285

Open
mdebarros opened this issue Nov 11, 2021 · 3 comments
Open

PATH is not resolving correctly #285

mdebarros opened this issue Nov 11, 2021 · 3 comments

Comments

@mdebarros
Copy link

mdebarros commented Nov 11, 2021

I have seen some strange happenings with regard to how the JSON-PATH is resolving in the rules with "json-rules-engine": "6.1.2".

If you consider the following rule:

{
    "ruleId": 1,
    "description": "Returns an NDC exceeded error response (ML error 4001) from the simulator when transfer value is 123 in any currency",
    "conditions": {
        "all": [
            {
                "fact": "path",
                "operator": "equal",
                "value": "/transfers"
            },
            {
                "fact": "method",
                "operator": "equal",
                "value": "POST"
            },
            {
                "fact": "body",
                "operator": "equal",
                "value": "123",
                "path": "$.amount"
            }
        ]
    },
    "event": {
        "type": "simulateError",
        "params": {
            "statusCode": 500,
            "body": {
                "statusCode": "4001",
                "message": "Payer FSP insufficient liquidity"
            }
        }
    }
}

With the following payload:

{
  path: '/transfers',
  body: '123', // <-- Non-matching PATH
  method: 'POST',
}

The rule will still resolve and fire off the event which I believe is incorrect.

My expectation is that it should only resolve when the payload is as follows:

{
  path: '/transfers',
  body: {      // <-- correct body 
      amount: '123',  // <-- Matching PATH
  },
  method: 'POST',
}

Link for reference: https://github.com/mojaloop/mojaloop-simulator/pull/120/files#r747311386

@akmjenkins
Copy link

akmjenkins commented Nov 14, 2021

It's explicitly defined behaviour (as you can see by this test), but I'd argue it's poor design.

You can see at this line: https://github.com/CacheControl/json-rules-engine/blob/master/src/almanac.js#L158 if the fact value isn't an object, then the path is essentially ignored. I'd open up a PR that this should return undefined instead, but I'm questioning whether this library is still maintained. There's been 0 activity from the maintainer of this repo since June?

@mdebarros
Copy link
Author

mdebarros commented Nov 16, 2021

It's explicitly defined behaviour (as you can see by this test), but I'd argue it's poor design.

You can see at this line: https://github.com/CacheControl/json-rules-engine/blob/master/src/almanac.js#L158 if the fact value isn't an object, then the path is essentially ignored. I'd open up a PR that this should return undefined instead, but I'm questioning whether this library is still maintained. There's been 0 activity from the maintainer of this repo since June?

It still looks like it's being somewhat maintained.

I do see that the dependency version used by json-rules-engine is "jsonpath-plus": "^5.0.7" with the latest being v6.0.1. Perhaps it's worth first upgrading to see if jsonpath-plus functions any differently?

However, I do think your proposal for returning undefined makes sense regardless.

@aaron-harvey
Copy link

aaron-harvey commented Dec 17, 2021

It still looks like it's being somewhat maintained.

@CacheControl do you have an update on the status on the project? There are several issues/requests and I'm sure there are a few people who are able and willing to help contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants