Skip to content

Commit

Permalink
$defs => definitions for draft 7
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Apr 3, 2023
1 parent b8279c5 commit 270f290
Show file tree
Hide file tree
Showing 22 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion packages/expressions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To learn more about JSON Schema, read [Understanding JSON Schema](https://json-s
## Adding a new expression

1. Describe arguments by creating a new file in [`schemas/`](schemas/) named `NewName.schema.json`. You can copy an existing function that has similar semantics to get started.
2. Add the new function in [`schemas/schema.json`](schemas/schema.json) to `$defs/function`.
2. Add the new function in [`schemas/schema.json`](schemas/schema.json) to `definitions/function`.
3. Create a new file in [`examples/`](./examples) named `NewName.json` with valid and invalid examples for the new function. See other examples for inspiration.
4. Run `yarn test` in `packages/expressions` and ensure tests pass.
5. Implement the function in [`lib/flipper/expressions/`](../../lib/flipper/expressions/).
Expand Down
2 changes: 1 addition & 1 deletion packages/expressions/schemas/All.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/All.schema.json",
"title": "All",
"description": "Returns true if all of the expressions return true.",
"$ref": "schema.json#/$defs/arguments-n"
"$ref": "schema.json#/definitions/arguments-n"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/Any.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/Any.schema.json",
"title": "Any",
"description": "Returns true if any of the expressions return true.",
"$ref": "schema.json#/$defs/arguments-n"
"$ref": "schema.json#/definitions/arguments-n"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/Boolean.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/Boolean.schema.json",
"title": "Boolean",
"description": "Cast a value to a boolean.",
"$ref": "schema.json#/$defs/argument"
"$ref": "schema.json#/definitions/argument"
}
8 changes: 4 additions & 4 deletions packages/expressions/schemas/Duration.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
"description": "A period of time expressed as a number of seconds, minutes, hours, days, weeks, months, or years.",
"type": "array",
"items": [
{ "$ref": "schema.json#/$defs/number" },
{ "$ref": "schema.json#/definitions/number" },
{
"anyOf": [
{ "$ref": "#/$defs/unit" },
{ "$ref": "schema.json#/$defs/function" }
{ "$ref": "#/definitions/unit" },
{ "$ref": "schema.json#/definitions/function" }
]
}
],
"minItems": 2,
"maxItems": 2,
"$defs": {
"definitions": {
"unit": {
"type": "string",
"enum": ["seconds", "minutes", "hours", "days", "weeks", "months", "years"],
Expand Down
2 changes: 1 addition & 1 deletion packages/expressions/schemas/Equal.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/Equal.schema.json",
"title": "Equal",
"description": "Compare two values for equality",
"$ref": "schema.json#/$defs/arguments-two"
"$ref": "schema.json#/definitions/arguments-two"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/GreaterThan.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/GreaterThan.schema.json",
"title": "GreaterThan",
"description": "Compare if the first argument is > the second argument.",
"$ref": "schema.json#/$defs/arguments-two"
"$ref": "schema.json#/definitions/arguments-two"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/GreaterThanOrEqualTo.schema.json",
"title": "GreaterThanOrEqualTo",
"description": "Compare if the first argument is >= the second argument.",
"$ref": "schema.json#/$defs/arguments-two"
"$ref": "schema.json#/definitions/arguments-two"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/LessThan.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/LessThan.schema.json",
"title": "LessThan",
"description": "Compare if the first argument is < the second argument.",
"$ref": "schema.json#/$defs/arguments-two"
"$ref": "schema.json#/definitions/arguments-two"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/LessThanOrEqualTo.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/LessThanOrEqualTo.schema.json",
"title": "LessThanOrEqualTo",
"description": "Compare if the first argument is < the second argument.",
"$ref": "schema.json#/$defs/arguments-two"
"$ref": "schema.json#/definitions/arguments-two"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/Max.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/Max.schema.json",
"title": "Max",
"description": "Returns the maximum value in a list.",
"$ref": "schema.json#/$defs/arguments-n"
"$ref": "schema.json#/definitions/arguments-n"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/Min.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/Min.schema.json",
"title": "Min",
"description": "Returns the minimum value in a list.",
"$ref": "schema.json#/$defs/arguments-n"
"$ref": "schema.json#/definitions/arguments-n"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/NotEqual.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/NotEqual.schema.json",
"title": "NotEqual",
"description": "Compare two values for equality",
"$ref": "schema.json#/$defs/arguments-two"
"$ref": "schema.json#/definitions/arguments-two"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/Number.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/Number.schema.json",
"title": "Number",
"description": "Cast a value to a number.",
"$ref": "schema.json#/$defs/argument"
"$ref": "schema.json#/definitions/argument"
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/Percentage.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "Percentage",
"description": "Cast a value to a percentage between 0 and 100.",
"type": "array",
"items": { "$ref": "schema.json#/$defs/number" },
"items": { "$ref": "schema.json#/definitions/number" },
"minItems": 1,
"maxItems": 1
}
4 changes: 2 additions & 2 deletions packages/expressions/schemas/PercentageOfActors.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "",
"type": "array",
"items": [
{ "$ref": "schema.json#/$defs/string" },
{ "$ref": "schema.json#/$defs/number" }
{ "$ref": "schema.json#/definitions/string" },
{ "$ref": "schema.json#/definitions/number" }
],
"minItems": 2,
"maxItems": 2
Expand Down
2 changes: 1 addition & 1 deletion packages/expressions/schemas/Property.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "Property",
"description": "Extract a property from context[properties].",
"type": "array",
"items": { "$ref": "schema.json#/$defs/string" },
"items": { "$ref": "schema.json#/definitions/string" },
"minItems": 1,
"maxItems": 1
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/Random.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
"title": "Random",
"description": "Return a random number",
"type": "array",
"items": { "$ref": "schema.json#/$defs/number" },
"items": { "$ref": "schema.json#/definitions/number" },
"maxItems": 1
}
2 changes: 1 addition & 1 deletion packages/expressions/schemas/String.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"$id": "https://www.flippercloud.io/expressions/String.schema.json",
"title": "String",
"description": "Cast a value to a string.",
"$ref": "schema.json#/$defs/argument"
"$ref": "schema.json#/definitions/argument"
}
6 changes: 3 additions & 3 deletions packages/expressions/schemas/Time.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"title": "Time",
"description": "A time in ISO8601 format",
"type": "array",
"items": { "$ref": "#/definitions/argument" },
"minItems": 1,
"maxItems": 1,
"items": { "$ref": "#/$defs/argument" },
"$defs": {
"definitions": {
"argument": {
"anyOf": [
{ "type": "string", "format": "date-time" },
{ "$ref": "schema.json#/$defs/function" }
{ "$ref": "schema.json#/definitions/function" }
]
}
}
Expand Down
31 changes: 20 additions & 11 deletions packages/expressions/schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@
"$id": "https://www.flippercloud.io/expressions/schema.json",
"title": "Flipper Expressions",
"description": "TODO",
"$ref": "#/$defs/expression",
"$defs": {
"$ref": "#/definitions/expression",
"definitions": {
"expression": {
"title": "Expression",
"description": "An expression can be a function or a constant (string, boolean, or number)",
"description": "An expression can be a Function or a Constant",
"anyOf": [
{ "$ref": "#/definitions/constant" },
{ "$ref": "#/definitions/function" }
]
},
"constant": {
"title": "Constant",
"description": "A constant value can be a string, number or boolean",
"anyOf": [
{ "$ref": "#/$defs/function" },
{ "type": "string" },
{ "type": "number" },
{ "type": "boolean" }
]
},
"function": {
"title": "Function",
"description": "A function is an object with a single property that is the name of the function and the value is the arguments to the function",
"type": "object",
"maxProperties": 1,
Expand Down Expand Up @@ -48,32 +56,33 @@
"description": "A constant string value or a function that returns a string",
"anyOf": [
{ "type": "string" },
{ "$ref": "#/$defs/function" }
{ "$ref": "#/definitions/function" }
]
},
"number": {
"description": "A constant numeric value or a function that returns a number",
"anyOf": [
{ "type": "number" },
{ "$ref": "#/$defs/function" }
{ "$ref": "#/definitions/function" }
]
},
"arguments-n": {
"description": "A single expression or an array of expressions",
"description": "An array of expressions",
"type": "array",
"items": { "$ref": "#/$defs/expression" }
"items": { "$ref": "#/definitions/expression" },
"minItems": 0
},
"arguments-two": {
"description": "An array with exactly two expressions",
"type": "array",
"items": { "$ref": "#/$defs/expression" },
"items": { "$ref": "#/definitions/expression" },
"minItems": 2,
"maxItems": 2
},
"argument": {
"description": "A single expression or an array with at most one expression",
"description": "An array with exactly one expression",
"type": "array",
"items": { "$ref": "#/$defs/expression" },
"items": { "$ref": "#/definitions/expression" },
"minItems": 1,
"maxItems": 1
}
Expand Down
3 changes: 1 addition & 2 deletions packages/expressions/test/schemas.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { describe, test, expect } from 'vitest'
import { validate } from '../lib'
import examples from '../examples'
import { validate, examples } from '../lib'

expect.extend({
toBeValid (received) {
Expand Down

0 comments on commit 270f290

Please sign in to comment.