{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://seoscore.tools/schema/scan-v1.json",
  "title": "seoscore.tools POST /api/v1/scan response",
  "description": "Answer of POST /api/v1/scan with body {\"url\": string, \"keyphrase\"?: string}. Either a scan result or an error. Version 1: fields are only added in a new version, never renamed or retyped.",
  "oneOf": [
    { "$ref": "#/$defs/result" },
    { "$ref": "#/$defs/error" }
  ],
  "$defs": {
    "score": {
      "description": "0-100, or null when the engine produced no score.",
      "type": ["integer", "null"],
      "minimum": 0,
      "maximum": 100
    },
    "result": {
      "type": "object",
      "additionalProperties": false,
      "required": ["schema_version", "url", "scanned_at", "scores", "checks", "warnings"],
      "properties": {
        "schema_version": { "const": "1" },
        "url": { "type": "string", "minLength": 1, "description": "Final URL after redirects." },
        "scanned_at": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$" },
        "scores": {
          "type": "object",
          "additionalProperties": false,
          "required": ["overall", "seo", "aeo", "geo", "cwv"],
          "properties": {
            "overall": { "type": "integer", "minimum": 0, "maximum": 100, "description": "round(seo*0.5 + aeo*0.25 + geo*0.25), the number the website shows." },
            "seo": { "$ref": "#/$defs/score" },
            "aeo": { "$ref": "#/$defs/score" },
            "geo": { "$ref": "#/$defs/score" },
            "cwv": { "$ref": "#/$defs/score", "description": "Core Web Vitals from PageSpeed Insights; null when PageSpeed returned no usable data. Not part of overall." }
          }
        },
        "checks": {
          "type": "array",
          "description": "Applicable checks only. Which checks appear depends on the page.",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["id", "engine", "category", "pass", "severity", "applicable", "message", "fix"],
            "properties": {
              "id": { "type": "string", "pattern": "^[a-z0-9_]+$" },
              "engine": { "enum": ["seo", "aeo", "geo", "cwv"] },
              "category": { "type": ["string", "null"] },
              "pass": { "type": "boolean" },
              "severity": { "enum": ["error", "warning", "info", "default"], "description": "As the engine sets it; may change with the result. Score weight: error 3, warning 1, info 0, default 2." },
              "applicable": { "const": true },
              "message": { "type": "string", "description": "The label the website shows." },
              "fix": { "type": ["string", "null"], "description": "Stored fix hint, or null when none is stored. null does not mean unimportant." }
            }
          }
        },
        "warnings": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Notes on the reliability of this scan, e.g. client-side rendered page or missing Core Web Vitals."
        }
      }
    },
    "error": {
      "type": "object",
      "additionalProperties": false,
      "required": ["schema_version", "error"],
      "properties": {
        "schema_version": { "const": "1" },
        "error": {
          "type": "object",
          "additionalProperties": false,
          "required": ["code", "message"],
          "properties": {
            "code": {
              "enum": ["invalid_request", "invalid_url", "private_url", "fetch_failed", "http_error", "not_html", "too_large", "timeout", "rate_limited", "target_rate_limited", "internal"],
              "description": "HTTP 400: invalid_request, invalid_url, private_url. 422: fetch_failed, http_error, not_html, too_large, timeout. 429 (with Retry-After): rate_limited (per client address, 5/min), target_rate_limited (per target domain, 30/h). 500: internal."
            },
            "message": { "type": "string" }
          }
        }
      }
    }
  }
}
