{
  "openapi": "3.1.0",
  "info": {
    "title": "Jank Reports — Test Reports API",
    "version": "1.0.0",
    "description": "AI-powered website quality scan service. Submit a URL, get a scored report (0–100 jank score), a ranked list of bugs with fix prompts, persona feedback, test flows, and category baselines. Each issue includes a `prompt_to_fix_this_issue` field ready to paste into Claude Code, Cursor, or Copilot.",
    "contact": { "email": "jason@testers.ai" },
    "x-llm-guide": "To audit a site: POST /api/reports → poll GET /api/reports/:id until status=done → read analysis.issues. Each issue.prompt_to_fix_this_issue is pre-written for an AI coding agent. Machine-readable report also at GET /r/:id.json and /r/:id.md."
  },
  "servers": [
    { "url": "https://reports.jank.ai", "description": "Production" }
  ],
  "security": [
    { "ApiKeyAuth": [], "AccountHeader": [] }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "API key in the form jk_... — email jason@testers.ai to get one. Omit for demo mode (1 report/day, 1 URL)."
      },
      "AccountHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Account",
        "description": "Your email address. Required for demo mode; also required alongside X-Api-Key."
      }
    },
    "schemas": {
      "ReportRequest": {
        "type": "object",
        "required": ["urls"],
        "properties": {
          "urls": {
            "type": "array",
            "items": { "type": "string", "format": "uri" },
            "minItems": 1,
            "maxItems": 25,
            "description": "URLs to audit. Scheme auto-prefixed if missing. SSRF-checked."
          },
          "visibility": {
            "type": "string",
            "enum": ["public", "private"],
            "default": "public",
            "description": "Private reports require admin token to view."
          },
          "label": {
            "type": "string",
            "description": "Free-form tag shown in the admin UI."
          },
          "subpages": {
            "oneOf": [
              { "type": "boolean", "enum": [false] },
              {
                "type": "object",
                "properties": {
                  "enabled": { "type": "boolean" },
                  "count": { "type": "integer", "minimum": 0, "maximum": 20 }
                }
              }
            ],
            "default": { "enabled": true, "count": 2 },
            "description": "AI picks N additional pages from the entry URL."
          },
          "flows": {
            "oneOf": [
              { "type": "boolean", "enum": [false] },
              {
                "type": "object",
                "properties": {
                  "enabled": { "type": "boolean" },
                  "count": { "type": "integer", "minimum": 1, "maximum": 10 },
                  "customPrompt": { "type": "string" }
                }
              }
            ],
            "default": { "enabled": true, "count": 5 },
            "description": "Generate N test flows with screenshots."
          },
          "personas": {
            "oneOf": [
              { "type": "boolean", "enum": [false] },
              {
                "type": "object",
                "properties": {
                  "enabled": { "type": "boolean" },
                  "count": { "type": "integer", "minimum": 1, "maximum": 10 },
                  "customPrompt": { "type": "string" }
                }
              }
            ],
            "description": "Generate N persona reviews. Off by default in demo mode."
          },
          "provider": {
            "type": "string",
            "enum": ["gemini", "openai", "anthropic"],
            "default": "gemini"
          },
          "model": {
            "type": "string",
            "description": "E.g. gemini-2.0-flash, gpt-4o-mini, claude-3-5-sonnet-latest. See GET /api/providers."
          },
          "emails": {
            "type": "array",
            "items": { "type": "string", "format": "email" },
            "description": "Send a 'report ready' email to each address."
          },
          "account": {
            "type": "string",
            "format": "email",
            "description": "Required for demo mode. Maps daily quotas."
          }
        }
      },
      "ReportCreated": {
        "type": "object",
        "properties": {
          "created": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": { "type": "string", "format": "uuid" },
                "url": { "type": "string", "format": "uri" },
                "visibility": { "type": "string" },
                "viewUrl": { "type": "string", "description": "Relative path to rendered HTML report, e.g. /r/:id" }
              }
            }
          }
        }
      },
      "Issue": {
        "type": "object",
        "properties": {
          "bug_title": { "type": "string" },
          "bug_type": { "type": "array", "items": { "type": "string" }, "description": "e.g. [\"accessibility\", \"ux\"]" },
          "bug_priority": { "type": "integer", "minimum": 1, "maximum": 5, "description": "1=highest, 5=lowest" },
          "bug_severity": { "type": "string", "enum": ["critical", "severe", "moderate", "minor"] },
          "bug_reasoning_why_a_bug": { "type": "string" },
          "suggested_fix": { "type": "string" },
          "prompt_to_fix_this_issue": { "type": "string", "description": "Pre-written prompt ready to paste into Claude Code, Cursor, Copilot, etc." }
        }
      },
      "Report": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "url": { "type": "string", "format": "uri" },
          "status": { "type": "string", "enum": ["queued", "running", "done", "failed"] },
          "createdAt": { "type": "integer", "description": "Unix timestamp ms" },
          "finishedAt": { "type": "integer", "description": "Unix timestamp ms" },
          "analysis": {
            "type": "object",
            "properties": {
              "score": { "type": "integer", "minimum": 0, "maximum": 100, "description": "0=clean, 100=maximum jank" },
              "summary": { "type": "string" },
              "issues": { "type": "array", "items": { "$ref": "#/components/schemas/Issue" } }
            }
          },
          "personaFeedback": {
            "type": "object",
            "properties": {
              "personas": { "type": "array", "items": { "type": "object" } }
            }
          },
          "testFlows": {
            "type": "object",
            "properties": {
              "flows": { "type": "array", "items": { "type": "object" } }
            }
          },
          "baselines": {
            "type": "object",
            "properties": {
              "category": {
                "type": "object",
                "properties": {
                  "name": { "type": "string" },
                  "appCount": { "type": "integer" },
                  "avgJank": { "type": "number" }
                }
              },
              "you": { "type": "object", "properties": { "jank": { "type": "number" } } },
              "rank": { "type": "object", "properties": { "betterThanPct": { "type": "number" } } },
              "aiAnalysis": { "type": "string" }
            }
          },
          "artifacts": {
            "type": "object",
            "properties": {
              "entryScreenshotUrl": { "type": "string", "format": "uri" }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api/reports": {
      "post": {
        "operationId": "submitReport",
        "summary": "Submit a new quality scan",
        "description": "Submit one or more URLs for AI quality analysis. Returns immediately with report ID(s). Analysis runs asynchronously — poll GET /api/reports/:id for status. Most demo runs finish in 60–180 seconds.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ReportRequest" },
              "example": {
                "urls": ["https://example.com"],
                "visibility": "public",
                "subpages": { "enabled": true, "count": 2 },
                "flows": { "enabled": true, "count": 5 },
                "personas": { "enabled": true, "count": 4 },
                "account": "you@example.com"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reports created",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ReportCreated" }
              }
            }
          },
          "400": { "description": "Invalid request (missing urls, bad URL, SSRF)" },
          "401": { "description": "No auth provided" },
          "403": { "description": "Plan cap exceeded" },
          "429": { "description": "Daily quota exhausted" }
        }
      },
      "get": {
        "operationId": "listReports",
        "summary": "List your reports",
        "parameters": [
          { "name": "limit", "in": "query", "schema": { "type": "integer", "default": 20 } }
        ],
        "responses": {
          "200": {
            "description": "Array of reports",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Report" } }
              }
            }
          }
        }
      }
    },
    "/api/reports/{id}": {
      "get": {
        "operationId": "getReport",
        "summary": "Fetch a report by ID",
        "description": "Returns full report JSON. Poll every 5s while status is queued or running. Public reports are world-readable without auth.",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": {
            "description": "Report (may still be queued/running)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Report" }
              }
            }
          },
          "404": { "description": "Report not found" }
        }
      }
    },
    "/api/reports/{id}/chat": {
      "post": {
        "operationId": "chatWithReport",
        "summary": "Chat with a report",
        "description": "Brand-aware chat backed by the configured LLM. Server attaches a compact report summary (issues, personas, flows, baselines) as context.",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "role": { "type": "string", "enum": ["user", "assistant"] },
                        "content": { "type": "string", "maxLength": 600 }
                      }
                    },
                    "maxItems": 12
                  },
                  "brand": { "type": "string", "enum": ["jank", "testers.ai", "icebergqa.com"], "default": "jank" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Chat reply",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "reply": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/r/{id}.json": {
      "get": {
        "operationId": "getReportJson",
        "summary": "Get full report as JSON (machine-readable)",
        "description": "Includes all issues with prompt_to_fix_this_issue, personas, flows, baselines. Ready to pipe into an agent or CI system.",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": { "description": "Full report JSON", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Report" } } } }
        }
      }
    },
    "/r/{id}.md": {
      "get": {
        "operationId": "getReportMarkdown",
        "summary": "Get full report as Markdown (LLM-pasteable)",
        "description": "Includes every issue and its prompt_to_fix_this_issue. Ready to paste into a doc, issue tracker, or AI coding agent.",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string", "format": "uuid" } }
        ],
        "responses": {
          "200": { "description": "Markdown report", "content": { "text/markdown": {} } }
        }
      }
    },
    "/api/providers": {
      "get": {
        "operationId": "listProviders",
        "summary": "List available LLM providers and models",
        "responses": {
          "200": {
            "description": "Provider/model list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "providers": { "type": "array", "items": { "type": "string" } },
                    "default": { "type": "string" },
                    "models": { "type": "object" }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
