{
  "openapi": "3.1.0",
  "info": {
    "title": "Open Code War API",
    "version": "1.0.0",
    "summary": "Public read API for the Open Code War coding-agent leaderboard",
    "description": "Unauthenticated JSON endpoints. Only counts are stored — no prompt content. See https://opencodewar.dev/docs/api for the full reference including plugin-only write endpoints.",
    "contact": {
      "name": "Open Code War",
      "email": "contact@opencodewar.dev",
      "url": "https://opencodewar.dev/contact"
    },
    "license": {
      "name": "BUSL-1.1",
      "url": "https://github.com/dodohankim/opencodewar/blob/main/LICENSE"
    }
  },
  "servers": [
    {
      "url": "https://opencodewar.dev"
    }
  ],
  "paths": {
    "/leaderboard": {
      "get": {
        "operationId": "getLeaderboard",
        "summary": "Ranking snapshot",
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "daily",
                "weekly",
                "weekend",
                "monthly"
              ],
              "default": "daily"
            }
          },
          {
            "name": "metric",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "prompts",
                "chars"
              ],
              "default": "prompts"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "scope",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "global",
                "country",
                "city"
              ],
              "default": "global"
            }
          },
          {
            "name": "country",
            "in": "query",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z]{2}$"
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranking",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/user": {
      "get": {
        "operationId": "getUser",
        "summary": "Public profile and last-30-day daily usage",
        "parameters": [
          {
            "name": "nickname",
            "in": "query",
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 15
            }
          },
          {
            "name": "id",
            "in": "query",
            "description": "public_id slug (alternative to nickname)",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Profile",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/user/hours": {
      "get": {
        "operationId": "getUserHours",
        "summary": "Hour-of-day histogram for one user",
        "parameters": [
          {
            "name": "nickname",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "day",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Histogram",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/zones": {
      "get": {
        "operationId": "getZones",
        "summary": "Countries and cities with registered users",
        "responses": {
          "200": {
            "description": "Zones",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/random": {
      "get": {
        "operationId": "getRandomProfile",
        "summary": "One random public profile",
        "responses": {
          "200": {
            "description": "Profile",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/battle": {
      "get": {
        "operationId": "getBattle",
        "summary": "Public state of a battle",
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[23456789abcdefghjkmnpqrstuvwxyz]{6}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Battle",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Liveness probe",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "required": [
                "error"
              ],
              "properties": {
                "error": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}