{
  "openapi": "3.1.0",
  "info": {
    "title": "Colorbox color API",
    "version": "1.0.0",
    "summary": "Free WCAG contrast checks and text-color repair. No API key.",
    "description": "Check text contrast for one pair or a whole theme, and find a replacement text color that passes WCAG 4.5:1 on every background it sits on. Colors are six-digit hex (with or without #) or URL-encoded, opaque, in-gamut OKLCH literals. Call from a server: cross-origin browser access is not enabled. Reference: https://colorbox.io/docs/api",
    "contact": { "name": "Colorbox", "url": "https://colorbox.io/docs/api", "email": "support@colorbox.io" },
    "termsOfService": "https://colorbox.io/terms"
  },
  "servers": [{ "url": "https://colorbox.io" }],
  "externalDocs": { "description": "HTTP API reference", "url": "https://colorbox.io/docs/api" },
  "paths": {
    "/api/contrast": {
      "get": {
        "operationId": "checkContrast",
        "summary": "Check text contrast for one pair or up to 64 pairs",
        "description": "Pass foreground and background for one pair, or pairs for several. Use one form or the other, not both. Each result reports the WCAG contrast ratio and whether it reaches 4.5:1 for normal text.",
        "parameters": [
          { "name": "foreground", "in": "query", "description": "Text color, for one pair.", "schema": { "$ref": "#/components/schemas/Color" }, "example": "666666" },
          { "name": "background", "in": "query", "description": "Background color, for one pair.", "schema": { "$ref": "#/components/schemas/Color" }, "example": "242424" },
          { "name": "pairs", "in": "query", "description": "1 to 64 comma-separated foreground:background pairs, to check a whole theme in one request.", "schema": { "type": "string" }, "example": "666666:242424,fafafa:0f0f0f" }
        ],
        "responses": {
          "200": {
            "description": "Contrast for one pair, or for each pair plus an overall result.",
            "content": {
              "application/json": {
                "schema": { "oneOf": [{ "$ref": "#/components/schemas/PairResult" }, { "$ref": "#/components/schemas/PairsResult" }] },
                "examples": {
                  "pair": { "value": { "foreground": "666666", "background": "242424", "ratio": 2.7034748321061786, "minimum": 4.5, "passes": false } },
                  "pairs": { "value": { "minimum": 4.5, "passes": false, "pairs": [{ "foreground": "666666", "background": "242424", "ratio": 2.7034748321061786, "passes": false }, { "foreground": "fafafa", "background": "0f0f0f", "ratio": 18.36490146542823, "passes": true }] } }
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" }
        }
      }
    },
    "/api/repair-text-contrast": {
      "get": {
        "operationId": "repairTextContrast",
        "summary": "Suggest a text color that passes on every background",
        "description": "For one text color used on 1 to 8 fixed backgrounds (for example a page, a card and a muted surface), returns a replacement that reaches 4.5:1 on all of them, with before and after ratios. status is repaired, unchanged (the original already passes everywhere) or blocked (no passing candidate; suggestedForeground is null and must not be applied).",
        "parameters": [
          { "name": "foreground", "in": "query", "required": true, "description": "The current text color.", "schema": { "$ref": "#/components/schemas/Color" }, "example": "666666" },
          { "name": "backgrounds", "in": "query", "required": true, "description": "1 to 8 comma-separated background colors the text appears on.", "schema": { "type": "string", "maxLength": 800 }, "example": "0f0f0f,242424" },
          { "name": "token", "in": "query", "description": "A CSS custom property name; the response then includes a ready-to-paste declaration.", "schema": { "type": "string", "pattern": "^--[a-zA-Z][a-zA-Z0-9_-]{0,63}$" }, "example": "--muted-foreground" },
          { "name": "verify", "in": "query", "description": "Set to 1 to include a contrast-check URL for each background.", "schema": { "type": "string", "enum": ["1"] } }
        ],
        "responses": {
          "200": {
            "description": "The repair result.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RepairResult" },
                "example": {
                  "status": "repaired",
                  "foreground": "#666666",
                  "suggestedForeground": "#8b8b8b",
                  "minimum": 4.5,
                  "declaration": "--muted-foreground: #8b8b8b;",
                  "checks": [
                    { "background": "#0f0f0f", "before": 3.338417161485082, "after": 5.62614080080623, "verificationUrl": "/api/contrast?foreground=%238b8b8b&background=%230f0f0f" },
                    { "background": "#242424", "before": 2.7034748321061786, "after": 4.556090303016288, "verificationUrl": "/api/contrast?foreground=%238b8b8b&background=%23242424" }
                  ]
                }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "405": { "$ref": "#/components/responses/MethodNotAllowed" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Color": { "type": "string", "description": "Six-digit hex with or without # (666666, #666666), or a URL-encoded opaque in-gamut OKLCH literal such as oklch(0.5 0.1 250)." },
      "PairResult": {
        "type": "object",
        "required": ["ratio", "minimum", "passes"],
        "properties": {
          "foreground": { "type": "string" },
          "background": { "type": "string" },
          "ratio": { "type": "number", "description": "WCAG 2 contrast ratio, from 1 to 21." },
          "minimum": { "type": "number", "const": 4.5 },
          "passes": { "type": "boolean", "description": "ratio >= 4.5 (normal text)." }
        }
      },
      "PairsResult": {
        "type": "object",
        "required": ["minimum", "passes", "pairs"],
        "properties": {
          "minimum": { "type": "number", "const": 4.5 },
          "passes": { "type": "boolean", "description": "True when every pair passes." },
          "pairs": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "foreground": { "type": "string" },
                "background": { "type": "string" },
                "ratio": { "type": "number" },
                "passes": { "type": "boolean" }
              }
            }
          }
        }
      },
      "RepairResult": {
        "type": "object",
        "required": ["status", "foreground", "suggestedForeground", "minimum", "checks"],
        "properties": {
          "status": { "type": "string", "enum": ["repaired", "unchanged", "blocked"] },
          "foreground": { "type": "string" },
          "suggestedForeground": { "type": ["string", "null"], "description": "Null when blocked." },
          "minimum": { "type": "number", "const": 4.5 },
          "declaration": { "type": "string", "description": "Present when token was given and a suggestion exists." },
          "checks": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "background": { "type": "string" },
                "before": { "type": "number" },
                "after": { "type": ["number", "null"] },
                "verificationUrl": { "type": "string", "description": "Present with verify=1." }
              }
            }
          }
        }
      },
      "Error": { "type": "object", "properties": { "error": { "type": "string" } } }
    },
    "responses": {
      "BadRequest": { "description": "Invalid or missing parameters.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "MethodNotAllowed": { "description": "Only GET is supported.", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    }
  }
}
