{
  "openapi": "3.0.3",
  "info": {
    "title": "Source Grader API",
    "description": "Scan websites for AI agent visibility and get an Agent Visibility Score.",
    "version": "1.0.0",
    "contact": {
      "name": "Source Grader",
      "url": "https://sourcegrader.com/contact"
    }
  },
  "servers": [
    {
      "url": "https://sourcegrader.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/scan": {
      "post": {
        "summary": "Scan a website for AI agent visibility",
        "description": "Crawls the given URL and evaluates it across 7 categories: schema markup, semantic HTML, machine-readable content, meta & OG tags, agent access, structured data feeds, and WebMCP readiness.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url"],
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "The website URL to scan",
                    "example": "https://example.com"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Scan completed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResult"
                }
              }
            }
          },
          "400": {
            "description": "Invalid URL provided"
          },
          "429": {
            "description": "Rate limit exceeded (5/hr anonymous, 50/hr authenticated)"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ScanResult": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique scan identifier (domain-based)"
          },
          "url": {
            "type": "string",
            "description": "The scanned URL"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "overallScore": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "description": "Agent Visibility Score (0-100)"
          },
          "categories": {
            "type": "object",
            "properties": {
              "schemaMarkup": { "$ref": "#/components/schemas/CategoryResult" },
              "semanticHtml": { "$ref": "#/components/schemas/CategoryResult" },
              "machineReadable": { "$ref": "#/components/schemas/CategoryResult" },
              "metaOg": { "$ref": "#/components/schemas/CategoryResult" },
              "agentAccess": { "$ref": "#/components/schemas/CategoryResult" },
              "structuredFeeds": { "$ref": "#/components/schemas/CategoryResult" },
              "webmcp": { "$ref": "#/components/schemas/CategoryResult" }
            }
          }
        }
      },
      "CategoryResult": {
        "type": "object",
        "properties": {
          "score": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "issues": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/ScanIssue" }
          },
          "details": {
            "type": "object",
            "additionalProperties": true
          }
        }
      },
      "ScanIssue": {
        "type": "object",
        "properties": {
          "severity": {
            "type": "string",
            "enum": ["error", "warning", "info"]
          },
          "message": {
            "type": "string"
          }
        }
      }
    }
  }
}
