{
  "openapi": "3.1.0",
  "info": {
    "title": "generated.directory",
    "version": "1.0.0",
    "summary": "Account and publish API for static sites at generated.directory/user/app."
  },
  "servers": [{ "url": "https://upload.generated.directory" }],
  "components": {
    "securitySchemes": {
      "bearer": { "type": "http", "scheme": "bearer" }
    }
  },
  "paths": {
    "/v1/accounts": {
      "post": {
        "operationId": "createAccount",
        "summary": "Create an account and return a bearer token.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username", "password"],
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "201": { "description": "Account created. Body is { username, token }." },
          "400": { "description": "Username or password rejected." },
          "409": { "description": "Username is taken." }
        }
      }
    },
    "/v1/sessions": {
      "post": {
        "operationId": "createSession",
        "summary": "Sign in and return a bearer token.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["username", "password"],
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Signed in. Body is { username, token }." },
          "401": { "description": "Username or password is wrong." }
        }
      }
    },
    "/v1/me": {
      "get": {
        "operationId": "me",
        "security": [{ "bearer": [] }],
        "summary": "Return the signed-in username.",
        "responses": {
          "200": { "description": "Body is { username }." },
          "401": { "description": "Missing or unknown token." }
        }
      }
    },
    "/v1/apps": {
      "get": {
        "operationId": "listApps",
        "security": [{ "bearer": [] }],
        "summary": "List the signed-in user's apps.",
        "responses": {
          "200": { "description": "Body is { apps: [{ slug, title, updatedAt, url }] }." },
          "401": { "description": "Missing or unknown token." }
        }
      }
    },
    "/v1/apps/{slug}/deploys": {
      "post": {
        "operationId": "startDeploy",
        "security": [{ "bearer": [] }],
        "summary": "Start a publish. Send hashes; the response lists hashes that still need bytes.",
        "parameters": [{ "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["files"],
                "properties": {
                  "title": { "type": "string" },
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": ["path", "hash", "size"],
                      "properties": {
                        "path": { "type": "string" },
                        "hash": { "type": "string", "description": "32 hex characters: SHA-256 of base64(file) plus the file extension, truncated." },
                        "size": { "type": "integer" }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Body is { deployId, missing }." },
          "400": { "description": "Invalid app name, path, or size." },
          "401": { "description": "Missing or unknown token." },
          "409": { "description": "Another publish is in progress." }
        }
      }
    },
    "/v1/apps/{slug}/deploys/{deployId}": {
      "put": {
        "operationId": "uploadFile",
        "security": [{ "bearer": [] }],
        "summary": "Upload one missing file. Pass its hash as the hash query parameter. The body is the raw file.",
        "parameters": [
          { "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "deployId", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "hash", "in": "query", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": { "application/octet-stream": { "schema": { "type": "string", "format": "binary" } } }
        },
        "responses": {
          "200": { "description": "Body is { received, remaining }." },
          "400": { "description": "Hash or size does not match." },
          "401": { "description": "Missing or unknown token." }
        }
      }
    },
    "/v1/apps/{slug}/deploys/{deployId}/commit": {
      "post": {
        "operationId": "commitDeploy",
        "security": [{ "bearer": [] }],
        "summary": "Publish the app at generated.directory/user/slug/.",
        "parameters": [
          { "name": "slug", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "deployId", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": { "title": { "type": "string" } }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Body is { url, slug, updatedAt }." },
          "400": { "description": "Files are still missing." },
          "401": { "description": "Missing or unknown token." }
        }
      }
    }
  }
}
