{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.krakend.io/schema/v2.8/qos/ratelimit/tiered.json",
  "title": "Tiered Rate Limit",
  "description": "Enterprise only. Apply ratelimit based on tier match.",
  "type": "object",
  "required": [ "tier_key", "tiers" ],
  "properties": {
    "tier_key": {
      "title": "Tier key",
      "description": "The header name containing the tier name. The string you provide is case-insensitive. If you need to take the value from a place that is not a header (a token, an API key), you must use propagate functions in the components that convert values to internal headers.\n\nSee: https://www.krakend.io/docs/enterprise/docs/enterprise/service-settings/tiered-rate-limit/",
      "type": "string"
    },
    "tiers": {
      "title": "Tiers",
      "description": "The list of all tier definitions and limits for each. Each item in the list is a tier object.\n\nSee: https://www.krakend.io/docs/enterprise/docs/enterprise/service-settings/tiered-rate-limit/",
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "ratelimit": {
            "title": "Ratelimit",
            "description": "The rate limit definition. This is an object with the same attributes the [service rate limit](https://www.krakend.io/docs/enterprise/service-settings/service-rate-limit/) has.\n\nSee: https://www.krakend.io/docs/enterprise/docs/enterprise/service-settings/tiered-rate-limit/",
            "$ref": "router.json",
            "type": "object"
          },
          "ratelimit_redis": {
            "title": "Redis Ratelimit",
            "description": "The stateful rate limit definition. This is an object with the same attributes the [stateful service rate limit](https://www.krakend.io/docs/enterprise/throttling/global-rate-limit/) has.\n\nSee: https://www.krakend.io/docs/enterprise/docs/enterprise/service-settings/tiered-rate-limit/",
            "$ref": "redis.json",
            "type": "object"
          },
          "tier_value": {
            "title": "Tier value",
            "description": "The tier value. When you use `literal`, it is the tier name. When you use `policy`, it is the expression you want to evaluate to determine if the user matches this tier or not (see security policies for syntax).\n\nSee: https://www.krakend.io/docs/enterprise/docs/enterprise/service-settings/tiered-rate-limit/",
            "examples": [ "gold", "silver", "value.matches('User-[a-zA-Z]+')" ],
            "default": "",
            "type": "string"
          },
          "tier_value_as": {
            "title": "Tier value as",
            "description": "Determines how to parse the value found in the tier header. When `literal` is used, the exact value of the header is compared against the tier name. When `policy` is used, the value is used to evaluate a policy. When `*` is used, all values will match. Make sure to put the `*` as the last tier; otherwise the rest will be ignored.\n\nSee: https://www.krakend.io/docs/enterprise/docs/enterprise/service-settings/tiered-rate-limit/",
            "default": "literal",
            "enum": [ "literal", "policy", "*" ]
          }
        }
      }
    }
  }
}
