diff --git a/docs/schema/flagd-definitions.json b/docs/schema/flagd-definitions.json index 55ae88c7a..ab2e05a86 100644 --- a/docs/schema/flagd-definitions.json +++ b/docs/schema/flagd-definitions.json @@ -1,4 +1,5 @@ { + "$id": "flagd.dev/schema/flagd-definitions.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", @@ -12,8 +13,6 @@ "additionalProperties": false, "patternProperties": { "^.{1,}$": { - "$comment": "'unevaluatedProperties': 'false' prevents additional props on a flag (ie: targetting)", - "unevaluatedProperties": false, "oneOf": [ { "title": "Boolean flag", @@ -61,7 +60,10 @@ "title": "Flag State", "description": "Indicates whether the flag is functional. Disabled flags are treated as if they don't exist.", "type": "string", - "enum": ["ENABLED", "DISABLED"] + "enum": [ + "ENABLED", + "DISABLED" + ] }, "defaultVariant": { "title": "Default Variant", @@ -72,7 +74,10 @@ "$ref": "./targeting.json#/$defs/targeting" } }, - "required": ["state", "defaultVariant"] + "required": [ + "state", + "defaultVariant" + ] }, "booleanVariants": { "type": "object", diff --git a/docs/schema/targeting.json b/docs/schema/targeting.json index 2eb317803..8341513fd 100644 --- a/docs/schema/targeting.json +++ b/docs/schema/targeting.json @@ -1,4 +1,5 @@ { + "$id": "flagd.dev/schema/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.", @@ -7,7 +8,17 @@ "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.", - "$ref": "#/$defs/anyRule" + "anyOf": [ + { + "$comment": "we need this to support empty targeting", + "type": "object", + "additionalProperties": false, + "properties": {} + }, + { + "$ref": "#/$defs/anyRule" + } + ] }, "primitive": { "oneOf": [ @@ -48,7 +59,29 @@ }, { "type": "array", - "items": [{ "type": "string" }, { "type": {} }] + "$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" + } + ] + } } ] } @@ -62,7 +95,9 @@ "properties": { "missing": { "type": "array", - "items": { "type": "string" } + "items": { + "type": "string" + } } } }, @@ -73,12 +108,18 @@ "additionalProperties": false, "properties": { "missing_some": { + "minItems": 2, + "maxItems": 2, "type": "array", "items": [ - { "type": "number" }, + { + "type": "number" + }, { "type": "array", - "items": { "type": "string" } + "items": { + "type": "string" + } } ] } @@ -87,14 +128,13 @@ "ifRule": { "type": "object", "additionalProperties": false, - "minItems": 3, - "maxItems": 3, "properties": { "if": { "title": "If Operator", - "description": "The if statement takes 3 arguments: a condition (if), what to do if it’s true (then), and what to do if it’s false (else). Note that the form accepting more than 3 arguments (if/else) is not supported in flagd; use nesting instead.", - + "description": "The if statement takes 3 arguments: a condition (if), what to do if its true (then), and what to do if its false (else). Note that the form accepting more than 3 arguments (if/else) is not supported in flagd; use nesting instead.", "type": "array", + "minItems": 3, + "maxItems": 3, "items": { "$ref": "#/$defs/args" } @@ -259,6 +299,7 @@ } }, "variadicRule": { + "$comment": "note < and <= can be used with up to 3 ops (between)", "type": "object", "additionalProperties": false, "properties": { @@ -272,7 +313,6 @@ "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": "#/$defs/variadicOp" }, - "$comment": "< and <= can be used with up to 3 ops (between)", "<": { "title": "Less-Than/Between Operation. Can be used to test that one value is between two others.", "description": "", @@ -347,6 +387,7 @@ "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": [ @@ -360,7 +401,16 @@ }, { "description": "Range specifiers: \"=\", \"!=\", \">\", \"<\", \">=\", \"<=\", \"~\" (match minor version), \"^\" (match major version).", - "enum": ["=", "!=", ">", "<", ">=", "<=", "~", "^"] + "enum": [ + "=", + "!=", + ">", + "<", + ">=", + "<=", + "~", + "^" + ] }, { "oneOf": [ @@ -386,20 +436,27 @@ { "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" } - ], - "additionalItems": { - "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": "#/$defs/varRule" + }, + { + "$ref": "#/$defs/fractionalWeightArg" + }, + { + "$ref": "#/$defs/fractionalWeightArg" } ], "additionalItems": {