-
Notifications
You must be signed in to change notification settings - Fork 6
add json schemas #4
Changes from all commits
b021254
79816f1
4abb538
6a49a69
8655dfb
dd903eb
7c4db53
3395183
f076b21
3f7192d
ff5b6dc
4f3ffca
9b48163
4579c0e
d620029
a4adbb2
ef11e87
8da53db
322305e
c8afad6
3373fd3
29d2b26
a54c284
7208b32
61b7d34
ef7fd01
785e28a
1ec78ae
086c9bd
1dc98b8
1e20688
8135b03
ff1d42c
04d49f2
66038be
ae9c3a0
89e5588
e4c3dfe
5fd8381
65d2af6
ed8cb06
8e8d87e
59b156f
368a8a2
19d36a1
6ad80d8
6feef28
d70bf54
845e8cb
a0db8a7
ce9c892
0753e40
aa199c3
e77dbb6
e60b575
1827239
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/common/all-types.json", | ||
|
||
"title": "All", | ||
"description": "Any valid JSON data type.", | ||
"type": ["array", "boolean", "null", "number", "object", "string"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/common/any.json", | ||
|
||
"title": "All", | ||
"description": "Any valid JSON Logic data source.", | ||
|
||
"anyOf": [ | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/accessor/variable.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/accessor/missing.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/accessor/missing_some.json" }, | ||
|
||
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/add.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/divide.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/modulo.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/multiply.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/substract.json" }, | ||
|
||
{ "$ref": "http://jsonlogic.com/schemas/operators/array/all.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/array/filter.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/array/map.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/array/merge.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/array/none.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/array/reduce.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/array/some.json" }, | ||
|
||
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/and.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/equal.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/if.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/not.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/notEqual.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/notnot.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/or.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/strictEqual.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/strictNotEqual.json" }, | ||
|
||
{ "$ref": "http://jsonlogic.com/schemas/operators/misc/in.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/misc/log.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/misc/method.json" }, | ||
|
||
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/greater.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/greaterEqual.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/less.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/lessEqual.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/max.json" }, | ||
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/min.json" }, | ||
|
||
{ "$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" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in this case a forgiving APi is nice |
||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/common/binary-args.json", | ||
|
||
"title": "Binary Arg", | ||
"description": "Up to two args of valid JSON Logic data source.", | ||
|
||
"oneOf": [ | ||
{ | ||
"title": "Array", | ||
"description": "An array with one or two elements.", | ||
"type": "array", | ||
"minItems": 1, | ||
"maxItems": 2, | ||
"items": { | ||
"$ref": "http://jsonlogic.com/schemas/common/any.json" | ||
} | ||
}, | ||
{ | ||
"$ref": "http://jsonlogic.com/schemas/common/any.json", | ||
"title": "Single Arg", | ||
"description": "Note: binary operators can also take a single, non array argument:" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/common/one-or-more-args.json", | ||
|
||
"title": "1 or more args", | ||
"description": "With 1 or more arguments.", | ||
|
||
"oneOf": [ | ||
{ | ||
"title": "Single Array", | ||
"description": "An array with 1 or more elements.", | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { | ||
"$ref": "http://jsonlogic.com/schemas/common/any.json" | ||
} | ||
}, | ||
{ | ||
"$ref": "http://jsonlogic.com/schemas/common/any.json", | ||
"title": "Single Arg", | ||
"description": "Note: 1 or more operators can also take a single, non array argument:" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/common/pointer.json", | ||
|
||
"title": "Pointer", | ||
"description": "Schema to access properties of an object or items of an array by index.", | ||
|
||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"title": "Property", | ||
"description": "The key passed to var can use dot-notation to get the property of a property (to any depth you need):" | ||
}, | ||
{ | ||
"type": "number", | ||
"title": "Index", | ||
"description": "You can also use the var operator to access an array by numeric index." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/common/trinary-args.json", | ||
|
||
"title": "Trinary Args", | ||
"description": "Up to three args of valid JSON Logic data source.", | ||
|
||
"oneOf": [ | ||
{ | ||
"title": "Array", | ||
"description": "An array with one or three elements.", | ||
"type": "array", | ||
"minItems": 1, | ||
"maxItems": 3, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it enough when we provide one-or-more args? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 then there are other special ops which take up to 3 like
To make all of this even more complex, all operators support a single argument without an array. |
||
"items": { | ||
"$ref": "http://jsonlogic.com/schemas/common/any.json" | ||
} | ||
}, | ||
{ | ||
"$ref": "http://jsonlogic.com/schemas/common/any.json", | ||
"title": "Single Arg", | ||
"description": "Note: trinary operators can also take a single, non array argument:" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/common/unary-arg.json", | ||
|
||
"title": "Unary Arg", | ||
"description": "Only one valid JSON Logic data source.", | ||
|
||
"oneOf": [ | ||
{ | ||
"title": "Single Array", | ||
"description": "An array with just one element.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think unary and one-or-more args cover all constellations 🤔 |
||
"type": "array", | ||
"minItems": 1, | ||
"maxItems": 1, | ||
"items": { | ||
"$ref": "http://jsonlogic.com/schemas/common/any.json" | ||
} | ||
}, | ||
{ | ||
"$ref": "http://jsonlogic.com/schemas/common/any.json", | ||
"title": "Single Arg", | ||
"description": "Note: unary operators can also take a single, non array argument:" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/common/var.json", | ||
|
||
"title": "Var", | ||
"description": "Retrieve data from the provided data object.", | ||
|
||
"oneOf": [ | ||
{ | ||
"type": "array", | ||
"items": [ | ||
{ "$ref": "http://jsonlogic.com/schemas/common/pointer.json" }, | ||
{ | ||
"$ref": "http://jsonlogic.com/schemas/common/all-types.json", | ||
"title": "Default", | ||
"description": "You can supply a default, as the second argument, for values that might be missing in the data object." | ||
} | ||
] | ||
}, | ||
{ | ||
"$ref": "http://jsonlogic.com/schemas/common/pointer.json", | ||
"title": "Shortcut", | ||
"description": "If you like, we support syntactic sugar to skip the array around single arguments." | ||
}, | ||
{ | ||
"type": "string", | ||
"enum": [""], | ||
"title": "Entire data object", | ||
"description": "You can also use var with an empty string to get the entire data object – which is really useful in map, filter, and reduce rules." | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/json-logic.json", | ||
|
||
"title": "JSON-Logic Schema", | ||
"description": "Build complex rules, serialize them as JSON, share them between front-end and back-end.", | ||
|
||
"$ref": "http://jsonlogic.com/schemas/common/any.json" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/operators/accessor/missing.json", | ||
|
||
"title": "missing", | ||
"description": "Takes an array of data keys to search for (same format as var). Returns an array of any keys that are missing from the data object, or an empty array.", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["missing"], | ||
"properties": { | ||
"missing": { | ||
"$ref": "http://jsonlogic.com/schemas/common/var.json" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/operators/accessor/missing_some.json", | ||
|
||
"title": "missing_some", | ||
"description": "Takes a minimum number of data keys that are required, and an array of keys to search for (same format as var or missing). Returns an empty array if the minimum is met, or an array of the missing keys otherwise.", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["missing_some"], | ||
"properties": { | ||
"missing_some": { | ||
"type": "array", | ||
"minItems": 2, | ||
"maxItems": 2, | ||
"items": [ | ||
{ | ||
"type": "integer", | ||
"title": "Need-Count", | ||
"description": "Takes a minimum number of data keys that are required" | ||
}, | ||
{ | ||
"$ref": "http://jsonlogic.com/schemas/common/var.json", | ||
"description": "An array of keys to search for (same format as var or missing)." | ||
} | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hope this schema implements all features documented here: |
||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/operators/accessor/variable.json", | ||
|
||
"title": "var", | ||
"description": "Retrieve data from the provided data object.", | ||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["var"], | ||
"properties": { | ||
"var": { | ||
"$ref": "http://jsonlogic.com/schemas/common/var.json" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/operators/arithmetic/add.json", | ||
|
||
"title": "+", | ||
"description": "Addition. Because addition is associative, it happily take as many args as you want. Passing just one argument to + casts it to a number.", | ||
|
||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["+"], | ||
"properties": { | ||
"+": { | ||
"$ref": "http://jsonlogic.com/schemas/common/one-or-more-args.json" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/operators/arithmetic/divide.json", | ||
|
||
"title": "/", | ||
"description": "Division.", | ||
|
||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["/"], | ||
"properties": { | ||
"/": { | ||
"$ref": "http://jsonlogic.com/schemas/common/binary-args.json" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/operators/arithmetic/modulo.json", | ||
|
||
"title": "%", | ||
"description": "Module. Finds the remainder after the first argument is divided by the second argument.", | ||
|
||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["%"], | ||
"properties": { | ||
"%": { | ||
"$ref": "http://jsonlogic.com/schemas/common/binary-args.json" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"$id": "http://jsonlogic.com/schemas/operators/arithmetic/multiply.json", | ||
|
||
"title": "*", | ||
"description": "Multiplication. Because multiplication is associative, it happily take as many args as you want.", | ||
|
||
"type": "object", | ||
"additionalProperties": false, | ||
"required": ["*"], | ||
"properties": { | ||
"*": { | ||
"$ref": "http://jsonlogic.com/schemas/common/one-or-more-args.json" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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 ofoneOf
below 🤔