Open NathanHazout opened 6 years ago
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?
json-logic
and a schema would be extremely helpfulYes, indeed a JSON Schema would be awesome 🎉
@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
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 😏
@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
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
in common/any
– which is fair, I guess, since the apply
function does accept any value as its first parameter, but that makes the whole thing a bit pointless. Am I missing something here?
@yelworc
Yeah, you are absolutely right, actually ideally this would be oneOf
instead of anyOf
:
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
:
https://github.com/jwadhams/json-logic-js/blob/a15f528919346f2ec7d82bd4fc91c41481546c01/logic.js#L209-L219
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
and any
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 https://github.com/axa-ch/json-logic-js/issues/15
@yelworc
I just started to refactor the schemas to get rid of anyOf
and replace it with oneOf
.
https://github.com/axa-ch/json-logic-js/pull/16
All official tests pass now, so seems to be good.
@yelworc
I just released a fix version 2.0.1
.
Works now with oneOf
only and type object
is only allowed if it is not a logic object (any existing operator)
@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!)
@yelworc The last thing which is not ideal I see is, that currently all operations can be combined with any other operator. Tracked here: https://github.com/axa-ch/json-logic-js/issues/17
If you see any other issues, please feel free to create a ticket.
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.
A year and a half later, any news?
@jwadhams Thanks for all your help efforts with this library, and with the Json-Logic project in general.
Is schema-support something you'd still consider? It would be great to have these schemas actually hosted at jsonlogic.com. I imagine this project is a labor of love, so I understand having limited time to devote to it, but I think this is a killer feature.
Has any progress been made on this issue? I have recently been working on a schema for validating json logics components myself but I would prefer to check that against any other attempts out there if there are any.
EDIT: Actually, I decided to upload my attempt at a json schema as pull request #136 . Tests so far seem fine, but I do not have the time or means to test every possible combination of expressions and arguments.
Does an official JSON Schema (http://json-schema.org/) currently exists for json-logic syntax?
If not, do you think it would be possible?