-
Notifications
You must be signed in to change notification settings - Fork 144
Open
axa-ch/json-logic-js
#4Description
Does an official JSON Schema (http://json-schema.org/) currently exists for json-logic syntax?
If not, do you think it would be possible?
iddan, AndyOGo, ludvigeriksson, acristu, flemming-n-larsen and 4 more
Metadata
Metadata
Assignees
Labels
No labels
Activity
jwadhams commentedon Mar 26, 2018
Not to my knowledge.
I think you'd end up writing a schema for every supported operation, right? And then any operation can take an operation in almost any argument, but in a few minutes Googling I couldn't find something inheritance-like to say:
{"+":[]} is a type of JsonLogic statement. It takes an array of numbers or "JsonLogic statements"
Maybe you could write one big schema that takes every supported operation as an optional property, but I'm not sure the format lets you say "you have to have exactly one of this huge property list"... and it doesn't play nice with adding operations.
What benefit do you expect from having a schema?
iddan commentedon May 18, 2018
json-logic
and a schema would be extremely helpfulAndyOGo commentedon Feb 19, 2019
Yes, indeed a JSON Schema would be awesome 🎉
AndyOGo commentedon Mar 18, 2019
@nasht00
@jwadhams
@iddan
This package is really great, unfortunately it seems that it isn't maintained anymore 😞
Therefore we forked it, rewrote it to ESnext and added JSON Schemas.
I just released
v2.0.1
at on npm@axa-ch/json-logic-js
@jwadhams
I hope we can return the ball to your original repo
yelworc commentedon Mar 20, 2019
Whoa, @AndyOGo – I was just evaluating
json-logic
for a project yesterday, and wondered if there was a schema to validate the resulting logic data – and here it is, added just a day before 😆Now if only the schema files were really hosted at the given URLs, my IDE (VS Code) could actually use them for validation 😏
AndyOGo commentedon Mar 20, 2019
@yelworc
Yeah, you are absolutely right, thats why I want to play the ball back to @jwadhams
So that all is nicely grouped together and publicly at jsonlogic.com
yelworc commentedon Mar 20, 2019
Hmm. After playing with it a little more, I'm starting to wonder if this is as helpful as I had hoped. The schema validates anything, due to the inclusion of
common/all-types
incommon/any
– which is fair, I guess, since theapply
function does accept any value as its first parameter, but that makes the whole thing a bit pointless. Am I missing something here?AndyOGo commentedon Mar 20, 2019
@yelworc
Yeah, you are absolutely right, actually ideally this would be
oneOf
instead ofanyOf
:https://github.com/axa-ch/json-logic-js/blob/d56799465c6ce011c23f09d45267bba55ae55ec7/schemas/common/any.json#L8
and maybe it works if
object
is removed from all-types here:https://github.com/axa-ch/json-logic-js/blob/d56799465c6ce011c23f09d45267bba55ae55ec7/schemas/common/all-types.json#L7
ACTUALLY IF I CHECK THE ORIGINALL CODE, IT SEEMS WOULD BE OKAY TO REMOVE
object
:json-logic-js/logic.js
Lines 209 to 219 in a15f528
Indeed
jsonLogic.apply
and all it's operands are very forgiving, so I decided to start with a forgiving schema.The first arg could also just be a boolean, as documented here:
https://github.com/jwadhams/json-logic-js#always-and-never
But I agree with you it's rather paradox and makes these schemas kinda pointless.
Though you can still replace
all-types
andany
with your own.Also it is possibly to nest any operator within each other, but semantically this is pointless too.
An ideal schema would also test, that a given operator makes sense.
I would also really like to get the inventors feedback @jwadhams
What do you think?
Edit:
Tracked here axa-ch#15
AndyOGo commentedon Mar 21, 2019
@yelworc
I just started to refactor the schemas to get rid of
anyOf
and replace it withoneOf
.axa-ch#16
All official tests pass now, so seems to be good.
AndyOGo commentedon Mar 21, 2019
@yelworc
I just released a fix version
2.0.1
.Works now with
oneOf
only and typeobject
is only allowed if it is not a logic object (any existing operator)yelworc commentedon Mar 21, 2019
@AndyOGo cool! This did fix one false negative I saw before (
{ if: [true, 'x', 'y'] }
, for what it's worth).Agreed, I'd appreciate some feedback by the maintainer, too; e.g. thoughts regarding a potential future major version with less permissive input handling.
(I'm a bit concerned about the general maintenance status of the project, so I'm glad to see the activity in your fork!)
AndyOGo commentedon Mar 21, 2019
@yelworc
The last thing which is not ideal I see is, that currently all operations can be combined with any other operator. Tracked here: axa-ch#17
If you see any other issues, please feel free to create a ticket.
jwadhams commentedon Mar 21, 2019
Thank you all for your hard work, this is spectacular. I haven't been able to dedicate as much time to this library as I'd like.
@AndyOGo I'll take a look at your repo and see if we're in a position to merge up. It looks like really great, thoughtful work.
AndyOGo commentedon May 29, 2020
@jwadhams
We just migrated from
draft-04
todraft-07
withv2.2.2
.5 remaining items