{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://api-evangelist.github.io/service-mesh/schemas/configuration",
  "title": "Service Mesh Configuration",
  "description": "Abstract schema representing the core configuration primitives common across service mesh implementations (Istio, Linkerd, Consul Connect, AWS App Mesh, SMI).",
  "type": "object",
  "properties": {
    "apiVersion": {
      "type": "string",
      "description": "API version of the resource (e.g., networking.istio.io/v1alpha3, split.smi-spec.io/v1alpha4)"
    },
    "kind": {
      "type": "string",
      "description": "Resource kind (VirtualService, TrafficSplit, HTTPRouteGroup, etc.)"
    },
    "metadata": {
      "$ref": "#/$defs/Metadata"
    },
    "spec": {
      "type": "object",
      "description": "Resource-specific specification. Contents vary by kind."
    }
  },
  "required": ["apiVersion", "kind", "metadata", "spec"],
  "$defs": {
    "Metadata": {
      "type": "object",
      "description": "Standard Kubernetes-style metadata for service mesh resources",
      "properties": {
        "name": {
          "type": "string",
          "description": "Name of the resource, unique within the namespace"
        },
        "namespace": {
          "type": "string",
          "description": "Kubernetes namespace",
          "default": "default"
        },
        "labels": {
          "type": "object",
          "additionalProperties": {"type": "string"},
          "description": "Key-value label pairs for resource selection"
        },
        "annotations": {
          "type": "object",
          "additionalProperties": {"type": "string"},
          "description": "Key-value annotation pairs for tooling metadata"
        }
      },
      "required": ["name"]
    },
    "TrafficSplit": {
      "type": "object",
      "description": "SMI TrafficSplit for canary and blue-green deployments",
      "properties": {
        "service": {
          "type": "string",
          "description": "Apex (root) service name"
        },
        "backends": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "service": {"type": "string"},
              "weight": {"type": "integer", "minimum": 0, "maximum": 100}
            },
            "required": ["service", "weight"]
          },
          "description": "Weighted backend services. Weights must sum to 100."
        }
      },
      "required": ["service", "backends"]
    },
    "TrafficPolicy": {
      "type": "object",
      "description": "Resilience and connection pool settings common across meshes",
      "properties": {
        "connectionPool": {
          "type": "object",
          "properties": {
            "http": {
              "type": "object",
              "properties": {
                "http1MaxPendingRequests": {"type": "integer"},
                "http2MaxRequests": {"type": "integer"},
                "maxRequestsPerConnection": {"type": "integer"}
              }
            },
            "tcp": {
              "type": "object",
              "properties": {
                "maxConnections": {"type": "integer"},
                "connectTimeout": {"type": "string"}
              }
            }
          }
        },
        "outlierDetection": {
          "type": "object",
          "description": "Circuit breaker / outlier ejection configuration",
          "properties": {
            "consecutive5xxErrors": {"type": "integer"},
            "interval": {"type": "string"},
            "baseEjectionTime": {"type": "string"},
            "maxEjectionPercent": {"type": "integer"}
          }
        },
        "retries": {
          "type": "object",
          "properties": {
            "attempts": {"type": "integer"},
            "perTryTimeout": {"type": "string"},
            "retryOn": {"type": "string", "description": "Comma-separated retry conditions"}
          }
        },
        "timeout": {
          "type": "string",
          "description": "Request timeout in duration format (e.g., 30s, 5m)"
        }
      }
    },
    "MutualTLS": {
      "type": "object",
      "description": "Mutual TLS peer authentication configuration",
      "properties": {
        "mode": {
          "type": "string",
          "enum": ["PERMISSIVE", "STRICT", "DISABLE"],
          "description": "mTLS mode — STRICT enforces mutual TLS for all traffic"
        }
      },
      "required": ["mode"]
    }
  }
}
