{
  "openapi": "3.1.0",
  "info": {
    "title": "heissa.de KI-Subdomains",
    "version": "1.0.0",
    "description": "Lets a person's AI request a free subdomain {name}.heissa.de and upload a static website (HTML, CSS, images; no JavaScript).\n\nWorkflow: 1) check the name with GET /names/{sub}, 2) POST /sites, 3) PUT each file into the draft, 4) look at preview_url, 5) POST /sites/{sub}/submit. A member of the heissa gUG team reviews the preview and approves it; only then is the site live and listed in https://heissa.de/sitemap.php. Later changes go into a new draft and need approval again; the approved version stays online meanwhile.\n\nNothing can be deleted through this API, names are never reassigned and every version is kept. Authentication: a personal token from https://heissa.de/ki/ (Google login) as 'Authorization: Bearer hki_...'. Guide in German: https://heissa.de/apihowto.php",
    "contact": { "name": "heissa.de", "url": "https://heissa.de/apihowto.php" }
  },
  "servers": [{ "url": "https://heissa.de/api/v1" }],
  "security": [{ "bearer": [] }],
  "tags": [
    { "name": "Names", "description": "Check whether a subdomain is free (no token needed)." },
    { "name": "Sites", "description": "Your own subdomains." },
    { "name": "Draft", "description": "The open draft revision: upload files, set title." },
    { "name": "Review", "description": "Hand a draft to the heissa gUG team for approval." }
  ],
  "paths": {
    "/": {
      "get": {
        "tags": ["Names"], "summary": "Service info and links", "operationId": "info", "security": [],
        "responses": { "200": { "description": "Links to spec, docs and token page", "content": { "application/json": { "schema": { "type": "object" } } } } }
      }
    },
    "/names/{sub}": {
      "get": {
        "tags": ["Names"], "summary": "Is <sub>.heissa.de available?", "operationId": "checkName", "security": [],
        "parameters": [{ "$ref": "#/components/parameters/sub" }],
        "responses": { "200": { "description": "Result", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NameCheck" } } } } }
      }
    },
    "/me": {
      "get": {
        "tags": ["Sites"], "summary": "Who am I, limits and allowed file types", "operationId": "me",
        "responses": {
          "200": { "description": "Account", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Me" } } } },
          "401": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/sites": {
      "get": {
        "tags": ["Sites"], "summary": "List my subdomains", "operationId": "listSites",
        "responses": { "200": { "description": "My sites", "content": { "application/json": { "schema": { "type": "object", "properties": { "sites": { "type": "array", "items": { "$ref": "#/components/schemas/Site" } } } } } } } }
      },
      "post": {
        "tags": ["Sites"], "summary": "Reserve a subdomain and open draft revision 1", "operationId": "createSite",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "$ref": "#/components/schemas/NewSite" } } } },
        "responses": {
          "201": { "description": "Created", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Site" } } } },
          "403": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/sites/{sub}": {
      "get": {
        "tags": ["Sites"], "summary": "Status of one of my subdomains incl. all revisions and review notes", "operationId": "getSite",
        "parameters": [{ "$ref": "#/components/parameters/sub" }],
        "responses": {
          "200": { "description": "Site", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Site" } } } },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/sites/{sub}/draft": {
      "get": {
        "tags": ["Draft"], "summary": "Show the open draft and its files", "operationId": "getDraft",
        "parameters": [{ "$ref": "#/components/parameters/sub" }],
        "responses": {
          "200": { "description": "Draft", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Revision" } } } },
          "404": { "$ref": "#/components/responses/Error" }
        }
      },
      "patch": {
        "tags": ["Draft"], "summary": "Set title / description (shown in the sitemap after approval)", "operationId": "patchDraft",
        "description": "Opens a new draft (copy of the newest revision) if none is open.",
        "parameters": [{ "$ref": "#/components/parameters/sub" }],
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "title": { "type": "string", "maxLength": 120 }, "description": { "type": "string", "maxLength": 500 } } } } } },
        "responses": { "200": { "description": "Draft", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Revision" } } } } }
      }
    },
    "/sites/{sub}/draft/files/{path}": {
      "put": {
        "tags": ["Draft"], "summary": "Upload one file into the draft", "operationId": "putFile",
        "description": "Opens a new draft (copy of the newest revision) if none is open. Uploading the same path again replaces it inside the draft; earlier content stays stored. Send the raw bytes, or JSON {\"text\": \"...\"} for text files, or JSON {\"base64\": \"...\"} for images. Allowed: html htm css txt png jpg jpeg gif webp avif svg ico pdf woff2. No JavaScript, no event handlers, no iframe/form. The only script allowed is <script src=\"https://heissa.de/assets/bootstrap.bundle.min.js\"></script>; Bootstrap CSS: https://heissa.de/assets/bootstrap.min.css. Use relative links (e.g. href=\"kontakt.html\", src=\"img/logo.png\").",
        "parameters": [
          { "$ref": "#/components/parameters/sub" },
          { "name": "path", "in": "path", "required": true, "description": "e.g. index.html, style.css, img/logo.png (up to 4 levels)", "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "oneOf": [
              { "type": "object", "required": ["text"], "properties": { "text": { "type": "string" } } },
              { "type": "object", "required": ["base64"], "properties": { "base64": { "type": "string", "contentEncoding": "base64" } } }
            ] } },
            "text/html": { "schema": { "type": "string" } },
            "text/css": { "schema": { "type": "string" } },
            "application/octet-stream": { "schema": { "type": "string", "format": "binary" } }
          }
        },
        "responses": {
          "200": { "description": "Replaced in draft", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Upload" } } } },
          "201": { "description": "Added to draft", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Upload" } } } },
          "400": { "$ref": "#/components/responses/Error" },
          "413": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/sites/{sub}/revisions/{rev}/files/{path}": {
      "get": {
        "tags": ["Draft"], "summary": "Download a file of any of my revisions", "operationId": "getFile",
        "parameters": [
          { "$ref": "#/components/parameters/sub" },
          { "name": "rev", "in": "path", "required": true, "schema": { "type": "integer", "minimum": 1 } },
          { "name": "path", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": { "200": { "description": "File content", "content": { "application/octet-stream": { "schema": { "type": "string", "format": "binary" } } } }, "404": { "$ref": "#/components/responses/Error" } }
      }
    },
    "/sites/{sub}/submit": {
      "post": {
        "tags": ["Review"], "summary": "Submit the draft for approval by the heissa gUG team", "operationId": "submit",
        "description": "Needs an index.html. The team gets an e-mail. Poll GET /sites/{sub}: state becomes 'approved' (live) or 'rejected' (see review_note; fix in a new draft and submit again).",
        "parameters": [{ "$ref": "#/components/parameters/sub" }],
        "requestBody": { "required": false, "content": { "application/json": { "schema": { "type": "object", "properties": { "note": { "type": "string", "maxLength": 1000, "description": "Message to the reviewer" } } } } } },
        "responses": {
          "200": { "description": "Submitted", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Revision" } } } },
          "409": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": { "type": "http", "scheme": "bearer", "description": "Personal token hki_... from https://heissa.de/ki/" }
    },
    "parameters": {
      "sub": { "name": "sub", "in": "path", "required": true, "description": "Subdomain without .heissa.de: 3-32 chars, a-z 0-9 and '-'", "schema": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]{1,30}[a-z0-9]$" } }
    },
    "responses": {
      "Error": { "description": "Error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    },
    "schemas": {
      "Error": { "type": "object", "properties": { "error": { "type": "string" }, "message": { "type": "string", "description": "German, meant to be shown to the person" } } },
      "NameCheck": { "type": "object", "properties": { "sub": { "type": "string" }, "host": { "type": "string" }, "available": { "type": "boolean" }, "reason": { "type": ["string", "null"], "enum": ["invalid", "reserved", "taken", null] }, "message": { "type": "string" } } },
      "Me": { "type": "object", "properties": { "email": { "type": "string" }, "name": { "type": "string" }, "sites": { "type": "integer" }, "limits": { "type": "object" }, "allowed_types": { "type": "array", "items": { "type": "string" } } } },
      "NewSite": { "type": "object", "required": ["sub", "title"], "properties": { "sub": { "type": "string", "example": "baeckerei-muster" }, "title": { "type": "string", "maxLength": 120, "example": "Bäckerei Muster, Lenggries" }, "description": { "type": "string", "maxLength": 500 } } },
      "Site": { "type": "object", "properties": {
        "sub": { "type": "string" }, "host": { "type": "string" },
        "live_rev": { "type": ["integer", "null"], "description": "Approved revision currently online" },
        "live_url": { "type": ["string", "null"] }, "blocked": { "type": "boolean" }, "created_at": { "type": "string" },
        "revisions": { "type": "array", "items": { "$ref": "#/components/schemas/Revision" } } } },
      "Revision": { "type": "object", "properties": {
        "rev": { "type": "integer" },
        "state": { "type": "string", "enum": ["draft", "submitted", "approved", "rejected", "superseded"] },
        "title": { "type": "string" }, "description": { "type": "string" },
        "created_at": { "type": "string" }, "submitted_at": { "type": ["string", "null"] }, "reviewed_at": { "type": ["string", "null"] },
        "review_note": { "type": ["string", "null"], "description": "Reviewer's note, e.g. why it was rejected" },
        "preview_url": { "type": "string", "description": "Private preview (not indexed); share only with the person" },
        "files": { "type": "array", "items": { "type": "object", "properties": { "path": { "type": "string" }, "size": { "type": "integer" }, "sha256": { "type": "string" }, "uploaded_at": { "type": "string" } } } },
        "total_bytes": { "type": "integer" } } },
      "Upload": { "type": "object", "properties": { "rev": { "type": "integer" }, "path": { "type": "string" }, "size": { "type": "integer" }, "sha256": { "type": "string" }, "preview_url": { "type": "string" } } }
    }
  }
}
