{
  "openapi": "3.1.0",
  "info": {
    "title": "gitwall",
    "version": "0.1.0",
    "summary": "Embeddable GitHub activity widgets and team leaderboards.",
    "description": "A widget is a URL on /w; embedding it is an iframe. This API returns ready-to-paste snippets and the underlying contribution data. All endpoints are GET, CORS-enabled and cached for an hour."
  },
  "servers": [{ "url": "https://gitwall.io" }],
  "paths": {
    "/w": {
      "get": {
        "operationId": "renderWidget",
        "summary": "Render a contribution-graph widget (HTML page meant to be framed)",
        "parameters": [{ "$ref": "#/components/parameters/WidgetParams" }],
        "responses": { "200": { "description": "HTML", "content": { "text/html": {} } }, "400": { "description": "Missing or invalid user" }, "404": { "description": "GitHub user not found" } }
      }
    },
    "/team": {
      "get": {
        "operationId": "renderLeaderboard",
        "summary": "Render a team leaderboard (HTML page meant to be framed)",
        "parameters": [
          { "name": "users", "in": "query", "required": true, "schema": { "type": "string" }, "description": "Comma-separated GitHub logins (max 50)" },
          { "name": "repos", "in": "query", "schema": { "type": "string" }, "description": "Comma-separated owner/repo for lines-of-code stats (max 20)" },
          { "name": "months", "in": "query", "schema": { "type": "integer", "enum": [3, 6, 12], "default": 12 } },
          { "name": "theme", "in": "query", "schema": { "$ref": "#/components/schemas/ThemeId" } },
          { "name": "brand", "in": "query", "schema": { "$ref": "#/components/schemas/Hex" } },
          { "name": "tv", "in": "query", "schema": { "type": "boolean", "default": false } }
        ],
        "responses": { "200": { "description": "HTML", "content": { "text/html": {} } } }
      }
    },
    "/api/v1/widget/snippet": {
      "get": {
        "operationId": "getWidgetSnippet",
        "summary": "Get the iframe snippet and canonical URL for a widget",
        "parameters": [
          { "$ref": "#/components/parameters/WidgetParams" },
          { "name": "width", "in": "query", "schema": { "type": "integer", "default": 800 }, "description": "Target width in CSS px, used to size the fixed-height iframe" }
        ],
        "responses": {
          "200": {
            "description": "Snippet",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": { "type": "string", "format": "uri" },
                    "width": { "type": "integer" },
                    "height": { "type": "integer" },
                    "iframe": { "type": "string", "description": "Fixed-height <iframe> HTML" },
                    "iframeAutoResize": { "type": "string", "description": "<iframe> plus a small script that resizes it to content" },
                    "config": { "$ref": "#/components/schemas/WidgetConfig" }
                  },
                  "required": ["url", "width", "height", "iframe", "iframeAutoResize", "config"]
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/contributions/{user}": {
      "get": {
        "operationId": "getContributions",
        "summary": "Daily contribution counts with a summary",
        "parameters": [
          { "name": "user", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "months", "in": "query", "schema": { "type": "integer", "enum": [3, 6, 12], "default": 12 } }
        ],
        "responses": {
          "200": {
            "description": "Contributions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user": { "type": "string" },
                    "from": { "type": "string", "format": "date" },
                    "to": { "type": "string", "format": "date" },
                    "months": { "type": "integer" },
                    "total": { "type": "integer" },
                    "source": { "type": "string", "enum": ["graphql", "public"] },
                    "days": { "type": "array", "items": { "type": "object", "properties": { "date": { "type": "string", "format": "date" }, "count": { "type": "integer" } } } },
                    "repos": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "url": { "type": "string" }, "commits": { "type": "integer" }, "language": { "type": ["string", "null"] }, "isPrivate": { "type": "boolean" } } } },
                    "summary": {
                      "type": "object",
                      "properties": {
                        "total": { "type": "integer" },
                        "activeDays": { "type": "integer" },
                        "currentStreak": { "type": "integer" },
                        "longestStreak": { "type": "integer" },
                        "peak": { "type": ["object", "null"], "properties": { "date": { "type": "string" }, "count": { "type": "integer" } } }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": { "description": "GitHub user not found" }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "WidgetParams": {
        "name": "user",
        "in": "query",
        "required": true,
        "schema": { "type": "string" },
        "description": "GitHub login. Other optional query params: months (3|6|12), theme (ThemeId), brand (Hex), bg, text, textDim, line, bgElev, accent (Hex), ramp (5 comma-separated Hex), title (string), stats/labels/legend/tooltips/tv (1|0)."
      }
    },
    "schemas": {
      "Hex": { "type": "string", "pattern": "^#?[0-9a-fA-F]{6}$", "description": "RGB hex, # optional" },
      "ThemeId": { "type": "string", "enum": ["github-dark", "github-light", "tethered", "tethered-light", "mono-dark"] },
      "WidgetConfig": {
        "type": "object",
        "properties": {
          "user": { "type": "string" },
          "months": { "type": "integer", "enum": [3, 6, 12] },
          "theme": { "$ref": "#/components/schemas/ThemeId" },
          "colors": {
            "type": "object",
            "properties": {
              "brand": { "$ref": "#/components/schemas/Hex" },
              "bg": { "$ref": "#/components/schemas/Hex" },
              "accent": { "$ref": "#/components/schemas/Hex" },
              "ramp": { "type": "array", "items": { "$ref": "#/components/schemas/Hex" }, "minItems": 5, "maxItems": 5 }
            }
          },
          "title": { "type": "string" },
          "stats": { "type": "boolean" },
          "labels": { "type": "boolean" },
          "legend": { "type": "boolean" },
          "tooltips": { "type": "boolean" },
          "tv": { "type": "boolean" }
        },
        "required": ["user"]
      }
    }
  }
}
