Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

add json schemas #4

Merged
merged 56 commits into from
Mar 15, 2019
Merged

add json schemas #4

merged 56 commits into from
Mar 15, 2019

Conversation

AndyOGo
Copy link

@AndyOGo AndyOGo commented Mar 5, 2019

fixes #2
fixes jwadhams#55

Added

  • Adds JSON schemas for all existing operators
  • Extended remote tests to also validate the logic by json schema

@AndyOGo AndyOGo added the enhancement New feature or request label Mar 5, 2019
@AndyOGo AndyOGo self-assigned this Mar 5, 2019
@AndyOGo AndyOGo changed the title chore: npm i ajv ajv-cli add json schemas Mar 5, 2019
@AndyOGo AndyOGo force-pushed the feature/add-json-schemas-for-aletheia branch from f100fde to 49347e8 Compare March 5, 2019 16:21
@@ -0,0 +1,55 @@
{
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope this schema implements all features documented here:
http://jsonlogic.com/operations.html#var

"title": "Any"
},
{
"$ref": "http://jsonlogic.com/schemas/operators/operators/variable.json"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other possible items for logical operators?
http://jsonlogic.com/operations.html#logic-and-boolean-operations

@@ -0,0 +1,28 @@
{
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@AndyOGo AndyOGo Mar 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lina-salih
@mjenny
May we should strictly keep the original underscore-case 🤔
missingSome to missing_some, same for all other files #11

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be consistent :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this one, all others within a separate PR

@AndyOGo AndyOGo requested review from l-salih and storm1ng March 7, 2019 13:16
@AndyOGo AndyOGo force-pushed the feature/add-json-schemas-for-aletheia branch from 5b02725 to d70bf54 Compare March 14, 2019 10:59

"title": "All",
"description": "Any valid JSON data type.",
"type": ["array", "boolean", "null", "number", "object", "string"]
Copy link
Author

@AndyOGo AndyOGo Mar 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need this for hardcoded static values...
But it forces us to use anyOf instead of oneOf below 🤔

{ "$ref": "http://jsonlogic.com/schemas/operators/string/cat.json" },
{ "$ref": "http://jsonlogic.com/schemas/operators/string/substr.json" },

{ "$ref": "http://jsonlogic.com/schemas/common/all-types.json" }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This schema is very loose, mainly because the API itself is very forgiving

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case a forgiving APi is nice

@AndyOGo AndyOGo force-pushed the feature/add-json-schemas-for-aletheia branch from 8381e38 to 0753e40 Compare March 15, 2019 08:26
"$id": "http://jsonlogic.com/schemas/operators/misc/method.json",

"title": "method",
"description": "If your rule needs to call a method on an object, you can use the built-in method operation.\n You can also pass an array of arguments into the methot.",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lina-salih
@mjenny
The only operator documented on a other page:
http://jsonlogic.com/add_operation.html#calling-methods-on-objects

Copy link

@l-salih l-salih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NICE!

{ "$ref": "http://jsonlogic.com/schemas/operators/string/cat.json" },
{ "$ref": "http://jsonlogic.com/schemas/operators/string/substr.json" },

{ "$ref": "http://jsonlogic.com/schemas/common/all-types.json" }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in this case a forgiving APi is nice

{
"type": "number",
"title": "Index",
"description": "You can also use the var operator to access an array by numeric index."
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"description": "An array with one or three elements.",
"type": "array",
"minItems": 1,
"maxItems": 3,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it enough when we provide one-or-more args?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so too at the beginning, then I saw that for example + and * take any number of arguments from 1 to infinity.
But - and / take only up to 2 - no more.

And then there are other special ops which take up to 3 like < and <= (in contrast to > and >=).

if is the most complex number of args, it 2n + 1, so 1, 3, 5, 7, 9, etc.

To make all of this even more complex, all operators support a single argument without an array.
It even doesn't matter if the provided number of arguments make sense, jsonLogic.apply will try it's best to never fail and output nonsense in the worst case 😅

"oneOf": [
{
"title": "Single Array",
"description": "An array with just one element.",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think unary and one-or-more args cover all constellations 🤔

@@ -0,0 +1,28 @@
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be consistent :)

@AndyOGo AndyOGo merged commit 8aec89c into master Mar 15, 2019
@AndyOGo AndyOGo deleted the feature/add-json-schemas-for-aletheia branch March 15, 2019 13:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON Schema define JSON schema for all operators
2 participants