diff --git a/json/flags.json b/json/flags.json index a6a09a7..b440b36 100644 --- a/json/flags.json +++ b/json/flags.json @@ -2,7 +2,7 @@ "$id": "https://flagd.dev/schema/v0/flags.json", "$schema": "http://json-schema.org/draft-07/schema#", "title": "flagd Flag Configuration", - "description": "Defines flags for use in flagd, including typed variants and rules", + "description": "Defines flags for use in flagd, including typed variants and rules.", "type": "object", "properties": { "flags": { @@ -46,7 +46,7 @@ "patternProperties": { "^.{1,}$": { "$comment": "this relative ref means that targeting.json MUST be in the same dir, or available on the same HTTP path", - "$ref": "./targeting.json#/definitions/targeting" + "$ref": "./targeting.json" } } } @@ -71,7 +71,7 @@ "type": "string" }, "targeting": { - "$ref": "./targeting.json#/definitions/targeting" + "$ref": "./targeting.json" } }, "required": [ diff --git a/json/flags.yaml b/json/flags.yaml index 3a18693..04a3dc1 100644 --- a/json/flags.yaml +++ b/json/flags.yaml @@ -1,7 +1,7 @@ $id: "https://flagd.dev/schema/v0/flags.json" $schema: http://json-schema.org/draft-07/schema# title: flagd Flag Configuration -description: Defines flags for use in flagd, including typed variants and rules +description: Defines flags for use in flagd, including typed variants and rules. type: object properties: flags: @@ -35,7 +35,7 @@ properties: "^.{1,}$": $comment: this relative ref means that targeting.json MUST be in the same dir, or available on the same HTTP path - $ref: "./targeting.json#/definitions/targeting" + $ref: "./targeting.json" definitions: flag: $comment: base flag object; no title/description here, allows for better UX, @@ -56,7 +56,7 @@ definitions: if the targeting returns null). type: string targeting: - $ref: "./targeting.json#/definitions/targeting" + $ref: "./targeting.json" required: - state - defaultVariant diff --git a/json/targeting.json b/json/targeting.json index c70335a..5df5b6d 100644 --- a/json/targeting.json +++ b/json/targeting.json @@ -2,29 +2,20 @@ "$id": "https://flagd.dev/schema/v0/targeting.json", "$schema": "http://json-schema.org/draft-07/schema#", "title": "flagd Targeting", - "description": "Defines targeting logic for flagd; a extension of JSONLogic, including purpose-built feature-flagging operations.", + "description": "Defines targeting logic for flagd; a extension of JSONLogic, including purpose-built feature-flagging operations. Note that this schema applies to top-level objects; no additional properties are supported, including \"$schema\", which means built-in JSON-schema support is not possible in editors. Please use flags.json (which imports this schema) for a rich editor experience.", "type": "object", - "properties": { - "targeting": { - "$ref": "#/definitions/targeting" + "anyOf": [ + { + "$comment": "we need this to support empty targeting", + "type": "object", + "additionalProperties": false, + "properties": {} + }, + { + "$ref": "#/definitions/anyRule" } - }, + ], "definitions": { - "targeting": { - "title": "Targeting", - "description": "An expression returning a value which is coerced to a string to be used as a targeting key, or null (to fall back to defaultVariant). If targeting returns a value which is not a variant key, it's considered an error.", - "anyOf": [ - { - "$comment": "we need this to support empty targeting", - "type": "object", - "additionalProperties": false, - "properties": {} - }, - { - "$ref": "#/definitions/anyRule" - } - ] - }, "primitive": { "oneOf": [ { diff --git a/json/targeting.yaml b/json/targeting.yaml index eb48fcb..dee4490 100644 --- a/json/targeting.yaml +++ b/json/targeting.yaml @@ -1,44 +1,44 @@ $id: "https://flagd.dev/schema/v0/targeting.json" $schema: http://json-schema.org/draft-07/schema# title: flagd Targeting -description: Defines targeting logic for flagd; a extension of JSONLogic, including - purpose-built feature-flagging operations. +description: + Defines targeting logic for flagd; a extension of JSONLogic, including + purpose-built feature-flagging operations. Note that this schema applies + to top-level objects; no additional properties are supported, including "$schema", + which means built-in JSON-schema support is not possible in editors. + Please use flags.json (which imports this schema) for a rich editor experience. type: object -properties: - targeting: - $ref: "#/definitions/targeting" +anyOf: + - $comment: we need this to support empty targeting + type: object + additionalProperties: false + properties: {} + - $ref: "#/definitions/anyRule" definitions: - targeting: - title: Targeting - description: An expression returning a value which is coerced to a string to be - used as a targeting key, or null (to fall back to defaultVariant). If targeting - returns a value which is not a variant key, it's considered an error. - anyOf: - - $comment: we need this to support empty targeting - type: object - additionalProperties: false - properties: {} - - $ref: "#/definitions/anyRule" primitive: oneOf: - - description: When returned from rules, a null value "exits", the targeting, - and the "defaultValue" is returned, with the reason indicating the targeting - did not match. - type: 'null' - - description: When returned from rules, booleans are converted to strings ("true"/"false"), - and used to as keys to retrieve the associated value from the "variants" object. - Be sure that the returned string is present as a key in the variants! - type: boolean - - description: When returned from rules, the behavior of numbers is not defined. - type: number - - description: When returned from rules, strings are used to as keys to retrieve - the associated value from the "variants" object. Be sure that the returned - string is present as a key in the variants!. - type: string - - description: When returned from rules, strings are used to as keys to retrieve - the associated value from the "variants" object. Be sure that the returned - string is present as a key in the variants!. - type: array + - description: + When returned from rules, a null value "exits", the targeting, + and the "defaultValue" is returned, with the reason indicating the targeting + did not match. + type: "null" + - description: + When returned from rules, booleans are converted to strings ("true"/"false"), + and used to as keys to retrieve the associated value from the "variants" object. + Be sure that the returned string is present as a key in the variants! + type: boolean + - description: When returned from rules, the behavior of numbers is not defined. + type: number + - description: + When returned from rules, strings are used to as keys to retrieve + the associated value from the "variants" object. Be sure that the returned + string is present as a key in the variants!. + type: string + - description: + When returned from rules, strings are used to as keys to retrieve + the associated value from the "variants" object. Be sure that the returned + string is present as a key in the variants!. + type: array varRule: title: Var Operation description: Retrieve data from the provided data object. @@ -47,34 +47,33 @@ definitions: properties: var: anyOf: - - type: string - description: flagd automatically injects "$flagd.timestamp" (unix epoch) - and "$flagd.flagKey" (the key of the flag in evaluation) into the context. - pattern: "^\\$flagd\\.((timestamp)|(flagKey))$" - - not: - $comment: this is a negated (not) match of "$flagd.{some-key}", which is faster and more compatible that a negative lookahead regex - type: string - description: flagd automatically injects "$flagd.timestamp" (unix epoch) and "$flagd.flagKey" - (the key of the flag in evaluation) into the context. - pattern: "^\\$flagd\\..*$" - - type: array - $comment: this is to support the form of var with a default... there seems to be a bug here, where ajv gives a warning (not an error) because maxItems doesn't equal the number of entries in items, though this is valid in this case - minItems: 1 - items: - - type: string - additionalItems: - anyOf: - - type: - 'null' - - type: - boolean - - type: - string - - type: - number + - type: string + description: + flagd automatically injects "$flagd.timestamp" (unix epoch) + and "$flagd.flagKey" (the key of the flag in evaluation) into the context. + pattern: "^\\$flagd\\.((timestamp)|(flagKey))$" + - not: + $comment: this is a negated (not) match of "$flagd.{some-key}", which is faster and more compatible that a negative lookahead regex + type: string + description: + flagd automatically injects "$flagd.timestamp" (unix epoch) and "$flagd.flagKey" + (the key of the flag in evaluation) into the context. + pattern: "^\\$flagd\\..*$" + - type: array + $comment: this is to support the form of var with a default... there seems to be a bug here, where ajv gives a warning (not an error) because maxItems doesn't equal the number of entries in items, though this is valid in this case + minItems: 1 + items: + - type: string + additionalItems: + anyOf: + - type: "null" + - type: boolean + - type: string + - type: number missingRule: title: Missing Operation - description: Takes an array of data keys to search for (same format as var). Returns + 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 @@ -85,7 +84,8 @@ definitions: type: string missingSomeRule: title: Missing-Some Operation - description: Takes a minimum number of data keys that are required, and an array + 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 @@ -96,10 +96,10 @@ definitions: maxItems: 2 type: array items: - - type: number - - type: array - items: - type: string + - type: number + - type: array + items: + type: string binaryOrTernaryOp: type: array minItems: 2 @@ -112,16 +112,19 @@ definitions: properties: substr: title: Substring Operation - description: Get a portion of a string. Give a positive start position to return everything beginning at that index. + description: + Get a portion of a string. Give a positive start position to return everything beginning at that index. Give a negative start position to work backwards from the end of the string, then return everything. Give a positive length to express how many characters to return. $ref: "#/definitions/binaryOrTernaryOp" "<": - title: Less-Than/Between Operation. Can be used to test that one value is + title: + Less-Than/Between Operation. Can be used to test that one value is between two others. $ref: "#/definitions/binaryOrTernaryOp" "<=": - title: Less-Than-Or-Equal-To/Between Operation. Can be used to test that one + title: + Less-Than-Or-Equal-To/Between Operation. Can be used to test that one value is between two others. $ref: "#/definitions/binaryOrTernaryOp" binaryOp: @@ -138,7 +141,7 @@ definitions: properties: "if": title: "If Operator" - description: "The if statement takes 1 or more arguments: a condition (\"if\"), what to do if its true (\"then\", optional, defaults to returning true), and what to do if its false (\"else\", optional, defaults to returning false). Note that the else condition can be used as an else-if statement by adding additional arguments." + description: 'The if statement takes 1 or more arguments: a condition ("if"), what to do if its true ("then", optional, defaults to returning true), and what to do if its false ("else", optional, defaults to returning false). Note that the else condition can be used as an else-if statement by adding additional arguments.' $ref: "#/definitions/variadicOp" "==": title: Lose Equality Operation @@ -164,7 +167,8 @@ definitions: $ref: "#/definitions/binaryOp" "%": title: Modulo Operation - description: Finds the remainder after the first argument is divided by the + description: + Finds the remainder after the first argument is divided by the second argument. $ref: "#/definitions/binaryOp" "/": @@ -172,37 +176,43 @@ definitions: $ref: "#/definitions/binaryOp" map: title: Map Operation - description: Perform an action on every member of an array. Note, that inside + description: + Perform an action on every member of an array. Note, that inside the logic being used to map, var operations are relative to the array element being worked on. $ref: "#/definitions/binaryOp" filter: title: Filter Operation - description: Keep only elements of the array that pass a test. Note, that + description: + Keep only elements of the array that pass a test. Note, that inside the logic being used to filter, var operations are relative to the array element being worked on. $ref: "#/definitions/binaryOp" all: title: All Operation - description: Perform a test on each member of that array, returning true if + description: + Perform a test on each member of that array, returning true if all pass. Inside the test code, var operations are relative to the array element being tested. $ref: "#/definitions/binaryOp" none: title: None Operation - description: Perform a test on each member of that array, returning true if + description: + Perform a test on each member of that array, returning true if none pass. Inside the test code, var operations are relative to the array element being tested. $ref: "#/definitions/binaryOp" some: title: Some Operation - description: Perform a test on each member of that array, returning true if + description: + Perform a test on each member of that array, returning true if some pass. Inside the test code, var operations are relative to the array element being tested. $ref: "#/definitions/binaryOp" in: title: In Operation - description: If the second argument is an array, tests that the first argument + description: + If the second argument is an array, tests that the first argument is a member of the array. $ref: "#/definitions/binaryOp" reduceRule: @@ -211,7 +221,8 @@ definitions: properties: reduce: title: Reduce Operation - description: Combine all the elements in an array into a single value, like + description: + Combine all the elements in an array into a single value, like adding up a list of numbers. Note, that inside the logic being used to reduce, var operations only have access to an object with a "current" and a "accumulator". type: array @@ -232,17 +243,18 @@ definitions: properties: "*": title: Multiplication Operation - description: Multiplication; associative, will accept and unlimited amount + description: + Multiplication; associative, will accept and unlimited amount of arguments. $ref: "#/definitions/associativeOp" unaryOp: anyOf: - - type: array - minItems: 1 - maxItems: 1 - items: - "$ref": "#/definitions/args" - - "$ref": "#/definitions/args" + - type: array + minItems: 1 + maxItems: 1 + items: + "$ref": "#/definitions/args" + - "$ref": "#/definitions/args" unaryRule: title: Unary Operation description: Any primitive JSONLogic operation with 1 operands. @@ -269,12 +281,14 @@ definitions: properties: or: title: Or Operation - description: Simple boolean test, with 1 or more arguments. At a more sophisticated + description: + Simple boolean test, with 1 or more arguments. At a more sophisticated level, "or" returns the first truthy argument, or the last argument. $ref: "#/definitions/variadicOp" and: - title: '' - description: Simple boolean test, with 1 or more arguments. At a more sophisticated + title: "" + description: + Simple boolean test, with 1 or more arguments. At a more sophisticated level, "and" returns the first falsy argument, or the last argument. $ref: "#/definitions/variadicOp" "+": @@ -294,18 +308,20 @@ definitions: $ref: "#/definitions/variadicOp" merge: title: Merge Operation - description: Takes one or more arrays, and merges them into one array. If + description: + Takes one or more arrays, and merges them into one array. If arguments aren't arrays, they get cast to arrays. $ref: "#/definitions/variadicOp" cat: title: Concatenate Operation - description: Concatenate all the supplied arguments. Note that this is not + description: + Concatenate all the supplied arguments. Note that this is not a join or implode operation, there is no “glue” string. $ref: "#/definitions/variadicOp" stringCompareArg: oneOf: - - type: string - - $ref: "#/definitions/anyRule" + - type: string + - $ref: "#/definitions/anyRule" stringCompareArgs: type: array minItems: 2 @@ -326,7 +342,8 @@ definitions: $ref: "#/definitions/stringCompareArgs" semVerString: title: Semantic Version String - description: A string representing a valid semantic version expression as per + description: + A string representing a valid semantic version expression as per https://semver.org/. type: string pattern: "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$" @@ -336,55 +353,60 @@ definitions: properties: sem_ver: title: Semantic Version Operation - description: 'Attribute matches a semantic version condition. Accepts "npm-style" + description: + 'Attribute matches a semantic version condition. Accepts "npm-style" range specifiers: "=", "!=", ">", "<", ">=", "<=", "~" (match minor version), "^" (match major version).' type: array minItems: 3 maxItems: 3 items: - - oneOf: - - $ref: "#/definitions/semVerString" - - $ref: "#/definitions/varRule" - - description: 'Range specifiers: "=", "!=", ">", "<", ">=", "<=", "~" (match - minor version), "^" (match major version).' - enum: - - "=" - - "!=" - - ">" - - "<" - - ">=" - - "<=" - - "~" - - "^" - - oneOf: - - $ref: "#/definitions/semVerString" - - $ref: "#/definitions/varRule" + - oneOf: + - $ref: "#/definitions/semVerString" + - $ref: "#/definitions/varRule" + - description: + 'Range specifiers: "=", "!=", ">", "<", ">=", "<=", "~" (match + minor version), "^" (match major version).' + enum: + - "=" + - "!=" + - ">" + - "<" + - ">=" + - "<=" + - "~" + - "^" + - oneOf: + - $ref: "#/definitions/semVerString" + - $ref: "#/definitions/varRule" fractionalWeightArg: $comment: if we remove the "sum to 100" restriction, update the descriptions below! - description: Distribution for all possible variants, with their associated weighting + description: + Distribution for all possible variants, with their associated weighting out of 100. type: array minItems: 1 maxItems: 2 items: - - description: If this bucket is randomly selected, this string is used to as - a key to retrieve the associated value from the "variants" object. - type: string - - description: Weighted distribution for this variant key (must sum to 100). - type: number + - description: + If this bucket is randomly selected, this string is used to as + a key to retrieve the associated value from the "variants" object. + type: string + - description: Weighted distribution for this variant key (must sum to 100). + type: number fractionalOp: type: array minItems: 3 $comment: there seems to be a bug here, where ajv gives a warning (not an error) because maxItems doesn't equal the number of entries in items, though this is valid in this case items: - - description: Bucketing value used in pseudorandom assignment; should be unique - and stable for each subject of flag evaluation. Defaults to a concatenation - of the flagKey and targetingKey. - $ref: "#/definitions/anyRule" - - $ref: "#/definitions/fractionalWeightArg" - - $ref: "#/definitions/fractionalWeightArg" + - description: + Bucketing value used in pseudorandom assignment; should be unique + and stable for each subject of flag evaluation. Defaults to a concatenation + of the flagKey and targetingKey. + $ref: "#/definitions/anyRule" + - $ref: "#/definitions/fractionalWeightArg" + - $ref: "#/definitions/fractionalWeightArg" additionalItems: $ref: "#/definitions/fractionalWeightArg" fractionalShorthandOp: @@ -400,8 +422,8 @@ definitions: title: Fractional Operation description: Deterministic, pseudorandom fractional distribution. oneOf: - - $ref: "#/definitions/fractionalOp" - - $ref: "#/definitions/fractionalShorthandOp" + - $ref: "#/definitions/fractionalOp" + - $ref: "#/definitions/fractionalShorthandOp" reference: additionalProperties: false type: object @@ -413,20 +435,20 @@ definitions: type: string args: oneOf: - - $ref: "#/definitions/reference" - - $ref: "#/definitions/anyRule" - - $ref: "#/definitions/primitive" + - $ref: "#/definitions/reference" + - $ref: "#/definitions/anyRule" + - $ref: "#/definitions/primitive" anyRule: anyOf: - - $ref: "#/definitions/varRule" - - $ref: "#/definitions/missingRule" - - $ref: "#/definitions/missingSomeRule" - - $ref: "#/definitions/binaryRule" - - $ref: "#/definitions/binaryOrTernaryRule" - - $ref: "#/definitions/associativeRule" - - $ref: "#/definitions/unaryRule" - - $ref: "#/definitions/variadicRule" - - $ref: "#/definitions/reduceRule" - - $ref: "#/definitions/stringCompareRule" - - $ref: "#/definitions/ruleSemVer" - - $ref: "#/definitions/fractionalRule" + - $ref: "#/definitions/varRule" + - $ref: "#/definitions/missingRule" + - $ref: "#/definitions/missingSomeRule" + - $ref: "#/definitions/binaryRule" + - $ref: "#/definitions/binaryOrTernaryRule" + - $ref: "#/definitions/associativeRule" + - $ref: "#/definitions/unaryRule" + - $ref: "#/definitions/variadicRule" + - $ref: "#/definitions/reduceRule" + - $ref: "#/definitions/stringCompareRule" + - $ref: "#/definitions/ruleSemVer" + - $ref: "#/definitions/fractionalRule" diff --git a/json/test/flags/negative/empty-variants.json b/json/test/flags/negative/empty-variants.json index a0ed458..2b312de 100644 --- a/json/test/flags/negative/empty-variants.json +++ b/json/test/flags/negative/empty-variants.json @@ -1,5 +1,5 @@ { - "$schema": "../../flags.json", + "$schema": "../../../flags.json", "flags": { "myBoolFlag": { "state": "ENABLED", diff --git a/json/test/flags/negative/malformed-flag.json b/json/test/flags/negative/malformed-flag.json index 2dfe73c..df52d24 100644 --- a/json/test/flags/negative/malformed-flag.json +++ b/json/test/flags/negative/malformed-flag.json @@ -1,5 +1,5 @@ { - "$schema": "../../flags.json", + "$schema": "../../../flags.json", "flags": { "myBoolFlag": { "state": "ENABLED", diff --git a/json/test/flags/negative/missing-variants.json b/json/test/flags/negative/missing-variants.json index 6d4b803..b88ad6f 100644 --- a/json/test/flags/negative/missing-variants.json +++ b/json/test/flags/negative/missing-variants.json @@ -1,6 +1,5 @@ { - "$schema": "../../flags.json", - + "$schema": "../../../flags.json", "flags": { "myBoolFlag": { "state": "ENABLED", diff --git a/json/test/flags/negative/mixed-variant-types.ffconfig.json b/json/test/flags/negative/mixed-variant-types.ffconfig.json index 4becc76..ea26663 100644 --- a/json/test/flags/negative/mixed-variant-types.ffconfig.json +++ b/json/test/flags/negative/mixed-variant-types.ffconfig.json @@ -1,5 +1,5 @@ { - "$schema": "../../flags.json", + "$schema": "../../../flags.json", "flags": { "myBoolFlag": { "state": "ENABLED", diff --git a/json/test/flags/negative/no-default-variant.json b/json/test/flags/negative/no-default-variant.json index bd57238..58c1335 100644 --- a/json/test/flags/negative/no-default-variant.json +++ b/json/test/flags/negative/no-default-variant.json @@ -1,5 +1,5 @@ { - "$schema": "../../flags.json", + "$schema": "../../../flags.json", "flags": { "myBoolFlag": { "state": "ENABLED", diff --git a/json/test/flags/negative/state-set-incorrectly.json b/json/test/flags/negative/state-set-incorrectly.json index 08e7e39..021918e 100644 --- a/json/test/flags/negative/state-set-incorrectly.json +++ b/json/test/flags/negative/state-set-incorrectly.json @@ -1,5 +1,5 @@ { - "$schema": "../../flags.json", + "$schema": "../../../flags.json", "flags": { "myBoolFlag": { "state": "WILL-FAIL", diff --git a/json/test/flags/negative/with-valid-targeting.json b/json/test/flags/negative/with-valid-targeting.json new file mode 100644 index 0000000..ba78ce0 --- /dev/null +++ b/json/test/flags/negative/with-valid-targeting.json @@ -0,0 +1,16 @@ +{ + "$schema": "../../../flags.json", + "flags": { + "targetedFlag": { + "state": "ENABLED", + "variants": { + "on": true, + "off": false + }, + "defaultVariant": "on", + "targeting": { + "not-a-real-rule": [1, 2] + } + } + } +} diff --git a/json/test/flags/positive/example-simple.flagd.json b/json/test/flags/positive/example-simple.flagd.json index c2c7ddf..9d2dd60 100644 --- a/json/test/flags/positive/example-simple.flagd.json +++ b/json/test/flags/positive/example-simple.flagd.json @@ -1,4 +1,5 @@ { + "$schema": "../../../flags.json", "flags": { "myBoolFlag": { "state": "ENABLED", diff --git a/json/test/flags/positive/example.flagd.json b/json/test/flags/positive/example.flagd.json index afe580a..8f66a70 100644 --- a/json/test/flags/positive/example.flagd.json +++ b/json/test/flags/positive/example.flagd.json @@ -1,5 +1,5 @@ { - "$schema": "../../flags.json", + "$schema": "../../../flags.json", "flags": { "myBoolFlag": { "state": "ENABLED", diff --git a/json/test/flags/positive/with-valid-targeting.json b/json/test/flags/positive/with-valid-targeting.json new file mode 100644 index 0000000..1a33e4e --- /dev/null +++ b/json/test/flags/positive/with-valid-targeting.json @@ -0,0 +1,26 @@ +{ + "$schema": "../../../flags.json", + "flags": { + "targetedFlag": { + "state": "ENABLED", + "variants": { + "on": true, + "off": false + }, + "defaultVariant": "on", + "targeting": { + "if": [ + { + "ends_with": [ + { + "var": "email" + }, + "@company.com" + ] + }, + "on" + ] + } + } + } +} diff --git a/json/test/targeting/negative/fractional-invalid-bucketing.json b/json/test/targeting/negative/fractional-invalid-bucketing.json index d36b3e2..9ed172f 100644 --- a/json/test/targeting/negative/fractional-invalid-bucketing.json +++ b/json/test/targeting/negative/fractional-invalid-bucketing.json @@ -1,13 +1,9 @@ { - "$schema": "../../../targeting.json", - "$comments": "tests that an invalid bucking value is invalid", - "targeting": { - "fractional": [ - "invalid", - ["clubs", 25], - ["diamonds", 25], - ["hearts", 25], - ["spades", 25] - ] - } -} + "fractional": [ + "invalid", + ["clubs", 25], + ["diamonds", 25], + ["hearts", 25], + ["spades", 25] + ] +} \ No newline at end of file diff --git a/json/test/targeting/negative/fractional-invalid-weighting.json b/json/test/targeting/negative/fractional-invalid-weighting.json index f121128..bdcd10e 100644 --- a/json/test/targeting/negative/fractional-invalid-weighting.json +++ b/json/test/targeting/negative/fractional-invalid-weighting.json @@ -1,12 +1,8 @@ { - "$schema": "../../../targeting.json", - "$comments": "tests that an invalid weight value is invalid", - "targeting": { - "fractional": [ - ["clubs", 25], - ["diamonds", "25"], - ["hearts", 25], - ["spades", 25] - ] - } -} + "fractional": [ + ["clubs", 25], + ["diamonds", "25"], + ["hearts", 25], + ["spades", 25] + ] +} \ No newline at end of file diff --git a/json/test/targeting/negative/invalid-ends-with-param.json b/json/test/targeting/negative/invalid-ends-with-param.json index 40b3c25..2d1e457 100644 --- a/json/test/targeting/negative/invalid-ends-with-param.json +++ b/json/test/targeting/negative/invalid-ends-with-param.json @@ -1,13 +1,9 @@ { - "$schema": "../../../targeting.json", - "$comments": "tests that an an int is not a valid ends_with param", - "targeting": { - "if": [ - { - "ends_with": [{ "var": "id" }, 0] - }, - "postfix", - "prefix" - ] - } -} + "if": [ + { + "ends_with": [{ "var": "id" }, 0] + }, + "postfix", + "prefix" + ] +} \ No newline at end of file diff --git a/json/test/targeting/negative/invalid-flagd-props.json b/json/test/targeting/negative/invalid-flagd-props.json index 3066f20..c89f529 100644 --- a/json/test/targeting/negative/invalid-flagd-props.json +++ b/json/test/targeting/negative/invalid-flagd-props.json @@ -1,13 +1,9 @@ { - "$schema": "../../../targeting.json", - "$comments": "tests that an unsupported $flagd property is invalid", - "targeting": { - "if": [ - { - "==": [{ "var": "$flagd.invalidProp" }, { "var": "someprop" }] - }, - "yes", - "no" - ] - } -} + "if": [ + { + "==": [{ "var": "$flagd.invalidProp" }, { "var": "someprop" }] + }, + "yes", + "no" + ] +} \ No newline at end of file diff --git a/json/test/targeting/negative/invalid-starts-with-param.json b/json/test/targeting/negative/invalid-starts-with-param.json index f72f28b..805aa14 100644 --- a/json/test/targeting/negative/invalid-starts-with-param.json +++ b/json/test/targeting/negative/invalid-starts-with-param.json @@ -1,13 +1,9 @@ { - "$schema": "../../../targeting.json", - "$comments": "tests that an an int is not a valid starts_with param", - "targeting": { - "if": [ - { - "starts_with": [{ "var": "id" }, 0] - }, - "prefix", - "postfix" - ] - } -} + "if": [ + { + "starts_with": [{ "var": "id" }, 0] + }, + "prefix", + "postfix" + ] +} \ No newline at end of file diff --git a/json/test/targeting/negative/sem-ver-invalid-range-specifier.json b/json/test/targeting/negative/sem-ver-invalid-range-specifier.json index e17ee93..32998f5 100644 --- a/json/test/targeting/negative/sem-ver-invalid-range-specifier.json +++ b/json/test/targeting/negative/sem-ver-invalid-range-specifier.json @@ -1,13 +1,9 @@ { - "$schema": "../../../targeting.json", - "$comments": "tests that an invalid range specifier is invalid", - "targeting": { - "if": [ - { - "sem_ver": [{ "var": "version" }, "*", "2.0.0"] - }, - "equal", - "not" - ] - } -} + "if": [ + { + "sem_ver": [{ "var": "version" }, "*", "2.0.0"] + }, + "equal", + "not" + ] +} \ No newline at end of file diff --git a/json/test/targeting/negative/sem-ver-invalid-ver-expression.json b/json/test/targeting/negative/sem-ver-invalid-ver-expression.json index 4110bc0..7af1374 100644 --- a/json/test/targeting/negative/sem-ver-invalid-ver-expression.json +++ b/json/test/targeting/negative/sem-ver-invalid-ver-expression.json @@ -1,13 +1,9 @@ { - "$schema": "../../../targeting.json", - "$comments": "tests that an invalid version is invalid", - "targeting": { - "if": [ - { - "sem_ver": [{ "var": "version" }, "=", "2.0.0.0"] - }, - "equal", - "not" - ] - } -} + "if": [ + { + "sem_ver": [{ "var": "version" }, "=", "2.0.0.0"] + }, + "equal", + "not" + ] +} \ No newline at end of file diff --git a/json/test/targeting/positive/basic-json-ops.json b/json/test/targeting/positive/basic-json-ops.json index 9f69c0e..dcbd358 100644 --- a/json/test/targeting/positive/basic-json-ops.json +++ b/json/test/targeting/positive/basic-json-ops.json @@ -1,64 +1,61 @@ { - "$schema": "../../../targeting.json", - "targeting": { - "*" : [ - {"if" : [false, "false", false, "false", true, "true"] }, - {"if" : [ true, "yes", "no" ]}, - {"if" : [ true, "yes" ]}, - {"if" : [ true ]}, - {"==" : [1, 1]}, - {"===" : [1, 1]}, - {"!=" : [1, 2]}, - {"!==" : [1, 2]}, - {"!": [true]}, - {"!": true}, - {"!!": ["0"] }, - {"or": [true, false]}, - {"or":[false, 0, "a"]}, - {"and": [true, true]}, - {"and":[true, "a", 3]}, - {">" : [2, 1]}, - {">=" : [1, 1]}, - {"<" : [1, 2]}, - {"<=" : [1, 1]}, - {"<" : [1, 2, 3]}, - {"<" : [1, 4, 3]}, - {"<=" : [1, 2, 3]}, - {"<=" : [1, 1, 3]}, - {"max":[1,2,3]}, - {"min":[1,2,3]}, - {"+":[4,2]}, - {"+":[2,2,2,2,2]}, - {"+" : [ "3.14" ]}, - {"/":[4,2]}, - {"*":[2,2,2,2,2]}, - {"-": [ 2 ]}, - {"-":[4, 2]}, - {"%": [101,2]}, - {"map":[ - {"var":"integers"}, - {"*":[{"var":""},2]} - ]}, - {"filter":[ - {"var":"integers"}, - {"%":[{"var":""},2]} - ]}, - {"reduce":[ - {"var":"integers"}, - {"+":[{"var":"current"}, {"var":"accumulator"}]}, - 0 - ]}, - {"all" : [ [1,2,3], {">":[{"var":""}, 0]} ]}, - {"some" : [ [-1,0,1], {">":[{"var":""}, 0]} ]}, - {"none" : [ [-3,-2,-1], {">":[{"var":""}, 0]} ]}, - {"some" : [ {"var":"pies"}, {"==":[{"var":"filling"}, "apple"]} ]}, - {"merge":[ [1,2], [3,4] ]}, - {"merge":[ 1, 2, [3,4] ]}, - {"in":[ "Ringo", ["John", "Paul", "George", "Ringo"] ]}, - {"in":["Spring", "Springfield"]}, - {"cat": ["I love", " pie"]}, - {"substr": ["jsonlogic", 4]}, - {"substr": ["jsonlogic", 1, 3]} - ] - } + "*" : [ + {"if" : [false, "false", false, "false", true, "true"] }, + {"if" : [ true, "yes", "no" ]}, + {"if" : [ true, "yes" ]}, + {"if" : [ true ]}, + {"==" : [1, 1]}, + {"===" : [1, 1]}, + {"!=" : [1, 2]}, + {"!==" : [1, 2]}, + {"!": [true]}, + {"!": true}, + {"!!": ["0"] }, + {"or": [true, false]}, + {"or":[false, 0, "a"]}, + {"and": [true, true]}, + {"and":[true, "a", 3]}, + {">" : [2, 1]}, + {">=" : [1, 1]}, + {"<" : [1, 2]}, + {"<=" : [1, 1]}, + {"<" : [1, 2, 3]}, + {"<" : [1, 4, 3]}, + {"<=" : [1, 2, 3]}, + {"<=" : [1, 1, 3]}, + {"max":[1,2,3]}, + {"min":[1,2,3]}, + {"+":[4,2]}, + {"+":[2,2,2,2,2]}, + {"+" : [ "3.14" ]}, + {"/":[4,2]}, + {"*":[2,2,2,2,2]}, + {"-": [ 2 ]}, + {"-":[4, 2]}, + {"%": [101,2]}, + {"map":[ + {"var":"integers"}, + {"*":[{"var":""},2]} + ]}, + {"filter":[ + {"var":"integers"}, + {"%":[{"var":""},2]} + ]}, + {"reduce":[ + {"var":"integers"}, + {"+":[{"var":"current"}, {"var":"accumulator"}]}, + 0 + ]}, + {"all" : [ [1,2,3], {">":[{"var":""}, 0]} ]}, + {"some" : [ [-1,0,1], {">":[{"var":""}, 0]} ]}, + {"none" : [ [-3,-2,-1], {">":[{"var":""}, 0]} ]}, + {"some" : [ {"var":"pies"}, {"==":[{"var":"filling"}, "apple"]} ]}, + {"merge":[ [1,2], [3,4] ]}, + {"merge":[ 1, 2, [3,4] ]}, + {"in":[ "Ringo", ["John", "Paul", "George", "Ringo"] ]}, + {"in":["Spring", "Springfield"]}, + {"cat": ["I love", " pie"]}, + {"substr": ["jsonlogic", 4]}, + {"substr": ["jsonlogic", 1, 3]} + ] } diff --git a/json/test/targeting/positive/custom-ops.json b/json/test/targeting/positive/custom-ops.json index e313bab..99c7ecd 100644 --- a/json/test/targeting/positive/custom-ops.json +++ b/json/test/targeting/positive/custom-ops.json @@ -1,118 +1,114 @@ { - "$schema": "../../../targeting.json", - "$comments": "tests that all the custom ops work", - "targeting": { - "*": [ - { - "fractional": [ - { "cat": [ - { "var": "$flagd.flagKey" }, - { "var": "user.name" } - ]}, - ["clubs", 25], - ["diamonds", 25], - ["hearts", 25], - ["spades", 25] - ] - }, - { - "fractional": [ - [ "heads" ], - [ "tails", 1 ] - ] - }, - { - "fractional": [ - ["clubs", 25], - ["diamonds", 25], - ["hearts", 25], - ["spades", 25] - ] - }, - { - "fractional": [ - ["clubs", 25], - ["diamonds", 25], - ["hearts", 25], - ["spades", 25] - ] - }, - { - "if": [ - { - "starts_with": [{ "var": "id" }, "abc"] - }, - "prefix", - { - "if": [ - { - "ends_with": [{ "var": "id" }, "xyz"] - }, - "postfix", - null - ] - } - ] - }, - { - "if": [ - { - "sem_ver": [{ "var": "version" }, "=", "2.0.0"] - }, - "equal", - { - "if": [ - { - "sem_ver": [{ "var": "version" }, ">", "2.0.0"] - }, - "greater", - { - "if": [ - { - "sem_ver": [{ "var": "version" }, "<", "2.0.0"] - }, - "lesser", - null - ] - } - ] - } - ] - }, - { - "if": [ - { - "sem_ver": [{ "var": "version" }, "~", "3.0.0"] - }, - "minor", - { - "if": [ - { - "sem_ver": [{ "var": "version" }, "^", "3.0.0"] - }, - "major", - "none" - ] - } - ] - }, - { - "if": [ - { - ">": [{ "var": "$flagd.timestamp" }, { "var": "time" }] - }, - "past", - { - "if": [ - { - "<": [{ "var": "$flagd.timestamp" }, { "var": "time" }] - }, - "future", - "none" - ] - } - ] - } - ] - } + "*": [ + { + "fractional": [ + { "cat": [ + { "var": "$flagd.flagKey" }, + { "var": "user.name" } + ]}, + ["clubs", 25], + ["diamonds", 25], + ["hearts", 25], + ["spades", 25] + ] + }, + { + "fractional": [ + [ "heads" ], + [ "tails", 1 ] + ] + }, + { + "fractional": [ + ["clubs", 25], + ["diamonds", 25], + ["hearts", 25], + ["spades", 25] + ] + }, + { + "fractional": [ + ["clubs", 25], + ["diamonds", 25], + ["hearts", 25], + ["spades", 25] + ] + }, + { + "if": [ + { + "starts_with": [{ "var": "id" }, "abc"] + }, + "prefix", + { + "if": [ + { + "ends_with": [{ "var": "id" }, "xyz"] + }, + "postfix", + null + ] + } + ] + }, + { + "if": [ + { + "sem_ver": [{ "var": "version" }, "=", "2.0.0"] + }, + "equal", + { + "if": [ + { + "sem_ver": [{ "var": "version" }, ">", "2.0.0"] + }, + "greater", + { + "if": [ + { + "sem_ver": [{ "var": "version" }, "<", "2.0.0"] + }, + "lesser", + null + ] + } + ] + } + ] + }, + { + "if": [ + { + "sem_ver": [{ "var": "version" }, "~", "3.0.0"] + }, + "minor", + { + "if": [ + { + "sem_ver": [{ "var": "version" }, "^", "3.0.0"] + }, + "major", + "none" + ] + } + ] + }, + { + "if": [ + { + ">": [{ "var": "$flagd.timestamp" }, { "var": "time" }] + }, + "past", + { + "if": [ + { + "<": [{ "var": "$flagd.timestamp" }, { "var": "time" }] + }, + "future", + "none" + ] + } + ] + } + ] } \ No newline at end of file diff --git a/json/test/targeting/positive/if-shorthand.json b/json/test/targeting/positive/if-shorthand.json index eb2b056..8fc1476 100644 --- a/json/test/targeting/positive/if-shorthand.json +++ b/json/test/targeting/positive/if-shorthand.json @@ -1,39 +1,35 @@ { - "$schema": "../../../targeting.json", - "$comments": "tests that all the variants of 'if' work (bugfix)", - "targeting": { - "*": [ - { - "if": [ - { - "===": [ - { - "var": "env" - }, - "production" - ] - } - ] - }, - { - "if": [ - { - "===": [ - { - "var": "env" - }, - "production" - ] - }, "true" - ] - }, - { - "if": [ - { - "$ref": "some-ref" - } - ] - } - ] - } + "*": [ + { + "if": [ + { + "===": [ + { + "var": "env" + }, + "production" + ] + } + ] + }, + { + "if": [ + { + "===": [ + { + "var": "env" + }, + "production" + ] + }, "true" + ] + }, + { + "if": [ + { + "$ref": "some-ref" + } + ] + } + ] } \ No newline at end of file