{
  "openapi": "3.1.0",
  "info": {
    "title": "SlimeFarm Canon API",
    "version": "1.0.0",
    "summary": "CRUD API for a markdown worldbuilding canon. Prefer action=export for single-shot ingestion; format=md returns raw markdown."
  },
  "servers": [{ "url": "https://mojichang.tailfe9dc4.ts.net/Slime" }],
  "components": {
    "securitySchemes": {
      "apiKeyQuery":  { "type": "apiKey", "in": "query",  "name": "key" },
      "apiKeyHeader": { "type": "apiKey", "in": "header", "name": "X-API-Key" }
    },
    "schemas": {
      "Ok":    { "type": "object", "properties": { "ok": { "const": true } } },
      "Error": { "type": "object", "properties": { "ok": { "const": false }, "error": { "type": "string" } } }
    }
  },
  "paths": {
    "/api.php": {
      "get": {
        "summary": "Read-only actions: list, read, export, history, revision, diff, trash_list. PUBLIC — no auth required.",
        "security": [],
        "parameters": [
          { "name": "action", "in": "query", "required": true, "schema": { "type": "string", "enum": ["list", "read", "export", "history", "revision", "diff", "trash_list"] } },
          { "name": "file",   "in": "query", "schema": { "type": "string", "description": "Canon-relative path ending in .md, .html, or .txt" } },
          { "name": "format", "in": "query", "schema": { "type": "string", "enum": ["json", "md", "txt"] } },
          { "name": "rev",    "in": "query", "schema": { "type": "integer" } }
        ],
        "responses": {
          "200": { "description": "Success (JSON unless format=md/txt)", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Ok" } }, "text/markdown": { "schema": { "type": "string" } } } },
          "400": { "description": "Bad request",   "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "Invalid auth",  "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "Not found",     "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      },
      "post": {
        "summary": "Mutating actions: write, delete, rename, mkdir, rmdir, rename_dir, revert, restore. write takes raw file body. Requires API key.",
        "security": [{ "apiKeyQuery": [] }, { "apiKeyHeader": [] }],
        "parameters": [
          { "name": "action", "in": "query", "required": true, "schema": { "type": "string", "enum": ["write", "delete", "rename", "mkdir", "rmdir", "rename_dir", "revert", "restore"] } },
          { "name": "file",      "in": "query", "schema": { "type": "string" } },
          { "name": "new",       "in": "query", "schema": { "type": "string" } },
          { "name": "dir",       "in": "query", "schema": { "type": "string" } },
          { "name": "recursive", "in": "query", "schema": { "type": "string", "enum": ["0", "1"] } },
          { "name": "rev",       "in": "query", "schema": { "type": "integer" } },
          { "name": "uuid",      "in": "query", "schema": { "type": "string" } }
        ],
        "requestBody": {
          "description": "For action=write only: raw file content as the body.",
          "content": { "text/plain": { "schema": { "type": "string" } }, "text/markdown": { "schema": { "type": "string" } } }
        },
        "responses": {
          "200": { "description": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Ok" } } } },
          "400": { "description": "Bad request",  "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "Invalid auth", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "Not found",    "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  }
}
