advantagefse / json-logic-swift

A native Swift JsonLogic implementation. This parser accepts JsonLogic rules and executes them.
MIT License
25 stars 22 forks source link

Add support for number lookup in expression IN #31

Closed mauriciomaniglia closed 1 year ago

mauriciomaniglia commented 1 year ago

Details

Currently, the library does not support lookup for numbers in arrays, only Strings.

As an example, the Rule and Data below works correctly when we try it on the JsonLogic website, but not in this library.

Rule

{ "if": [ { "some" : [ {"var" : ""}, { "and": [ { "==": [{ "var": "id" }, "123"] }, { "all" : [ { "map": [ {"var":"componentAttributes.options"}, { "var": "value"} ] }, { "in":[{"var":""}, [1, 2] ] } ] } ] } ] }, 5 ] }

Data

[ { "id": "123", "componentAttributes":{ "options":[ { "value":1 }, { "value":2 } ] } } ]

Fix

I'm adding Integer and Double values support in the IN expression.

csknns commented 1 year ago

@mauriciomaniglia Thanks for providing a fix for this!

mauriciomaniglia commented 1 year ago

@csknns, can you add a new tag with this fix?

csknns commented 1 year ago

@mauriciomaniglia Sure done! tag 1.2.3