{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/flagd-flag-configuration/versions/0.2.0.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.2.0/json/flags.json",
    "sourceSha256": "291be88781cb601502b76c8f5d2966bbe962bdebdd2842a8087624c602cf207f",
    "fileMatch": [
      "flagd.json",
      "flagd.yaml",
      "flagd.yml",
      "*.flagd.json",
      "*.flagd.yaml",
      "*.flagd.yml"
    ],
    "parsers": [
      "json",
      "yaml"
    ]
  },
  "type": "object",
  "properties": {
    "flags": {
      "title": "Flags",
      "description": "Top-level flags object. All flags are defined here.",
      "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 having boolean values.",
              "$ref": "#/$defs/booleanFlag"
            },
            {
              "title": "String flag",
              "description": "A flag having string values.",
              "$ref": "#/$defs/stringFlag"
            },
            {
              "title": "Numeric flag",
              "description": "A flag having numeric values.",
              "$ref": "#/$defs/numberFlag"
            },
            {
              "title": "Object flag",
              "description": "A flag having arbitrary object values.",
              "$ref": "#/$defs/objectFlag"
            }
          ]
        }
      }
    },
    "$evaluators": {
      "title": "Evaluators",
      "description": "Reusable targeting rules that can be referenced with \"$ref\": \"myRule\" in multiple flags.",
      "type": "object",
      "additionalProperties": false,
      "patternProperties": {
        "^.{1,}$": {
          "$comment": "this relative ref means that targeting.json MUST be in the same dir, or available on the same HTTP path",
          "$ref": "https://catalog.lintel.tools/schemas/schemastore/flagd-flag-configuration/_shared/0.2.0--targeting.json#/$defs/targeting"
        }
      }
    }
  },
  "$comment": "merge the variants with the base flag to build our typed flags",
  "$defs": {
    "flag": {
      "$comment": "base flag object; no title/description here, allows for better UX, keep it in the overrides",
      "type": "object",
      "properties": {
        "state": {
          "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"
          ]
        },
        "defaultVariant": {
          "title": "Default Variant",
          "description": "The variant to serve if no dynamic targeting applies (including if the targeting returns null).",
          "type": "string"
        },
        "targeting": {
          "$ref": "https://catalog.lintel.tools/schemas/schemastore/flagd-flag-configuration/_shared/0.2.0--targeting.json#/$defs/targeting"
        }
      },
      "required": [
        "state",
        "defaultVariant"
      ]
    },
    "booleanVariants": {
      "type": "object",
      "properties": {
        "variants": {
          "type": "object",
          "default": {
            "true": true,
            "false": 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"
        }
      ]
    }
  }
}
