{
  "openapi": "3.0.3",
  "info": {
    "title": "WebInventory API",
    "version": "1",
    "description": "Read API of the WebInventory Minecraft plugin. The public endpoints are what the web UI uses (per-IP rate limits). The Developer API (Premium) adds named keys with scopes: send the key as X-API-Key or Authorization: Bearer. Scopes: read (own rate limit, api.rate-limit per minute), live (WebSocket /ws/inventory/*; in the URL as ?api_key= only a live-only key is accepted), admin (admin endpoints, admin IP whitelist applies). Every path also exists under /api/v1, the stable prefix for integrations. Errors are {\"error\": message, \"code\": machine_code}."
  },
  "servers": [{ "url": "/api/v1" }],
  "components": {
    "securitySchemes": {
      "ApiKey": { "type": "apiKey", "in": "header", "name": "X-API-Key" },
      "Bearer": { "type": "http", "scheme": "bearer" }
    },
    "parameters": {
      "Username": {
        "name": "username", "in": "path", "required": true,
        "description": "Player name (Bedrock names may start with . or *)",
        "schema": { "type": "string", "pattern": "^[A-Za-z0-9_.*]{1,32}$" }
      }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string" },
          "code": {
            "type": "string",
            "enum": ["bad_request", "unauthorized", "invalid_api_key", "premium_required", "forbidden", "not_found",
              "conflict", "length_required", "too_large", "rate_limited", "unavailable", "internal_error", "error"]
          }
        }
      },
      "PlayerSummary": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "uuid": { "type": "string" },
          "online": { "type": "boolean" },
          "lastUpdated": { "type": "integer", "format": "int64" },
          "server": { "type": "string", "description": "Network mode only: the server the player is (or was last) on; omitted on a single server" },
          "bedrock": { "type": "boolean" },
          "skin": { "type": "string", "nullable": true, "description": "Skin texture id of a Bedrock player (textures.minecraft.net/texture/<id>)" },
          "discordId": { "type": "string", "nullable": true },
          "avatarUrl": { "type": "string", "nullable": true },
          "skinUrl": { "type": "string", "nullable": true }
        }
      },
      "Item": {
        "type": "object",
        "properties": {
          "material": { "type": "string", "description": "Vanilla material or namespace:id of a custom item" },
          "amount": { "type": "integer" },
          "displayName": { "type": "string", "nullable": true },
          "lore": { "type": "array", "items": { "type": "string" } },
          "enchantments": { "type": "object", "additionalProperties": { "type": "integer" } },
          "durability": { "type": "integer" },
          "maxDurability": { "type": "integer" },
          "customModelData": { "type": "integer" }
        },
        "nullable": true,
        "description": "null for an empty slot"
      },
      "LeaderboardEntry": {
        "type": "object",
        "properties": {
          "rank": { "type": "integer" },
          "name": { "type": "string" },
          "uuid": { "type": "string" },
          "value": { "type": "integer", "format": "int64" },
          "online": { "type": "boolean" },
          "bedrock": { "type": "boolean" },
          "skin": { "type": "string", "nullable": true }
        }
      }
    }
  },
  "security": [{}, { "ApiKey": [] }, { "Bearer": [] }],
  "paths": {
    "/health": {
      "get": { "summary": "Server is up; plugin version", "responses": { "200": { "description": "OK" } } }
    },
    "/settings": {
      "get": { "summary": "Enabled modules, language, theme, premium flag", "responses": { "200": { "description": "OK" } } }
    },
    "/players": {
      "get": {
        "summary": "Players visible on the web",
        "parameters": [
          { "name": "online", "in": "query", "schema": { "type": "boolean" }, "description": "Only online players" },
          { "name": "q", "in": "query", "schema": { "type": "string", "minLength": 1, "maxLength": 32 }, "description": "Part of the name, case-insensitive" },
          { "name": "limit", "in": "query", "schema": { "type": "integer", "minimum": 1, "maximum": 1000 } },
          { "name": "offset", "in": "query", "schema": { "type": "integer", "minimum": 0 } }
        ],
        "description": "Without limit/offset every match is returned; with them the result is sorted by name. total counts the matches before paging. Revalidate with If-None-Match (ETag).",
        "responses": {
          "200": {
            "description": "OK",
            "content": { "application/json": { "schema": { "type": "object", "properties": {
              "players": { "type": "array", "items": { "$ref": "#/components/schemas/PlayerSummary" } },
              "total": { "type": "integer" } } } } }
          },
          "400": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/player/{username}": {
      "get": {
        "summary": "One player (Discord link, skin)",
        "parameters": [{ "$ref": "#/components/parameters/Username" }],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PlayerSummary" } } } },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/player/{username}/inventory": {
      "get": {
        "summary": "Full snapshot: inventory, armor, off-hand, ender chest, stats, advancements, effects",
        "description": "Sections the player or the server hides are empty; enabledFeatures says which. Revalidate with If-None-Match (ETag).",
        "parameters": [{ "$ref": "#/components/parameters/Username" }],
        "responses": {
          "200": { "description": "OK" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/player/{username}/enderchest": {
      "get": {
        "summary": "Ender chest only",
        "parameters": [{ "$ref": "#/components/parameters/Username" }],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "type": "object", "properties": {
            "enderChest": { "type": "array", "items": { "$ref": "#/components/schemas/Item" } } } } } } },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/search": {
      "get": {
        "summary": "Find an item across visible inventories",
        "parameters": [{ "name": "q", "in": "query", "required": true, "schema": { "type": "string", "minLength": 2, "maxLength": 64 } }],
        "responses": { "200": { "description": "At most 200 results" }, "400": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/leaderboards": {
      "get": {
        "summary": "Every leaderboard (cached; refreshSeconds)",
        "responses": {
          "200": {
            "description": "OK",
            "content": { "application/json": { "schema": { "type": "object", "properties": {
              "size": { "type": "integer" },
              "refreshSeconds": { "type": "integer" },
              "boards": { "type": "array", "items": { "type": "object", "properties": {
                "id": { "type": "string" },
                "unit": { "type": "string", "enum": ["ticks", "cm", "count"] },
                "entries": { "type": "array", "items": { "$ref": "#/components/schemas/LeaderboardEntry" } } } } } } } } }
          },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/texture/{material}": {
      "get": {
        "summary": "Item icon (PNG)",
        "parameters": [{ "name": "material", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "image/png" }, "503": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/admin/items": {
      "get": {
        "summary": "Store items (admin)",
        "description": "Admin endpoints accept an admin session token or a Developer API key with the admin scope, only from addresses allowed by admin.security.ip-whitelist. Writes are in the audit log under the key's name.",
        "security": [{ "ApiKey": [] }, { "Bearer": [] }],
        "responses": { "200": { "description": "OK" }, "401": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/admin/transactions": {
      "get": {
        "summary": "Store transactions (admin)",
        "security": [{ "ApiKey": [] }, { "Bearer": [] }],
        "parameters": [{ "name": "limit", "in": "query", "schema": { "type": "integer", "default": 100 } }],
        "responses": { "200": { "description": "OK" }, "401": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/admin/stats": {
      "get": {
        "summary": "Store statistics (admin)",
        "security": [{ "ApiKey": [] }, { "Bearer": [] }],
        "responses": { "200": { "description": "OK" }, "401": { "$ref": "#/components/responses/Error" } }
      }
    }
  }
}
