Skip to content

Commit

Permalink
fixup: validate top-level object in targeting.json
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 Jul 5, 2024
1 parent 2b9fb80 commit 41e3d71
Show file tree
Hide file tree
Showing 24 changed files with 487 additions and 471 deletions.
6 changes: 3 additions & 3 deletions json/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
}
}
}
Expand All @@ -71,7 +71,7 @@
"type": "string"
},
"targeting": {
"$ref": "./targeting.json#/definitions/targeting"
"$ref": "./targeting.json"
}
},
"required": [
Expand Down
6 changes: 3 additions & 3 deletions json/flags.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -56,7 +56,7 @@ definitions:
if the targeting returns null).
type: string
targeting:
$ref: "./targeting.json#/definitions/targeting"
$ref: "./targeting.json"
required:
- state
- defaultVariant
Expand Down
31 changes: 11 additions & 20 deletions json/targeting.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
Loading

0 comments on commit 41e3d71

Please sign in to comment.