From 82cf6ac947d9ea3b66284a113497464b976236e9 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Wed, 12 Apr 2023 08:49:56 -0400 Subject: [PATCH] Add operator keyword to schemas --- packages/expressions/lib/schemas.js | 2 +- packages/expressions/schemas/Add.schema.json | 3 ++- packages/expressions/schemas/Divide.schema.json | 3 ++- packages/expressions/schemas/Duration.schema.json | 5 ++--- packages/expressions/schemas/Equal.schema.json | 3 ++- packages/expressions/schemas/GreaterThan.schema.json | 3 ++- .../expressions/schemas/GreaterThanOrEqualTo.schema.json | 3 ++- packages/expressions/schemas/LessThan.schema.json | 3 ++- packages/expressions/schemas/LessThanOrEqualTo.schema.json | 3 ++- packages/expressions/schemas/Multiply.schema.json | 3 ++- packages/expressions/schemas/NotEqual.schema.json | 3 ++- packages/expressions/schemas/Subtract.schema.json | 3 ++- packages/expressions/schemas/schema.json | 7 ++++--- 13 files changed, 27 insertions(+), 17 deletions(-) diff --git a/packages/expressions/lib/schemas.js b/packages/expressions/lib/schemas.js index 2b9127265..2dd162fe2 100644 --- a/packages/expressions/lib/schemas.js +++ b/packages/expressions/lib/schemas.js @@ -14,7 +14,7 @@ const ajv = new Ajv({ strict: true }) addFormats(ajv) - +ajv.addKeyword('operator') // Delegate property access to the schema definition const DelegateToDefinition = { diff --git a/packages/expressions/schemas/Add.schema.json b/packages/expressions/schemas/Add.schema.json index 5b9ba5071..fb3f164fb 100644 --- a/packages/expressions/schemas/Add.schema.json +++ b/packages/expressions/schemas/Add.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/Add.schema.json", "title": "Add", "description": "Add two values", - "$ref": "schema.json#/definitions/arguments-two" + "operator": "+", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/Divide.schema.json b/packages/expressions/schemas/Divide.schema.json index b6cd701ff..5ec157109 100644 --- a/packages/expressions/schemas/Divide.schema.json +++ b/packages/expressions/schemas/Divide.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/Divide.schema.json", "title": "Divide", "description": "Divide two values", - "$ref": "schema.json#/definitions/arguments-two" + "operator": "/", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/Duration.schema.json b/packages/expressions/schemas/Duration.schema.json index 5684d5eaf..8da463377 100644 --- a/packages/expressions/schemas/Duration.schema.json +++ b/packages/expressions/schemas/Duration.schema.json @@ -7,12 +7,11 @@ "items": [ { "$ref": "schema.json#/definitions/number" }, { - "title": "Unit", "anyOf": [ { + "title": "Unit", "type": "string", - "enum": ["seconds", "minutes", "hours", "days", "weeks", "months", "years"], - "default": "seconds" + "enum": ["seconds", "minutes", "hours", "days", "weeks", "months", "years"] }, { "$ref": "schema.json#/definitions/function" } ] diff --git a/packages/expressions/schemas/Equal.schema.json b/packages/expressions/schemas/Equal.schema.json index 52f5cf1f9..84c533c01 100644 --- a/packages/expressions/schemas/Equal.schema.json +++ b/packages/expressions/schemas/Equal.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/Equal.schema.json", "title": "Equal", "description": "Compare two values for equality", - "$ref": "schema.json#/definitions/arguments-two" + "operator": "==", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/GreaterThan.schema.json b/packages/expressions/schemas/GreaterThan.schema.json index 9d996ac8d..2f714ad46 100644 --- a/packages/expressions/schemas/GreaterThan.schema.json +++ b/packages/expressions/schemas/GreaterThan.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/GreaterThan.schema.json", "title": "GreaterThan", "description": "Compare if the first argument is > the second argument.", - "$ref": "schema.json#/definitions/arguments-two" + "operator": ">", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/GreaterThanOrEqualTo.schema.json b/packages/expressions/schemas/GreaterThanOrEqualTo.schema.json index 3eebfb45e..db4879ee9 100644 --- a/packages/expressions/schemas/GreaterThanOrEqualTo.schema.json +++ b/packages/expressions/schemas/GreaterThanOrEqualTo.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/GreaterThanOrEqualTo.schema.json", "title": "GreaterThanOrEqualTo", "description": "Compare if the first argument is >= the second argument.", - "$ref": "schema.json#/definitions/arguments-two" + "operator": ">=", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/LessThan.schema.json b/packages/expressions/schemas/LessThan.schema.json index f7d82f054..9c2e07b0f 100644 --- a/packages/expressions/schemas/LessThan.schema.json +++ b/packages/expressions/schemas/LessThan.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/LessThan.schema.json", "title": "LessThan", "description": "Compare if the first argument is < the second argument.", - "$ref": "schema.json#/definitions/arguments-two" + "operator": "<", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/LessThanOrEqualTo.schema.json b/packages/expressions/schemas/LessThanOrEqualTo.schema.json index 8acb178ea..2cc871121 100644 --- a/packages/expressions/schemas/LessThanOrEqualTo.schema.json +++ b/packages/expressions/schemas/LessThanOrEqualTo.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/LessThanOrEqualTo.schema.json", "title": "LessThanOrEqualTo", "description": "Compare if the first argument is < the second argument.", - "$ref": "schema.json#/definitions/arguments-two" + "operator": "<=", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/Multiply.schema.json b/packages/expressions/schemas/Multiply.schema.json index b3e12e540..6a8b6d517 100644 --- a/packages/expressions/schemas/Multiply.schema.json +++ b/packages/expressions/schemas/Multiply.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/Multiply.schema.json", "title": "Multiply", "description": "Multiply two values", - "$ref": "schema.json#/definitions/arguments-two" + "operator": "*", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/NotEqual.schema.json b/packages/expressions/schemas/NotEqual.schema.json index 411312f0f..007f84cfc 100644 --- a/packages/expressions/schemas/NotEqual.schema.json +++ b/packages/expressions/schemas/NotEqual.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/NotEqual.schema.json", "title": "NotEqual", "description": "Compare two values for equality", - "$ref": "schema.json#/definitions/arguments-two" + "operator": "!=", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/Subtract.schema.json b/packages/expressions/schemas/Subtract.schema.json index 7ab407583..053bc6ec5 100644 --- a/packages/expressions/schemas/Subtract.schema.json +++ b/packages/expressions/schemas/Subtract.schema.json @@ -3,5 +3,6 @@ "$id": "https://www.flippercloud.io/expressions/Subtract.schema.json", "title": "Subtract", "description": "Subtract two values", - "$ref": "schema.json#/definitions/arguments-two" + "operator": "-", + "$ref": "schema.json#/definitions/operation" } diff --git a/packages/expressions/schemas/schema.json b/packages/expressions/schemas/schema.json index f4531e259..8812fc08e 100644 --- a/packages/expressions/schemas/schema.json +++ b/packages/expressions/schemas/schema.json @@ -22,7 +22,8 @@ }, { "title": "Boolean", - "type": "boolean" + "type": "boolean", + "enum": [true, false] } ] }, @@ -82,8 +83,8 @@ "items": { "$ref": "#" }, "minItems": 0 }, - "arguments-two": { - "title": "Comparison", + "operation": { + "title": "Operation", "description": "An array with exactly two expressions", "type": "array", "items": { "$ref": "#" },