Skip to content

Commit f20bd60

Browse files
committed
Add/Subtract/Multiply/Divide functions
1 parent 9fa9916 commit f20bd60

File tree

9 files changed

+124
-0
lines changed

9 files changed

+124
-0
lines changed

examples/Add.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"valid": [
3+
{
4+
"expression": { "Add": [2, 2] },
5+
"result": { "enum": [4] }
6+
},
7+
{
8+
"expression": { "Add": ["a", "a"] },
9+
"result": { "enum": ["aa"] }
10+
},
11+
{
12+
"expression": { "Add": [{ "Property": "age" }, 3] },
13+
"context": { "properties": { "age": 18 }},
14+
"result": { "enum": [21] }
15+
}
16+
],
17+
"invalid": [
18+
{ "Add": [1, 2, 3] },
19+
{ "Add": [1] },
20+
{ "Add": 1 },
21+
{ "Add": null },
22+
{ "Add": [1, 2], "Any": [] }
23+
]
24+
}

examples/Divide.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"valid": [
3+
{
4+
"expression": { "Divide": [6, 2] },
5+
"result": { "enum": [3] }
6+
},
7+
{
8+
"expression": { "Divide": [3, 1.5] },
9+
"result": { "enum": [2.0] }
10+
},
11+
{
12+
"expression": { "Divide": [{ "Property": "age" }, 3] },
13+
"context": { "properties": { "age": 18 }},
14+
"result": { "enum": [6] }
15+
}
16+
],
17+
"invalid": [
18+
{ "Divide": [1, 2, 3] },
19+
{ "Divide": [1] },
20+
{ "Divide": 1 },
21+
{ "Divide": null },
22+
{ "Divide": [1, 2], "Any": [] }
23+
]
24+
}

examples/Multiply.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"valid": [
3+
{
4+
"expression": { "Multiply": [3, 2] },
5+
"result": { "enum": [6] }
6+
},
7+
{
8+
"expression": { "Multiply": ["foo", 2] },
9+
"result": { "enum": ["foofoo"] }
10+
},
11+
{
12+
"expression": { "Multiply": [{ "Property": "age" }, 3] },
13+
"context": { "properties": { "age": 18 }},
14+
"result": { "enum": [54] }
15+
}
16+
],
17+
"invalid": [
18+
{ "Multiply": [1, 2, 3] },
19+
{ "Multiply": [1] },
20+
{ "Multiply": 1 },
21+
{ "Multiply": null },
22+
{ "Multiply": [1, 2], "Any": [] }
23+
]
24+
}

examples/Subtract.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"valid": [
3+
{
4+
"expression": { "Subtract": [3, 2] },
5+
"result": { "enum": [1] }
6+
},
7+
{
8+
"expression": { "Subtract": [{ "Property": "age" }, 3] },
9+
"context": { "properties": { "age": 18 }},
10+
"result": { "enum": [15] }
11+
}
12+
],
13+
"invalid": [
14+
{ "Subtract": [1, 2, 3] },
15+
{ "Subtract": [1] },
16+
{ "Subtract": 1 },
17+
{ "Subtract": null },
18+
{ "Subtract": [1, 2], "Any": [] }
19+
]
20+
}

schemas/Add.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://www.flippercloud.io/expressions/Add.schema.json",
4+
"title": "Add",
5+
"description": "Add two values",
6+
"$ref": "schema.json#/definitions/arguments-two"
7+
}

schemas/Divide.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://www.flippercloud.io/expressions/Divide.schema.json",
4+
"title": "Divide",
5+
"description": "Divide two values",
6+
"$ref": "schema.json#/definitions/arguments-two"
7+
}

schemas/Multiply.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://www.flippercloud.io/expressions/Multiply.schema.json",
4+
"title": "Multiply",
5+
"description": "Multiply two values",
6+
"$ref": "schema.json#/definitions/arguments-two"
7+
}

schemas/Subtract.schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://www.flippercloud.io/expressions/Subtract.schema.json",
4+
"title": "Subtract",
5+
"description": "Subtract two values",
6+
"$ref": "schema.json#/definitions/arguments-two"
7+
}

schemas/schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
"maxProperties": 1,
3434
"minProperties": 1,
3535
"properties": {
36+
"Add": { "$ref": "Add.schema.json" },
3637
"All": { "$ref": "All.schema.json" },
3738
"Any": { "$ref": "Any.schema.json" },
3839
"Boolean": { "$ref": "Boolean.schema.json" },
40+
"Divide": { "$ref": "Divide.schema.json" },
3941
"Duration": { "$ref": "Duration.schema.json" },
4042
"Equal": { "$ref": "Equal.schema.json" },
4143
"GreaterThan": { "$ref": "GreaterThan.schema.json" },
@@ -44,6 +46,7 @@
4446
"LessThanOrEqualTo": { "$ref": "LessThanOrEqualTo.schema.json" },
4547
"Max": { "$ref": "Max.schema.json" },
4648
"Min": { "$ref": "Min.schema.json" },
49+
"Multiply": { "$ref": "Multiply.schema.json" },
4750
"NotEqual": { "$ref": "NotEqual.schema.json" },
4851
"Now": { "$ref": "Now.schema.json" },
4952
"Number": { "$ref": "Number.schema.json" },
@@ -52,6 +55,7 @@
5255
"Property": { "$ref": "Property.schema.json" },
5356
"Random": { "$ref": "Random.schema.json" },
5457
"String": { "$ref": "String.schema.json" },
58+
"Subtract": { "$ref": "Subtract.schema.json" },
5559
"Time": { "$ref": "Time.schema.json" }
5660
},
5761
"additionalProperties": false

0 commit comments

Comments
 (0)