{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/flagd-flag-configuration/versions/0.1.1.json",
  "title": "flagd Flag Configuration",
  "description": "Defines flags for use in flagd, including typed variants and rules",
  "x-lintel": {
    "source": "https://raw.githubusercontent.com/open-feature/flagd-schemas/json/json-schema-v0.1.1/json/flagd-definitions.json",
    "sourceSha256": "9b3e94516ae530d0ba61d8c7097a515c4bb9f62478c5501839f5de924469f973",
    "fileMatch": [
      "flagd.json",
      "flagd.yaml",
      "flagd.yml",
      "*.flagd.json",
      "*.flagd.yaml",
      "*.flagd.yml"
    ],
    "parsers": [
      "json",
      "yaml"
    ]
  },
  "type": "object",
  "properties": {
    "flags": {
      "type": "object",
      "$comment": "flag objects are one of the 4 flag types defined in $defs",
      "additionalProperties": false,
      "patternProperties": {
        "^.{1,}$": {
          "oneOf": [
            {
              "title": "Boolean flag",
              "description": "A flag associated with boolean values",
              "$ref": "#/$defs/booleanFlag"
            },
            {
              "title": "String flag",
              "description": "A flag associated with string values",
              "$ref": "#/$defs/stringFlag"
            },
            {
              "title": "Numeric flag",
              "description": "A flag associated with numeric values",
              "$ref": "#/$defs/numberFlag"
            },
            {
              "title": "Object flag",
              "description": "A flag associated with arbitrary object values",
              "$ref": "#/$defs/objectFlag"
            }
          ]
        }
      }
    }
  },
  "$defs": {
    "flag": {
      "title": "Flag Base",
      "description": "Base object for all flags",
      "type": "object",
      "properties": {
        "state": {
          "description": "Indicates whether the flag is functional. Disabled flags are treated as if they don't exist",
          "type": "string",
          "enum": [
            "ENABLED",
            "DISABLED"
          ]
        },
        "defaultVariant": {
          "description": "The variant to serve if no dynamic targeting applies",
          "type": "string"
        },
        "targeting": {
          "type": "object",
          "description": "JsonLogic expressions to be used for dynamic evaluation. The \"context\" is passed as the data. Rules must resolve one of the defined variants, or the \"defaultVariant\" will be used."
        }
      },
      "required": [
        "state",
        "defaultVariant"
      ]
    },
    "booleanVariants": {
      "type": "object",
      "properties": {
        "variants": {
          "type": "object",
          "default": {
            "on": true,
            "off": false
          },
          "additionalProperties": false,
          "patternProperties": {
            "^.{1,}$": {
              "type": "boolean"
            }
          }
        }
      }
    },
    "stringVariants": {
      "type": "object",
      "properties": {
        "variants": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^.{1,}$": {
              "type": "string"
            }
          }
        }
      }
    },
    "numberVariants": {
      "type": "object",
      "properties": {
        "variants": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^.{1,}$": {
              "type": "number"
            }
          }
        }
      }
    },
    "objectVariants": {
      "type": "object",
      "properties": {
        "variants": {
          "type": "object",
          "additionalProperties": false,
          "patternProperties": {
            "^.{1,}$": {
              "type": "object"
            }
          }
        }
      }
    },
    "objectFlag": {
      "allOf": [
        {
          "$ref": "#/$defs/flag"
        },
        {
          "$ref": "#/$defs/objectVariants"
        }
      ]
    },
    "booleanFlag": {
      "allOf": [
        {
          "$ref": "#/$defs/flag"
        },
        {
          "$ref": "#/$defs/booleanVariants"
        }
      ]
    },
    "stringFlag": {
      "allOf": [
        {
          "$ref": "#/$defs/flag"
        },
        {
          "$ref": "#/$defs/stringVariants"
        }
      ]
    },
    "numberFlag": {
      "allOf": [
        {
          "$ref": "#/$defs/flag"
        },
        {
          "$ref": "#/$defs/numberVariants"
        }
      ]
    }
  },
  "$comment": "Merge the variants with the base flag to build our typed flags"
}
