Skip to content

Commit

Permalink
feat: support chainable if conditions (#138)
Browse files Browse the repository at this point in the history
## This PR

- adds support for chainable if conditions

### Notes

Verified that all the JsonLogic implementations used by flagd support
chainable if conditions.

---------

Signed-off-by: Michael Beemer <[email protected]>
  • Loading branch information
beeme1mr authored Apr 8, 2024
1 parent ea4f119 commit cc7832a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
24 changes: 5 additions & 19 deletions json/targeting.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,6 @@
}
}
},
"ifRule": {
"type": "object",
"additionalProperties": false,
"properties": {
"if": {
"title": "If Operator",
"description": "The if statement takes 1-3 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 form accepting more than 3 arguments (else-if) is not supported in flagd; use nesting instead.",
"type": "array",
"minItems": 1,
"maxItems": 3,
"items": {
"$ref": "#/$defs/args"
}
}
}
},
"binaryOrTernaryOp": {
"type": "array",
"minItems": 2,
Expand Down Expand Up @@ -190,6 +174,11 @@
"type": "object",
"additionalProperties": false,
"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.",
"$ref": "#/$defs/variadicOp"
},
"==": {
"title": "Lose Equality Operation",
"description": "Tests equality, with type coercion. Requires two arguments.",
Expand Down Expand Up @@ -560,9 +549,6 @@
{
"$ref": "#/$defs/missingSomeRule"
},
{
"$ref": "#/$defs/ifRule"
},
{
"$ref": "#/$defs/binaryRule"
},
Expand Down
21 changes: 4 additions & 17 deletions json/targeting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,6 @@ type: object
- type: array
items:
type: string
ifRule:
type: object
additionalProperties: false
properties:
if:
title: If Operator
description: 'The if statement takes 1-3 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 form accepting more than 3 arguments (else-if) is not supported in flagd;
use nesting instead.'
type: array
minItems: 1
maxItems: 3
items:
$ref: "#/$defs/args"
binaryOrTernaryOp:
type: array
minItems: 2
Expand Down Expand Up @@ -149,6 +133,10 @@ type: object
type: object
additionalProperties: false
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."
$ref: "#/$defs/variadicOp"
"==":
title: Lose Equality Operation
description: Tests equality, with type coercion. Requires two arguments.
Expand Down Expand Up @@ -428,7 +416,6 @@ type: object
- $ref: "#/$defs/varRule"
- $ref: "#/$defs/missingRule"
- $ref: "#/$defs/missingSomeRule"
- $ref: "#/$defs/ifRule"
- $ref: "#/$defs/binaryRule"
- $ref: "#/$defs/binaryOrTernaryRule"
- $ref: "#/$defs/associativeRule"
Expand Down
1 change: 1 addition & 0 deletions json/test/positive/basic-json-ops.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"defaultVariant": "on",
"targeting": {
"*" : [
{"if" : [false, "false", false, "false", true, "true"] },
{"if" : [ true, "yes", "no" ]},
{"if" : [ true, "yes" ]},
{"if" : [ true ]},
Expand Down

0 comments on commit cc7832a

Please sign in to comment.