Skip to content

Commit

Permalink
fixup: support {}
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
  • Loading branch information
toddbaert committed Jan 3, 2024
1 parent a42e098 commit d73dc30
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 20 deletions.
13 changes: 9 additions & 4 deletions docs/schema/flagd-definitions.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -72,7 +74,10 @@
"$ref": "./targeting.json#/$defs/targeting"
}
},
"required": ["state", "defaultVariant"]
"required": [
"state",
"defaultVariant"
]
},
"booleanVariants": {
"type": "object",
Expand Down
89 changes: 73 additions & 16 deletions docs/schema/targeting.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand All @@ -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": [
Expand Down Expand Up @@ -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"
}
]
}
}
]
}
Expand All @@ -62,7 +95,9 @@
"properties": {
"missing": {
"type": "array",
"items": { "type": "string" }
"items": {
"type": "string"
}
}
}
},
Expand All @@ -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"
}
}
]
}
Expand All @@ -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"
}
Expand Down Expand Up @@ -259,6 +299,7 @@
}
},
"variadicRule": {
"$comment": "note < and <= can be used with up to 3 ops (between)",
"type": "object",
"additionalProperties": false,
"properties": {
Expand All @@ -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": "",
Expand Down Expand Up @@ -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": [
Expand All @@ -360,7 +401,16 @@
},
{
"description": "Range specifiers: \"=\", \"!=\", \">\", \"<\", \">=\", \"<=\", \"~\" (match minor version), \"^\" (match major version).",
"enum": ["=", "!=", ">", "<", ">=", "<=", "~", "^"]
"enum": [
"=",
"!=",
">",
"<",
">=",
"<=",
"~",
"^"
]
},
{
"oneOf": [
Expand All @@ -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": {
Expand Down

0 comments on commit d73dc30

Please sign in to comment.