serverlessworkflow / specification

Contains the official specification for the Serverless Workflow Domain Specific Language. It provides detailed guidelines and standards for defining, executing, and managing workflows in serverless environments, ensuring consistency and interoperability across implementations.
http://serverlessworkflow.io
Apache License 2.0
740 stars 146 forks source link

“ isAdult to true” this is not JsonPath syntax #157

Closed skyshaokai closed 3 years ago

skyshaokai commented 3 years ago

What is the question:

{ "isAdult" : "{{ $.[?(@.age > 18)] }}" } would set the value if isAdult to true, as the expression returns a non-empty subset of the JSON data. Similarly

“ isAdult to true, as the expression returns a non-empty subset of the JSON data”
This description in the specification (master branch) is not a function supported by jsonpath syntax. Who should implement it ?

tsurdilo commented 3 years ago

@sky132333 hi thanks for the question. If I understand it correctly you are saying that it is confusing since JsonPath returns an empty or non-empty result back and the docs say it can translate it to boolean values true/false, and then ask how or who should implement this?

The evaluation of expressions should be handled by the runtime impls. We use only JsonPath for expressions thus allowing for better portability of the markup (multiple expressions languages is much harder to be support by multiple runtimes).

So for this case, and lets take a Java impl for example, but any lang that supports JsonPath can do this as well, this expression can be evaluated on runtime as for example:

return JsonPath.parse(stateData).read(expression).isEmpty();

so basically you would evaluate the expression against the state data, and return true/false depending if its results are empty or not.

Hope this helps.

skyshaokai commented 3 years ago

@sky132333 hi thanks for the question. If I understand it correctly you are saying that it is confusing since JsonPath returns an empty or non-empty result back and the docs say it can translate it to boolean values true/false, and then ask how or who should implement this?

The evaluation of expressions should be handled by the runtime impls. We use only JsonPath for expressions thus allowing for better portability of the markup (multiple expressions languages is much harder to be support by multiple runtimes).

So for this case, and lets take a Java impl for example, but any lang that supports JsonPath can do this as well, this expression can be evaluated on runtime as for example:

return JsonPath.parse(stateData).read(expression).isEmpty();

so basically you would evaluate the expression against the state data, and return true/false depending if its results are empty or not.

Hope this helps.

Thank you for your answer . But there is no clear indication of whether to obtain JSON data or to calculate whether empty means true or false, which is easy to confuse implementers.

{ "isAdult" : true/false, }

OR

{ "isAdult": [ { "firstName": "John", "lastName": "Doe", "age": 26 } ] }

tsurdilo commented 3 years ago

@sky132333 ok I agree that the two examples given in the spec docs for example:

{
   "isAdult" : "{{ $.[?(@.age  > 18)] }}"
}

is ambiguous. The docs should clearly state that expression that should be evaluated to true/false should be used in switch state conditions. Otherwise it would be as you said considered an assignment for example "person": "{{ $.person }}"

Good point. I will make sure to update the docs to make this more clear.

tsurdilo commented 3 years ago

Pull Request: https://github.com/serverlessworkflow/specification/pull/170

tsurdilo commented 3 years ago

closed via https://github.com/serverlessworkflow/specification/pull/170