{
  "openapi": "3.1.0",
  "info": {
    "title": "1.vu OneLink API",
    "description": "Free URL shortener on the shortest domain on Earth. No key required for normal use. See https://1.vu/llms.txt.",
    "version": "1.0.0"
  },
  "servers": [{ "url": "https://1.vu" }],
  "paths": {
    "/api/link": {
      "post": {
        "summary": "Create a short link",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url", "accept_terms"],
                "properties": {
                  "url": { "type": "string", "maxLength": 2048, "description": "http/https URL with a public DNS hostname" },
                  "slug": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]{2,38}[a-z0-9]$", "description": "optional custom name" },
                  "accept_terms": { "type": "boolean", "enum": [true], "description": "required — accepts https://1.vu/terms and https://1.vu/privacy" }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Link" } } }
          },
          "422": { "$ref": "#/components/responses/Error" },
          "409": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/api/link/{code}": {
      "get": {
        "summary": "Link metadata",
        "parameters": [{ "$ref": "#/components/parameters/code" }],
        "responses": {
          "200": { "description": "OK" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      },
      "delete": {
        "summary": "Delete a link (requires secret)",
        "parameters": [
          { "$ref": "#/components/parameters/code" },
          { "name": "k", "in": "query", "required": true, "schema": { "type": "string" }, "description": "secret returned at creation" }
        ],
        "responses": {
          "200": { "description": "Deleted" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/api/resolve/{code}": {
      "get": {
        "summary": "Expand a short link without following it",
        "parameters": [{ "$ref": "#/components/parameters/code" }],
        "responses": {
          "200": { "description": "OK" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/api/stats/{code}": {
      "get": {
        "summary": "Click statistics (requires secret)",
        "parameters": [
          { "$ref": "#/components/parameters/code" },
          { "name": "k", "in": "query", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "OK" },
          "403": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/api/health": {
      "get": { "summary": "Health check", "responses": { "200": { "description": "OK" } } }
    },
    "/{code}": {
      "get": {
        "summary": "Follow a short link",
        "parameters": [{ "$ref": "#/components/parameters/code" }],
        "responses": { "302": { "description": "Redirect to destination" }, "404": { "$ref": "#/components/responses/Error" } }
      }
    }
  },
  "components": {
    "parameters": {
      "code": { "name": "code", "in": "path", "required": true, "schema": { "type": "string", "pattern": "^[a-zA-Z0-9-]{4,40}$" } }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": { "type": "object", "properties": { "error": { "type": "object", "properties": { "code": { "type": "string" }, "message": { "type": "string" } } } } }
          }
        }
      }
    },
    "schemas": {
      "Link": {
        "type": "object",
        "properties": {
          "short_url": { "type": "string", "format": "uri" },
          "code": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "secret": { "type": "string" },
          "stats_url": { "type": "string", "format": "uri" },
          "preview_url": { "type": "string", "format": "uri" },
          "created_at": { "type": "integer" }
        }
      }
    }
  }
}
