{
  "openapi": "3.0.0",
  "info": {
    "title": "LoadEng Test Lab API",
    "version": "1.0.0",
    "description": "API Testing Lab for LoadEng - includes auth, CRUD, file upload, WebSocket, and test endpoints"
  },
  "servers": [
    { "url": "https://lab.engardens.com", "description": "Production" },
    { "url": "http://localhost:3000", "description": "Local development" }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  },
  "paths": {
    "/api/auth/register": {
      "post": {
        "tags": ["Auth"],
        "summary": "Register a new user",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username", "password"],
                "properties": {
                  "username": { "type": "string", "example": "testuser" },
                  "password": { "type": "string", "example": "testpass123" },
                  "email": { "type": "string", "example": "test@example.com" }
                }
              }
            }
          }
        },
        "responses": {
          "201": { "description": "User created" },
          "409": { "description": "Username already exists" }
        }
      }
    },
    "/api/auth/login": {
      "post": {
        "tags": ["Auth"],
        "summary": "Login and get JWT token",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username", "password"],
                "properties": {
                  "username": { "type": "string", "example": "admin" },
                  "password": { "type": "string", "example": "admin" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Login successful, returns JWT token and user object" },
          "401": { "description": "Invalid credentials" }
        }
      }
    },
    "/api/auth/logout": {
      "post": {
        "tags": ["Auth"],
        "summary": "Logout and clear cookie",
        "responses": {
          "200": { "description": "Logout successful" }
        }
      }
    },
    "/api/users": {
      "get": {
        "tags": ["Users"],
        "summary": "List all users",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "in": "query", "name": "limit", "schema": { "type": "integer", "default": 50 } },
          { "in": "query", "name": "offset", "schema": { "type": "integer", "default": 0 } }
        ],
        "responses": {
          "200": { "description": "List of users" },
          "401": { "description": "Unauthorized" }
        }
      },
      "post": {
        "tags": ["Users"],
        "summary": "Create a new user",
        "security": [{ "bearerAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username", "password"],
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "email": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "201": { "description": "User created" }
        }
      }
    },
    "/api/users/{id}": {
      "get": {
        "tags": ["Users"],
        "summary": "Get user by ID",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "in": "path", "name": "id", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "User details" }, "404": { "description": "Not found" } }
      },
      "put": {
        "tags": ["Users"],
        "summary": "Update a user",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "in": "path", "name": "id", "required": true, "schema": { "type": "string" } }],
        "requestBody": { "content": { "application/json": { "schema": { "type": "object", "properties": { "email": { "type": "string" }, "password": { "type": "string" } } } } } },
        "responses": { "200": { "description": "User updated" }, "404": { "description": "Not found" } }
      },
      "delete": {
        "tags": ["Users"],
        "summary": "Delete a user",
        "security": [{ "bearerAuth": [] }],
        "parameters": [{ "in": "path", "name": "id", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Deleted" }, "404": { "description": "Not found" } }
      }
    },
    "/api/files/upload": {
      "post": {
        "tags": ["Files"],
        "summary": "Upload a file",
        "security": [{ "bearerAuth": [] }],
        "requestBody": { "required": true, "content": { "multipart/form-data": { "schema": { "type": "object", "properties": { "file": { "type": "string", "format": "binary" } } } } } },
        "responses": { "200": { "description": "File uploaded" }, "400": { "description": "No file" }, "413": { "description": "Too large" } }
      }
    },
    "/api/health": {
      "get": {
        "tags": ["System"],
        "summary": "Health check",
        "responses": { "200": { "description": "Service healthy" } }
      }
    },
    "/api/metrics": {
      "get": {
        "tags": ["System"],
        "summary": "Live server metrics",
        "responses": { "200": { "description": "Current metrics" } }
      }
    },
    "/api/test/slow": {
      "get": {
        "tags": ["Test"],
        "summary": "Slow response simulation",
        "parameters": [{ "in": "query", "name": "delay", "schema": { "type": "integer", "default": 3000 }, "description": "Delay in ms (max 30000)" }],
        "responses": { "200": { "description": "Delayed response" } }
      }
    },
    "/api/test/error": {
      "get": {
        "tags": ["Test"],
        "summary": "Error simulation",
        "parameters": [
          { "in": "query", "name": "status", "schema": { "type": "integer", "default": 500 }, "description": "Status code (400-599)" },
          { "in": "query", "name": "message", "schema": { "type": "string" } }
        ],
        "responses": { "default": { "description": "Error response" } }
      }
    },
    "/api/test/chunked": {
      "get": {
        "tags": ["Test"],
        "summary": "Chunked transfer response",
        "parameters": [
          { "in": "query", "name": "chunks", "schema": { "type": "integer", "default": 5 } },
          { "in": "query", "name": "interval", "schema": { "type": "integer", "default": 500 }, "description": "ms between chunks" }
        ],
        "responses": { "200": { "description": "Chunked stream" } }
      }
    },
    "/api/test/echo": {
      "post": {
        "tags": ["Test"],
        "summary": "Echo request body and headers",
        "requestBody": { "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": { "200": { "description": "Echoed request" } }
      }
    }
  }
}
