{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://gaspwiki.com/schemas/gasp-adapter-v1.json",
  "title": "GASP Adapter",
  "description": "Maps a business's data warehouse columns to the canonical GASP field schema. Fill in warehouseRef for each field your systems provide, then validate to see which GASP metrics you can compute.",
  "type": "object",
  "required": ["version", "metricOwners", "mappings"],
  "properties": {
    "version": {
      "const": "1.0",
      "description": "Adapter schema version"
    },
    "organization": {
      "type": "string",
      "description": "Your organization name (for reference only)"
    },
    "warehouse": {
      "type": "string",
      "description": "Warehouse platform (e.g. snowflake, bigquery, postgres, redshift, databricks)",
      "examples": ["snowflake", "bigquery", "postgres"]
    },
    "metricOwners": {
      "type": "array",
      "description": "Who in your organization owns each metric definition. Required — someone must be accountable for every metric being calculated correctly.",
      "items": {
        "$ref": "#/$defs/metricOwner"
      }
    },
    "mappings": {
      "type": "array",
      "description": "One entry per GASP field you can map. You don't need to map every field — the validator will tell you which metrics are covered.",
      "items": {
        "$ref": "#/$defs/fieldMapping"
      }
    }
  },
  "$defs": {
    "metricOwner": {
      "type": "object",
      "required": ["metric", "team"],
      "description": "Declares who in your organization owns the definition of a metric. This is the person or team that resolves disputes about how the metric is calculated.",
      "properties": {
        "metric": {
          "type": "string",
          "description": "Metric name or group (e.g. 'NRR / GRR', 'Pipeline Value', 'All Core Metrics')",
          "examples": ["ARR / MRR", "NRR / GRR", "Pipeline Value", "Health Score"]
        },
        "team": {
          "type": "string",
          "description": "The team that owns this metric definition",
          "examples": ["Finance", "RevOps", "Data Engineering", "Customer Success"]
        },
        "contact": {
          "type": "string",
          "description": "Optional contact person — email, Slack handle, or name",
          "examples": ["jane@acme.com", "#finance-metrics", "Jane Smith"]
        }
      },
      "additionalProperties": false
    },
    "fieldMapping": {
      "type": "object",
      "required": ["gaspField", "warehouseRef"],
      "properties": {
        "gaspField": {
          "type": "string",
          "description": "Canonical GASP field name (e.g. 'account_id', 'mrr_start', 'churn_date'). Must match a field ID from the GASP ontology."
        },
        "warehouseRef": {
          "type": "string",
          "description": "Your warehouse reference: schema.table.column (e.g. 'analytics.account_cohorts.beginning_mrr'). Leave empty in the template for fields you haven't mapped yet.",
          "examples": ["analytics.accounts.id", "billing.subscriptions.mrr", "dbt_marts.cohorts.beginning_mrr"]
        },
        "transform": {
          "type": "string",
          "description": "Optional SQL expression to transform the source value to match GASP's expected semantics. Use {{value}} as a placeholder for the column value.",
          "examples": ["{{value}} / 100", "CASE WHEN {{value}} = 'active' THEN true ELSE false END", "DATE_TRUNC('month', {{value}})"]
        },
        "owner": {
          "type": "string",
          "description": "Optional: team or person that owns this data pipeline/source field. Who to contact when the data is stale or incorrect.",
          "examples": ["Data Engineering", "Analytics Team", "billing-pipeline@acme.com"]
        },
        "notes": {
          "type": "string",
          "description": "Optional free-text notes about this mapping (e.g. 'Only available after 2024-01', 'Derived from two columns')"
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
