{
  "openapi": "3.1.0",
  "info": {
    "title": "Small-Server",
    "version": "1.4.0",
    "description": "A tiny REST API testing server \u2014 full CRUD on any JSON payload, SQLite-backed. Built with Go. Includes public HTTP lab endpoints for echo, status, delay, redirect, and cache testing. Only /secure/* routes require X-API-Key authentication."
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Item": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "payload": {
            "description": "Whatever JSON you sent, stored verbatim"
          },
          "scope": {
            "type": "string",
            "enum": [
              "public",
              "secure"
            ]
          },
          "created_at": {
            "type": "string"
          }
        }
      },
      "Cleared": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "cleared"
          },
          "scope": {
            "type": "string"
          },
          "removed": {
            "type": "integer",
            "description": "count of items deleted"
          }
        }
      },
      "Deleted": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "example": "deleted"
          },
          "id": {
            "type": "integer"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "detail": {
            "type": "string"
          }
        }
      },
      "EchoResponse": {
        "type": "object",
        "required": [
          "method",
          "path",
          "query",
          "headers",
          "body",
          "json",
          "bytes"
        ],
        "properties": {
          "method": {
            "type": "string"
          },
          "path": {
            "type": "string"
          },
          "query": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "headers": {
            "type": "object",
            "description": "Header names map to arrays of values. Authorization, Cookie, and X-API-Key values are redacted.",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          "body": {
            "type": "string",
            "description": "Raw request body text."
          },
          "json": {
            "description": "Parsed JSON body, or null when the body is not valid JSON."
          },
          "bytes": {
            "type": "integer",
            "description": "Request body size in bytes."
          }
        }
      },
      "LabStatus": {
        "type": "object",
        "required": [
          "status",
          "message"
        ],
        "properties": {
          "status": {
            "type": "integer"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "LabDelay": {
        "type": "object",
        "required": [
          "delay_ms",
          "status"
        ],
        "properties": {
          "delay_ms": {
            "type": "integer"
          },
          "status": {
            "type": "string",
            "const": "ok"
          }
        }
      },
      "LabCached": {
        "type": "object",
        "required": [
          "message",
          "version"
        ],
        "properties": {
          "message": {
            "type": "string",
            "example": "Cached response"
          },
          "version": {
            "type": "integer",
            "const": 1
          }
        }
      },
      "UploadStatus": {
        "type": "object",
        "required": [
          "configured",
          "max_bytes"
        ],
        "properties": {
          "configured": {
            "type": "boolean"
          },
          "max_bytes": {
            "type": "integer",
            "const": 10485760
          }
        }
      },
      "UploadFile": {
        "type": "object",
        "required": [
          "key",
          "size",
          "etag",
          "last_modified"
        ],
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}-[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"
          },
          "size": {
            "type": "integer"
          },
          "etag": {
            "type": "string"
          },
          "last_modified": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "UploadList": {
        "type": "object",
        "required": [
          "files",
          "next_cursor"
        ],
        "properties": {
          "files": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "$ref": "#/components/schemas/UploadFile"
            }
          },
          "next_cursor": {
            "type": "string"
          }
        }
      },
      "UploadCreated": {
        "type": "object",
        "required": [
          "key",
          "filename",
          "size",
          "content_type",
          "download_path"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "filename": {
            "type": "string"
          },
          "size": {
            "type": "integer"
          },
          "content_type": {
            "type": "string"
          },
          "download_path": {
            "type": "string",
            "example": "/secure/uploads/0123456789abcdef0123456789abcdef-example.txt"
          }
        }
      }
    }
  },
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "ok",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "example": "ok"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/stats": {
      "get": {
        "tags": [
          "meta"
        ],
        "summary": "Lightweight in-memory telemetry (resets on restart)",
        "responses": {
          "200": {
            "description": "stats snapshot",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "uptime_seconds": {
                      "type": "integer"
                    },
                    "started_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "total_requests": {
                      "type": "integer"
                    },
                    "by_method": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "integer"
                      }
                    },
                    "by_status": {
                      "type": "object",
                      "additionalProperties": {
                        "type": "integer"
                      }
                    },
                    "last_request": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "latency": {
                      "type": "object",
                      "description": "Latency over the last 100 requests",
                      "properties": {
                        "avg_ms": {
                          "type": "number"
                        },
                        "min_ms": {
                          "type": "number"
                        },
                        "max_ms": {
                          "type": "number"
                        },
                        "p95_ms": {
                          "type": "number"
                        },
                        "samples": {
                          "type": "integer"
                        }
                      }
                    },
                    "items_total": {
                      "type": "integer"
                    },
                    "items_public": {
                      "type": "integer"
                    },
                    "items_secure": {
                      "type": "integer"
                    },
                    "db_size_bytes": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/public/items": {
      "get": {
        "tags": [
          "public"
        ],
        "summary": "List all public items",
        "responses": {
          "200": {
            "description": "array of items",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Item"
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "public"
        ],
        "summary": "Create \u2014 store ANY JSON payload (no auth)",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "description": "Any valid JSON \u2014 object, array, string, number, boolean, or null"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "created item",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Item"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "public"
        ],
        "summary": "Clear all \u2014 delete every public item",
        "responses": {
          "200": {
            "description": "cleared",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Cleared"
                }
              }
            }
          }
        }
      }
    },
    "/public/items/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "tags": [
          "public"
        ],
        "summary": "Read one public item by id",
        "responses": {
          "200": {
            "description": "item",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Item"
                }
              }
            }
          },
          "404": {
            "description": "not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": [
          "public"
        ],
        "summary": "Update \u2014 replace the payload of a public item",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "description": "Any valid JSON \u2014 replaces the existing payload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "updated item",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Item"
                }
              }
            }
          },
          "404": {
            "description": "not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "public"
        ],
        "summary": "Delete one public item by id",
        "responses": {
          "200": {
            "description": "deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Deleted"
                }
              }
            }
          },
          "404": {
            "description": "not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/secure/items": {
      "get": {
        "tags": [
          "secure"
        ],
        "summary": "List all secure items",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "array of items",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Item"
                  }
                }
              }
            }
          },
          "401": {
            "description": "missing/invalid API key"
          }
        }
      },
      "post": {
        "tags": [
          "secure"
        ],
        "summary": "Create \u2014 store ANY JSON payload",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "description": "Any valid JSON"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "created item",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Item"
                }
              }
            }
          },
          "401": {
            "description": "missing/invalid API key"
          }
        }
      },
      "delete": {
        "tags": [
          "secure"
        ],
        "summary": "Clear all \u2014 delete every secure item",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "cleared",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Cleared"
                }
              }
            }
          },
          "401": {
            "description": "missing/invalid API key"
          }
        }
      }
    },
    "/secure/items/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "integer"
          }
        }
      ],
      "get": {
        "tags": [
          "secure"
        ],
        "summary": "Read one secure item by id",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "item",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Item"
                }
              }
            }
          },
          "404": {
            "description": "not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "missing/invalid API key"
          }
        }
      },
      "put": {
        "tags": [
          "secure"
        ],
        "summary": "Update \u2014 replace the payload of a secure item",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "description": "Any valid JSON \u2014 replaces the existing payload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "updated item",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Item"
                }
              }
            }
          },
          "404": {
            "description": "not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "missing/invalid API key"
          }
        }
      },
      "delete": {
        "tags": [
          "secure"
        ],
        "summary": "Delete one secure item by id",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Deleted"
                }
              }
            }
          },
          "404": {
            "description": "not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "missing/invalid API key"
          }
        }
      }
    },
    "/lab/echo": {
      "get": {
        "tags": [
          "http-lab"
        ],
        "summary": "Echo request details",
        "description": "Returns the request method, path, query values and header values as arrays, raw body text, parsed JSON or null, and body byte count. Authorization, Cookie, and X-API-Key header values are redacted. Request bodies are limited to 1 MiB.",
        "responses": {
          "200": {
            "description": "Echoed request (HEAD has no response body)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds 1 MiB"
          }
        }
      },
      "post": {
        "tags": [
          "http-lab"
        ],
        "summary": "Echo request details",
        "description": "Returns the request method, path, query values and header values as arrays, raw body text, parsed JSON or null, and body byte count. Authorization, Cookie, and X-API-Key header values are redacted. Request bodies are limited to 1 MiB.",
        "responses": {
          "200": {
            "description": "Echoed request (HEAD has no response body)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds 1 MiB"
          }
        },
        "requestBody": {
          "required": false,
          "description": "Raw request body, up to 1 MiB.",
          "content": {
            "text/plain": {
              "schema": {
                "type": "string"
              }
            },
            "application/json": {
              "schema": {}
            }
          }
        }
      },
      "put": {
        "tags": [
          "http-lab"
        ],
        "summary": "Echo request details",
        "description": "Returns the request method, path, query values and header values as arrays, raw body text, parsed JSON or null, and body byte count. Authorization, Cookie, and X-API-Key header values are redacted. Request bodies are limited to 1 MiB.",
        "responses": {
          "200": {
            "description": "Echoed request (HEAD has no response body)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds 1 MiB"
          }
        },
        "requestBody": {
          "required": false,
          "description": "Raw request body, up to 1 MiB.",
          "content": {
            "text/plain": {
              "schema": {
                "type": "string"
              }
            },
            "application/json": {
              "schema": {}
            }
          }
        }
      },
      "patch": {
        "tags": [
          "http-lab"
        ],
        "summary": "Echo request details",
        "description": "Returns the request method, path, query values and header values as arrays, raw body text, parsed JSON or null, and body byte count. Authorization, Cookie, and X-API-Key header values are redacted. Request bodies are limited to 1 MiB.",
        "responses": {
          "200": {
            "description": "Echoed request (HEAD has no response body)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds 1 MiB"
          }
        },
        "requestBody": {
          "required": false,
          "description": "Raw request body, up to 1 MiB.",
          "content": {
            "text/plain": {
              "schema": {
                "type": "string"
              }
            },
            "application/json": {
              "schema": {}
            }
          }
        }
      },
      "delete": {
        "tags": [
          "http-lab"
        ],
        "summary": "Echo request details",
        "description": "Returns the request method, path, query values and header values as arrays, raw body text, parsed JSON or null, and body byte count. Authorization, Cookie, and X-API-Key header values are redacted. Request bodies are limited to 1 MiB.",
        "responses": {
          "200": {
            "description": "Echoed request (HEAD has no response body)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "413": {
            "description": "Request body exceeds 1 MiB"
          }
        }
      },
      "head": {
        "tags": [
          "http-lab"
        ],
        "summary": "Echo request details",
        "description": "Returns the request method, path, query values and header values as arrays, raw body text, parsed JSON or null, and body byte count. Authorization, Cookie, and X-API-Key header values are redacted. Request bodies are limited to 1 MiB.",
        "responses": {
          "200": {
            "description": "Echoed request (HEAD has no response body)"
          },
          "413": {
            "description": "Request body exceeds 1 MiB"
          }
        }
      }
    },
    "/lab/status/{code}": {
      "parameters": [
        {
          "name": "code",
          "in": "path",
          "required": true,
          "description": "HTTP status code to return (200\u2013599).",
          "schema": {
            "type": "integer",
            "minimum": 200,
            "maximum": 599
          }
        }
      ],
      "get": {
        "tags": [
          "http-lab"
        ],
        "summary": "Return a chosen HTTP status",
        "description": "Returns {status,message} for statuses with a body. 204, 205, and 304 have no response body. 429 includes Retry-After: 5.",
        "responses": {
          "200": {
            "description": "Requested response (its actual HTTP status is the path value; HEAD and bodyless statuses have no body)",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "default": {
            "description": "The requested status code from 200 through 599; response contains {status,message} except for 204, 205, and 304",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      },
      "head": {
        "tags": [
          "http-lab"
        ],
        "summary": "Return a chosen HTTP status",
        "description": "Returns {status,message} for statuses with a body. 204, 205, and 304 have no response body. 429 includes Retry-After: 5.",
        "responses": {
          "200": {
            "description": "Requested response (its actual HTTP status is the path value; HEAD and bodyless statuses have no body)"
          },
          "default": {
            "description": "The requested status code from 200 through 599; response contains {status,message} except for 204, 205, and 304",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/lab/delay/{ms}": {
      "parameters": [
        {
          "name": "ms",
          "in": "path",
          "required": true,
          "description": "Delay in milliseconds (0\u201310,000).",
          "schema": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10000
          }
        }
      ],
      "get": {
        "tags": [
          "http-lab"
        ],
        "summary": "Wait, then return a result",
        "description": "Wait is cancellable when the request context is canceled.",
        "responses": {
          "200": {
            "description": "Delay completed (HEAD has no response body)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LabDelay"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or out-of-range delay"
          }
        }
      },
      "head": {
        "tags": [
          "http-lab"
        ],
        "summary": "Wait, then return a result",
        "description": "Wait is cancellable when the request context is canceled.",
        "responses": {
          "200": {
            "description": "Delay completed (HEAD has no response body)"
          },
          "400": {
            "description": "Invalid or out-of-range delay"
          }
        }
      }
    },
    "/lab/redirect": {
      "get": {
        "tags": [
          "http-lab"
        ],
        "summary": "Redirect to a local path",
        "parameters": [
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Local absolute path; defaults to /lab/echo. External URLs and paths beginning with // are rejected.",
            "schema": {
              "type": "string",
              "default": "/lab/echo"
            }
          },
          {
            "name": "code",
            "in": "query",
            "required": false,
            "description": "Redirect status.",
            "schema": {
              "type": "integer",
              "enum": [
                301,
                302,
                303,
                307,
                308
              ],
              "default": 302
            }
          }
        ],
        "responses": {
          "301": {
            "description": "Redirect (when code=301)",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "302": {
            "description": "Redirect (default)",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "303": {
            "description": "Redirect (when code=303)",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "307": {
            "description": "Redirect (when code=307)",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "308": {
            "description": "Redirect (when code=308)",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid or external redirect target"
          }
        }
      },
      "head": {
        "tags": [
          "http-lab"
        ],
        "summary": "Redirect to a local path (HEAD)",
        "parameters": [
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "default": "/lab/echo"
            }
          },
          {
            "name": "code",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "enum": [
                301,
                302,
                303,
                307,
                308
              ],
              "default": 302
            }
          }
        ],
        "responses": {
          "301": {
            "description": "Redirect (when code=301)"
          },
          "302": {
            "description": "Redirect (default)"
          },
          "303": {
            "description": "Redirect (when code=303)"
          },
          "307": {
            "description": "Redirect (when code=307)"
          },
          "308": {
            "description": "Redirect (when code=308)"
          },
          "400": {
            "description": "Invalid or external redirect target"
          }
        }
      }
    },
    "/lab/cache": {
      "get": {
        "tags": [
          "http-lab"
        ],
        "summary": "Exercise conditional caching",
        "parameters": [
          {
            "name": "If-None-Match",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Matching \"small-server-v1\" or * produces 304."
          }
        ],
        "responses": {
          "200": {
            "description": "Cached response (HEAD has no body)",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string",
                  "const": "\"small-server-v1\""
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=60"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LabCached"
                }
              }
            }
          },
          "304": {
            "description": "Not modified; no response body",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string",
                  "const": "\"small-server-v1\""
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=60"
                }
              }
            }
          }
        }
      },
      "head": {
        "tags": [
          "http-lab"
        ],
        "summary": "Exercise conditional caching",
        "parameters": [
          {
            "name": "If-None-Match",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Matching \"small-server-v1\" or * produces 304."
          }
        ],
        "responses": {
          "200": {
            "description": "Cached response (HEAD has no body)",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string",
                  "const": "\"small-server-v1\""
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=60"
                }
              }
            }
          },
          "304": {
            "description": "Not modified; no response body",
            "headers": {
              "ETag": {
                "schema": {
                  "type": "string",
                  "const": "\"small-server-v1\""
                }
              },
              "Cache-Control": {
                "schema": {
                  "type": "string",
                  "const": "public, max-age=60"
                }
              }
            }
          }
        }
      }
    },
    "/secure/uploads/status": {
      "get": {
        "tags": [
          "uploads"
        ],
        "summary": "Check R2 upload configuration",
        "responses": {
          "200": {
            "description": "Configuration status; never returns credentials",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadStatus"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key"
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      }
    },
    "/secure/uploads": {
      "get": {
        "tags": [
          "uploads"
        ],
        "summary": "List uploaded files",
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "description": "Opaque pagination cursor, at most 2048 bytes.",
            "schema": {
              "type": "string",
              "maxLength": 2048
            }
          }
        ],
        "responses": {
          "200": {
            "description": "At most 100 files from the application uploads/ prefix",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadList"
                }
              }
            }
          },
          "400": {
            "description": "Invalid cursor"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "502": {
            "description": "Storage request failed"
          },
          "503": {
            "description": "R2 is not configured"
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      },
      "post": {
        "tags": [
          "uploads"
        ],
        "summary": "Upload a file",
        "description": "Send raw binary bytes (not multipart/form-data). Body must be nonempty and no larger than 10 MiB. The browser UI normalizes selected filenames to the allowed ASCII format; API callers must send a valid filename. Filename must begin with an ASCII letter or digit and contain only ASCII letters, digits, dot, underscore, or hyphen; maximum 128 characters. Object keys are generated as random 32 lowercase hex characters, a hyphen, then the filename.",
        "parameters": [
          {
            "name": "filename",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128,
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Raw binary bytes. Do not use multipart/form-data.",
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary",
                "maxLength": 10485760
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "File stored under the private uploads/ prefix",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadCreated"
                }
              }
            }
          },
          "400": {
            "description": "Empty body or invalid filename"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "413": {
            "description": "File exceeds 10 MiB"
          },
          "502": {
            "description": "Storage request failed"
          },
          "503": {
            "description": "R2 is not configured"
          },
          "429": {
            "description": "Four uploads are already in progress",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "string",
                  "const": "1"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      }
    },
    "/secure/uploads/{key}": {
      "parameters": [
        {
          "name": "key",
          "in": "path",
          "required": true,
          "description": "Object key in the application uploads/ prefix: 32 lowercase hex characters, a hyphen, and a valid filename. Keys outside this format or prefix are inaccessible.",
          "schema": {
            "type": "string",
            "pattern": "^[0-9a-f]{32}-[A-Za-z0-9][A-Za-z0-9._-]{0,127}$"
          }
        }
      ],
      "get": {
        "tags": [
          "uploads"
        ],
        "summary": "Download a file",
        "responses": {
          "200": {
            "description": "File attachment",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Invalid key"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "404": {
            "description": "File not found"
          },
          "502": {
            "description": "Storage request failed"
          },
          "503": {
            "description": "R2 is not configured"
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      },
      "head": {
        "tags": [
          "uploads"
        ],
        "summary": "Inspect a file without downloading it",
        "responses": {
          "200": {
            "description": "File metadata headers"
          },
          "400": {
            "description": "Invalid key"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "404": {
            "description": "File not found"
          },
          "502": {
            "description": "Storage request failed"
          },
          "503": {
            "description": "R2 is not configured"
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      },
      "delete": {
        "tags": [
          "uploads"
        ],
        "summary": "Delete a file",
        "description": "Idempotent: deleting a missing file also succeeds.",
        "responses": {
          "204": {
            "description": "Deleted or already absent"
          },
          "400": {
            "description": "Invalid key"
          },
          "401": {
            "description": "Missing or invalid API key"
          },
          "502": {
            "description": "Storage request failed"
          },
          "503": {
            "description": "R2 is not configured"
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ]
      }
    },
    "/secure/gateways/crm": {
      "post": {
        "tags": [
          "Claire mock gateways"
        ],
        "summary": "Test crm gateway",
        "description": "Operations: create_record (fields), find_record (match), update_record (record_id, fields), add_note (record_id, note). record_type: contact, company, deal, case, custom. Returns root id/name for body.id/body.name mappings. Mock only, no real provider. Shared persistent SQLite data. Responses include mock:true. Body/record max 64 KiB; dataset max 1000 records. Successful Idempotency-Key requests replay after restart; changed input with same key returns 409.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 256
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "operation": "create_record",
                "record_type": "contact",
                "fields": {
                  "name": "Test customer",
                  "email": "test@example.com"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Overlap, full dataset, or idempotency conflict"
          },
          "413": {
            "description": "Too large"
          },
          "500": {
            "description": "Database error"
          }
        }
      }
    },
    "/secure/gateways/calendar": {
      "post": {
        "tags": [
          "Claire mock gateways"
        ],
        "summary": "Test calendar gateway",
        "description": "Operations: check_availability, create_booking, reschedule_booking, cancel_booking. calendar_id/timezone required. RFC3339 start_at/end_at required except cancel. reschedule/cancel require event_id. Create requires title/attendee_email. Overlaps return 409. Mock only, no real provider. Shared persistent SQLite data. Responses include mock:true. Body/record max 64 KiB; dataset max 1000 records. Successful Idempotency-Key requests replay after restart; changed input with same key returns 409.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 256
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "operation": "create_booking",
                "calendar_id": "demo",
                "timezone": "UTC",
                "start_at": "2030-01-10T10:00:00Z",
                "end_at": "2030-01-10T10:30:00Z",
                "title": "Test appointment",
                "attendee_email": "test@example.com"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Overlap, full dataset, or idempotency conflict"
          },
          "413": {
            "description": "Too large"
          },
          "500": {
            "description": "Database error"
          }
        }
      }
    },
    "/secure/gateways/business": {
      "post": {
        "tags": [
          "Claire mock gateways"
        ],
        "summary": "Test business gateway",
        "description": "Stores a mock accepted request. operation is a lowercase identifier; description required; inputs is an object. Mock only, no real provider. Shared persistent SQLite data. Responses include mock:true. Body/record max 64 KiB; dataset max 1000 records. Successful Idempotency-Key requests replay after restart; changed input with same key returns 409.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 256
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "operation": "create_ticket",
                "description": "Test support request",
                "inputs": {
                  "subject": "Demo"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Overlap, full dataset, or idempotency conflict"
          },
          "413": {
            "description": "Too large"
          },
          "500": {
            "description": "Database error"
          }
        }
      }
    },
    "/secure/gateways/database": {
      "post": {
        "tags": [
          "Claire mock gateways"
        ],
        "summary": "Test database gateway",
        "description": "Operations: read, create, update, delete. resource is a lowercase sandbox identifier, not SQL. Flat equality filters; values required for create/update; nonempty filters required for update/delete; read limit 1\u2013100 (default 10). Mock only, no real provider. Shared persistent SQLite data. Responses include mock:true. Body/record max 64 KiB; dataset max 1000 records. Successful Idempotency-Key requests replay after restart; changed input with same key returns 409.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 256
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "operation": "create",
                "resource": "customers",
                "values": {
                  "name": "Test customer",
                  "active": true
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Overlap, full dataset, or idempotency conflict"
          },
          "413": {
            "description": "Too large"
          },
          "500": {
            "description": "Database error"
          }
        }
      }
    },
    "/secure/gateways/voice": {
      "post": {
        "tags": [
          "Claire mock gateways"
        ],
        "summary": "Test voice gateway",
        "description": "analysis: summary, sentiment, intent, quality, custom. transcript/language required; instructions required for quality/custom. Simulated text output; no AI/audio provider or timestamps. Mock only, no real provider. Shared persistent SQLite data. Responses include mock:true. Body/record max 64 KiB; dataset max 1000 records. Successful Idempotency-Key requests replay after restart; changed input with same key returns 409.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 256
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              },
              "example": {
                "analysis": "summary",
                "transcript": "Hello, I would like to book an appointment.",
                "language": "en"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success"
          },
          "201": {
            "description": "Created"
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "Invalid key"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Overlap, full dataset, or idempotency conflict"
          },
          "413": {
            "description": "Too large"
          },
          "500": {
            "description": "Database error"
          }
        }
      }
    }
  }
}
