{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/abmeter-ai/json-schema/abmeter-ai-metric-schema.json",
  "title": "Metric",
  "description": "Customer-defined business KPI with a formula over measures. Metrics combine measures using mathematical expressions.",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/abmeter-ai-metrics-api-openapi.yml#/components/schemas/Metric",
  "type": "object",
  "properties": {
    "slug": {
      "$ref": "#/$defs/Slug"
    },
    "description": {
      "type": [
        "string",
        "null"
      ],
      "description": "Human-readable description of what this metric measures"
    },
    "formula": {
      "type": "string",
      "description": "Formula expression using measures (e.g., \"count(purchase)\", \"sum(purchase.amount)\")"
    },
    "based_on_events": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "readOnly": true,
      "description": "Event type slugs referenced in the formula (derived automatically)"
    },
    "created_at": {
      "type": "string",
      "format": "date-time",
      "readOnly": true
    },
    "updated_at": {
      "type": "string",
      "format": "date-time",
      "readOnly": true
    }
  },
  "required": [
    "slug",
    "formula"
  ],
  "$defs": {
    "Slug": {
      "type": "string",
      "description": "Standardized identifier for entities used across the API. Recommended format: each entity type has its own prefix pattern followed by a short alphanumeric identifier (e.g., parameter-ab4c, space-main, audience-control)."
    }
  }
}