{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://nsta1.github.io/Orleans.Lattice/docs/agents/schemas/governance-identity-propagation.schema.json",
  "schema": "lattice.agents/json-schema/v1",
  "title": "Orleans.Lattice identity propagation",
  "description": "Credential and tenant headers, request-context keys, and the flows that carry identity from the transport to the grain call context.",
  "type": "object",
  "required": [
    "schema",
    "headers",
    "request_context_keys",
    "flows",
    "fail_closed"
  ],
  "properties": {
    "schema": {
      "const": "lattice.agents/governance-identity-propagation/v1"
    },
    "headers": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "name",
          "value",
          "request_context_key",
          "source"
        ],
        "properties": {
          "id": {
            "$ref": "#/$defs/id"
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "value": {
            "type": "string",
            "minLength": 1
          },
          "request_context_key": {
            "type": "string",
            "minLength": 1
          },
          "source": {
            "$ref": "#/$defs/source"
          }
        },
        "additionalProperties": false
      }
    },
    "request_context_keys": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "constant",
          "value",
          "carrier",
          "source"
        ],
        "properties": {
          "id": {
            "$ref": "#/$defs/id"
          },
          "constant": {
            "type": "string",
            "minLength": 1
          },
          "value": {
            "type": "string",
            "minLength": 1
          },
          "carrier": {
            "type": "string",
            "minLength": 1
          },
          "source": {
            "$ref": "#/$defs/source"
          }
        },
        "additionalProperties": false
      }
    },
    "flows": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "entry",
          "steps",
          "sources"
        ],
        "properties": {
          "id": {
            "$ref": "#/$defs/id"
          },
          "entry": {
            "type": "string",
            "minLength": 1
          },
          "steps": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          },
          "sources": {
            "$ref": "#/$defs/sources"
          }
        },
        "additionalProperties": false
      }
    },
    "fail_closed": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "rule",
          "sources"
        ],
        "properties": {
          "id": {
            "$ref": "#/$defs/id"
          },
          "rule": {
            "type": "string",
            "minLength": 1
          },
          "sources": {
            "$ref": "#/$defs/sources"
          }
        },
        "additionalProperties": false
      }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "claim": {
      "oneOf": [
        {
          "type": "object",
          "required": [
            "statement",
            "source"
          ],
          "properties": {
            "statement": {
              "type": "string",
              "minLength": 1
            },
            "source": {
              "$ref": "#/$defs/source"
            }
          },
          "additionalProperties": false
        },
        {
          "$ref": "#/$defs/uncertain"
        }
      ]
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
    },
    "package": {
      "type": "string",
      "pattern": "^Orleans\\.Lattice(\\.[A-Z][A-Za-z0-9]*)*$"
    },
    "packages": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^Orleans\\.Lattice(\\.[A-Z][A-Za-z0-9]*)*$"
      }
    },
    "source": {
      "type": "string",
      "pattern": "^((src|docs|test|samples|spec|tools|benchmark|reference-architecture|\\.github)/[A-Za-z0-9_./\\-]+|FEATURES\\.md|PACKAGES\\.md|README\\.md|reference-architecture\\.md)(#[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*)?$"
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^((src|docs|test|samples|spec|tools|benchmark|reference-architecture|\\.github)/[A-Za-z0-9_./\\-]+|FEATURES\\.md|PACKAGES\\.md|README\\.md|reference-architecture\\.md)(#[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)*)?$"
      }
    },
    "text": {
      "type": "string",
      "minLength": 1
    },
    "uncertain": {
      "type": "object",
      "required": [
        "status",
        "reason",
        "required_source"
      ],
      "properties": {
        "status": {
          "const": "uncertain"
        },
        "reason": {
          "type": "string",
          "minLength": 1
        },
        "required_source": {
          "type": "string",
          "minLength": 1
        },
        "issue": {
          "type": "integer",
          "minimum": 1
        }
      },
      "additionalProperties": false
    }
  }
}
