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

Commit 8aec89c

Browse files
authored
Merge pull request #4 from axa-ch/feature/add-json-schemas-for-aletheia
add json schemas
2 parents 38c531d + 1827239 commit 8aec89c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+833
-0
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
"@babel/core": "^7.3.3",
1717
"@babel/plugin-proposal-export-default-from": "^7.2.0",
1818
"@babel/preset-env": "^7.3.1",
19+
"ajv": "^6.10.0",
20+
"ajv-cli": "^3.0.0",
1921
"cross-env": "^5.2.0",
2022
"eslint": "^5.14.1",
2123
"eslint-config-airbnb": "^17.1.0",
@@ -24,6 +26,7 @@
2426
"eslint-plugin-jsx-a11y": "^6.2.1",
2527
"eslint-plugin-prettier": "^3.0.1",
2628
"eslint-plugin-react": "^7.12.4",
29+
"glob": "^7.1.3",
2730
"husky": "^1.3.1",
2831
"lint-staged": "^8.1.4",
2932
"prettier": "^1.16.4",
@@ -40,6 +43,7 @@
4043
"scripts": {
4144
"lint": "eslint src tests",
4245
"lint-fix": "npm run lint -- --fix",
46+
"lint:schemas": "ajv compile -s schemas/json-logic.json -r 'schemas/**/*.json'",
4347
"test": "cross-env NODE_ENV=test qunit 'tests/**/*.js' -r tap",
4448
"pretest": "npm run build-package",
4549
"build": "cross-env NODE_ENV=production npm run build-lib",

schemas/common/all-types.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "http://jsonlogic.com/schemas/common/all-types.json",
4+
5+
"title": "All",
6+
"description": "Any valid JSON data type.",
7+
"type": ["array", "boolean", "null", "number", "object", "string"]
8+
}

schemas/common/any.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "http://jsonlogic.com/schemas/common/any.json",
4+
5+
"title": "All",
6+
"description": "Any valid JSON Logic data source.",
7+
8+
"anyOf": [
9+
{ "$ref": "http://jsonlogic.com/schemas/operators/accessor/variable.json" },
10+
{ "$ref": "http://jsonlogic.com/schemas/operators/accessor/missing.json" },
11+
{ "$ref": "http://jsonlogic.com/schemas/operators/accessor/missing_some.json" },
12+
13+
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/add.json" },
14+
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/divide.json" },
15+
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/modulo.json" },
16+
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/multiply.json" },
17+
{ "$ref": "http://jsonlogic.com/schemas/operators/arithmetic/substract.json" },
18+
19+
{ "$ref": "http://jsonlogic.com/schemas/operators/array/all.json" },
20+
{ "$ref": "http://jsonlogic.com/schemas/operators/array/filter.json" },
21+
{ "$ref": "http://jsonlogic.com/schemas/operators/array/map.json" },
22+
{ "$ref": "http://jsonlogic.com/schemas/operators/array/merge.json" },
23+
{ "$ref": "http://jsonlogic.com/schemas/operators/array/none.json" },
24+
{ "$ref": "http://jsonlogic.com/schemas/operators/array/reduce.json" },
25+
{ "$ref": "http://jsonlogic.com/schemas/operators/array/some.json" },
26+
27+
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/and.json" },
28+
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/equal.json" },
29+
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/if.json" },
30+
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/not.json" },
31+
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/notEqual.json" },
32+
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/notnot.json" },
33+
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/or.json" },
34+
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/strictEqual.json" },
35+
{ "$ref": "http://jsonlogic.com/schemas/operators/logic/strictNotEqual.json" },
36+
37+
{ "$ref": "http://jsonlogic.com/schemas/operators/misc/in.json" },
38+
{ "$ref": "http://jsonlogic.com/schemas/operators/misc/log.json" },
39+
{ "$ref": "http://jsonlogic.com/schemas/operators/misc/method.json" },
40+
41+
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/greater.json" },
42+
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/greaterEqual.json" },
43+
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/less.json" },
44+
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/lessEqual.json" },
45+
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/max.json" },
46+
{ "$ref": "http://jsonlogic.com/schemas/operators/numeric/min.json" },
47+
48+
{ "$ref": "http://jsonlogic.com/schemas/operators/string/cat.json" },
49+
{ "$ref": "http://jsonlogic.com/schemas/operators/string/substr.json" },
50+
51+
{ "$ref": "http://jsonlogic.com/schemas/common/all-types.json" }
52+
]
53+
}

schemas/common/binary-args.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "http://jsonlogic.com/schemas/common/binary-args.json",
4+
5+
"title": "Binary Arg",
6+
"description": "Up to two args of valid JSON Logic data source.",
7+
8+
"oneOf": [
9+
{
10+
"title": "Array",
11+
"description": "An array with one or two elements.",
12+
"type": "array",
13+
"minItems": 1,
14+
"maxItems": 2,
15+
"items": {
16+
"$ref": "http://jsonlogic.com/schemas/common/any.json"
17+
}
18+
},
19+
{
20+
"$ref": "http://jsonlogic.com/schemas/common/any.json",
21+
"title": "Single Arg",
22+
"description": "Note: binary operators can also take a single, non array argument:"
23+
}
24+
]
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "http://jsonlogic.com/schemas/common/one-or-more-args.json",
4+
5+
"title": "1 or more args",
6+
"description": "With 1 or more arguments.",
7+
8+
"oneOf": [
9+
{
10+
"title": "Single Array",
11+
"description": "An array with 1 or more elements.",
12+
"type": "array",
13+
"minItems": 1,
14+
"items": {
15+
"$ref": "http://jsonlogic.com/schemas/common/any.json"
16+
}
17+
},
18+
{
19+
"$ref": "http://jsonlogic.com/schemas/common/any.json",
20+
"title": "Single Arg",
21+
"description": "Note: 1 or more operators can also take a single, non array argument:"
22+
}
23+
]
24+
}

schemas/common/pointer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "http://jsonlogic.com/schemas/common/pointer.json",
4+
5+
"title": "Pointer",
6+
"description": "Schema to access properties of an object or items of an array by index.",
7+
8+
"oneOf": [
9+
{
10+
"type": "string",
11+
"title": "Property",
12+
"description": "The key passed to var can use dot-notation to get the property of a property (to any depth you need):"
13+
},
14+
{
15+
"type": "number",
16+
"title": "Index",
17+
"description": "You can also use the var operator to access an array by numeric index."
18+
}
19+
]
20+
}

schemas/common/trinary-args.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "http://jsonlogic.com/schemas/common/trinary-args.json",
4+
5+
"title": "Trinary Args",
6+
"description": "Up to three args of valid JSON Logic data source.",
7+
8+
"oneOf": [
9+
{
10+
"title": "Array",
11+
"description": "An array with one or three elements.",
12+
"type": "array",
13+
"minItems": 1,
14+
"maxItems": 3,
15+
"items": {
16+
"$ref": "http://jsonlogic.com/schemas/common/any.json"
17+
}
18+
},
19+
{
20+
"$ref": "http://jsonlogic.com/schemas/common/any.json",
21+
"title": "Single Arg",
22+
"description": "Note: trinary operators can also take a single, non array argument:"
23+
}
24+
]
25+
}

schemas/common/unary-arg.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "http://jsonlogic.com/schemas/common/unary-arg.json",
4+
5+
"title": "Unary Arg",
6+
"description": "Only one valid JSON Logic data source.",
7+
8+
"oneOf": [
9+
{
10+
"title": "Single Array",
11+
"description": "An array with just one element.",
12+
"type": "array",
13+
"minItems": 1,
14+
"maxItems": 1,
15+
"items": {
16+
"$ref": "http://jsonlogic.com/schemas/common/any.json"
17+
}
18+
},
19+
{
20+
"$ref": "http://jsonlogic.com/schemas/common/any.json",
21+
"title": "Single Arg",
22+
"description": "Note: unary operators can also take a single, non array argument:"
23+
}
24+
]
25+
}

schemas/common/var.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "http://jsonlogic.com/schemas/common/var.json",
4+
5+
"title": "Var",
6+
"description": "Retrieve data from the provided data object.",
7+
8+
"oneOf": [
9+
{
10+
"type": "array",
11+
"items": [
12+
{ "$ref": "http://jsonlogic.com/schemas/common/pointer.json" },
13+
{
14+
"$ref": "http://jsonlogic.com/schemas/common/all-types.json",
15+
"title": "Default",
16+
"description": "You can supply a default, as the second argument, for values that might be missing in the data object."
17+
}
18+
]
19+
},
20+
{
21+
"$ref": "http://jsonlogic.com/schemas/common/pointer.json",
22+
"title": "Shortcut",
23+
"description": "If you like, we support syntactic sugar to skip the array around single arguments."
24+
},
25+
{
26+
"type": "string",
27+
"enum": [""],
28+
"title": "Entire data object",
29+
"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."
30+
}
31+
]
32+
}

schemas/json-logic.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"$id": "http://jsonlogic.com/schemas/json-logic.json",
4+
5+
"title": "JSON-Logic Schema",
6+
"description": "Build complex rules, serialize them as JSON, share them between front-end and back-end.",
7+
8+
"$ref": "http://jsonlogic.com/schemas/common/any.json"
9+
}

0 commit comments

Comments
 (0)