{
    "openapi": "3.1.0",
    "info": {
        "title": "URLino REST API",
        "version": "1.0.0",
        "description": "Kurzlinks automatisiert erstellen, verwalten und auswerten.\n\nAuthentifizierung: persönlicher API-Schlüssel als Bearer-Token (`Authorization: Bearer urlino_live_<key_id>_<secret>`). Schlüssel werden im Dashboard unter /api-keys erstellt.\n\nKontingente (Free, konfigurierbar): 100.000 Aufrufe/Monat, 10.000 neue Links/Monat (UTC-Kalendermonat, authentifizierte Anfragen inkl. Fehler), 120 Aufrufe/Minute, 10 aktive Schlüssel. Alle Schlüssel eines Benutzers teilen sich das Kontingent. `X-RateLimit-*` beschreibt das Monatskontingent der Aufrufe, `X-RateLimit-Minute-*` das Minutenlimit. Bei 429 liefert `Retry-After` die Wartezeit in Sekunden."
    },
    "servers": [
        {
            "url": "https://urlino.de/api/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "paths": {
        "/links": {
            "post": {
                "operationId": "createLink",
                "summary": "Kurzlink erstellen",
                "description": "Scope `links:write`. Nur http(s)-Ziele; Blacklist, Domainlimits und URL-Prüfung wie im Web-Dashboard. Optionaler Header `Idempotency-Key` (1–64 Zeichen, 24 h): Wiederholung mit gleichem Inhalt liefert denselben Link (Header `Idempotency-Replayed: true`), mit anderem Inhalt 409.",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "required": false,
                        "schema": {
                            "type": "string",
                            "pattern": "^[A-Za-z0-9_.:-]{1,64}$"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "url"
                                ],
                                "additionalProperties": false,
                                "properties": {
                                    "url": {
                                        "type": "string",
                                        "maxLength": 2048,
                                        "examples": [
                                            "https://draeger-it.blog/"
                                        ]
                                    },
                                    "expires_at": {
                                        "type": [
                                            "string",
                                            "null"
                                        ],
                                        "format": "date-time",
                                        "description": "Optional, in der Zukunft, höchstens 10 Jahre."
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Erstellt",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Link"
                                }
                            }
                        }
                    },
                    "400": {
                        "$ref": "#/components/responses/Error"
                    },
                    "401": {
                        "$ref": "#/components/responses/Error"
                    },
                    "403": {
                        "$ref": "#/components/responses/Error"
                    },
                    "409": {
                        "$ref": "#/components/responses/Error"
                    },
                    "413": {
                        "$ref": "#/components/responses/Error"
                    },
                    "429": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            },
            "get": {
                "operationId": "listLinks",
                "summary": "Eigene Links auflisten",
                "description": "Scope `links:read`. Das Feld `clicks` wird nur mit zusätzlichem Scope `stats:read` ausgeliefert.",
                "parameters": [
                    {
                        "name": "limit",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 100,
                            "default": 20
                        }
                    },
                    {
                        "name": "offset",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "minimum": 0,
                            "default": 0
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Link"
                                            }
                                        },
                                        "pagination": {
                                            "type": "object",
                                            "properties": {
                                                "limit": {
                                                    "type": "integer"
                                                },
                                                "offset": {
                                                    "type": "integer"
                                                },
                                                "total": {
                                                    "type": "integer"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "$ref": "#/components/responses/Error"
                    },
                    "401": {
                        "$ref": "#/components/responses/Error"
                    },
                    "403": {
                        "$ref": "#/components/responses/Error"
                    },
                    "429": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            }
        },
        "/links/{id}": {
            "parameters": [
                {
                    "name": "id",
                    "in": "path",
                    "required": true,
                    "schema": {
                        "type": "string",
                        "pattern": "^[0-9A-Za-z]{5,12}$"
                    }
                }
            ],
            "get": {
                "operationId": "getLink",
                "summary": "Linkdetails abrufen",
                "description": "Scope `links:read`. Fremde oder unbekannte Links liefern 404.",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Link"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Error"
                    },
                    "403": {
                        "$ref": "#/components/responses/Error"
                    },
                    "404": {
                        "$ref": "#/components/responses/Error"
                    },
                    "429": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            },
            "delete": {
                "operationId": "deleteLink",
                "summary": "Eigenen Link löschen",
                "description": "Scope `links:delete`. Der Kurzcode wird nie wieder vergeben.",
                "responses": {
                    "204": {
                        "description": "Gelöscht"
                    },
                    "401": {
                        "$ref": "#/components/responses/Error"
                    },
                    "403": {
                        "$ref": "#/components/responses/Error"
                    },
                    "404": {
                        "$ref": "#/components/responses/Error"
                    },
                    "429": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            }
        },
        "/links/{id}/stats": {
            "parameters": [
                {
                    "name": "id",
                    "in": "path",
                    "required": true,
                    "schema": {
                        "type": "string",
                        "pattern": "^[0-9A-Za-z]{5,12}$"
                    }
                }
            ],
            "get": {
                "operationId": "getLinkStats",
                "summary": "Klickstatistik eines Links abrufen",
                "description": "Scope `stats:read`. Datenschutz wie auf der Statistikseite: Einzelwerte erst ab `privacy.min_group` Klicks (sonst in `other`), `timeseries` ist `null`, solange im Zeitraum weniger als `privacy.min_total_for_timeseries` Klicks vorliegen.",
                "parameters": [
                    {
                        "name": "days",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "enum": [
                                7,
                                30,
                                90,
                                0
                            ],
                            "default": 30
                        },
                        "description": "Zeitraum in Tagen; 0 = seit Erstellung des Links"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/LinkStats"
                                }
                            }
                        }
                    },
                    "400": {
                        "$ref": "#/components/responses/Error"
                    },
                    "401": {
                        "$ref": "#/components/responses/Error"
                    },
                    "403": {
                        "$ref": "#/components/responses/Error"
                    },
                    "404": {
                        "$ref": "#/components/responses/Error"
                    },
                    "429": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            }
        },
        "/usage": {
            "get": {
                "operationId": "getUsage",
                "summary": "Kontingente abrufen",
                "description": "Scope `usage:read`.",
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Usage"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#/components/responses/Error"
                    },
                    "403": {
                        "$ref": "#/components/responses/Error"
                    },
                    "429": {
                        "$ref": "#/components/responses/Error"
                    }
                }
            }
        }
    },
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer",
                "description": "urlino_live_<key_id>_<secret>"
            }
        },
        "schemas": {
            "Link": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string",
                        "examples": [
                            "aB3xY7k"
                        ]
                    },
                    "short_url": {
                        "type": "string",
                        "format": "uri"
                    },
                    "original_url": {
                        "type": "string",
                        "format": "uri"
                    },
                    "clicks": {
                        "type": "integer",
                        "description": "Nur mit Scope stats:read"
                    },
                    "created_at": {
                        "type": "string",
                        "format": "date-time"
                    },
                    "expires_at": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time"
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "active",
                            "expired",
                            "disabled"
                        ]
                    }
                }
            },
            "Quota": {
                "type": "object",
                "properties": {
                    "limit": {
                        "type": "integer"
                    },
                    "used": {
                        "type": "integer"
                    },
                    "remaining": {
                        "type": "integer"
                    },
                    "resets_at": {
                        "type": "string",
                        "format": "date-time"
                    }
                }
            },
            "Usage": {
                "type": "object",
                "properties": {
                    "period": {
                        "type": "object",
                        "properties": {
                            "type": {
                                "const": "month"
                            },
                            "timezone": {
                                "const": "UTC"
                            },
                            "month": {
                                "type": "string"
                            },
                            "resets_at": {
                                "type": "string",
                                "format": "date-time"
                            }
                        }
                    },
                    "requests": {
                        "$ref": "#/components/schemas/Quota"
                    },
                    "links_created": {
                        "$ref": "#/components/schemas/Quota"
                    },
                    "rate_limit_per_minute": {
                        "type": "object",
                        "properties": {
                            "limit": {
                                "type": "integer"
                            }
                        }
                    },
                    "api_keys": {
                        "type": "object",
                        "properties": {
                            "active": {
                                "type": "integer"
                            },
                            "max": {
                                "type": "integer"
                            }
                        }
                    }
                }
            },
            "Breakdown": {
                "type": "object",
                "properties": {
                    "items": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "value": {
                                    "type": "string"
                                },
                                "clicks": {
                                    "type": "integer"
                                }
                            }
                        }
                    },
                    "other": {
                        "type": "integer",
                        "description": "Klicks von Werten unterhalb der Datenschutz-Schwelle"
                    }
                }
            },
            "LinkStats": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "period": {
                        "type": "object",
                        "properties": {
                            "days": {
                                "type": "integer"
                            },
                            "from": {
                                "type": "string",
                                "format": "date"
                            },
                            "to": {
                                "type": "string",
                                "format": "date"
                            },
                            "timezone": {
                                "type": "string"
                            }
                        }
                    },
                    "clicks": {
                        "type": "object",
                        "properties": {
                            "total": {
                                "type": "integer"
                            },
                            "period": {
                                "type": "integer"
                            },
                            "today": {
                                "type": "integer"
                            }
                        }
                    },
                    "privacy": {
                        "type": "object",
                        "properties": {
                            "min_group": {
                                "type": "integer"
                            },
                            "min_total_for_timeseries": {
                                "type": "integer"
                            }
                        }
                    },
                    "timeseries": {
                        "type": [
                            "array",
                            "null"
                        ],
                        "items": {
                            "type": "object",
                            "properties": {
                                "date": {
                                    "type": "string",
                                    "format": "date"
                                },
                                "clicks": {
                                    "type": "integer"
                                }
                            }
                        }
                    },
                    "referrers": {
                        "$ref": "#/components/schemas/Breakdown"
                    },
                    "countries": {
                        "$ref": "#/components/schemas/Breakdown"
                    },
                    "devices": {
                        "$ref": "#/components/schemas/Breakdown"
                    },
                    "browsers": {
                        "$ref": "#/components/schemas/Breakdown"
                    },
                    "operating_systems": {
                        "$ref": "#/components/schemas/Breakdown"
                    },
                    "languages": {
                        "$ref": "#/components/schemas/Breakdown"
                    }
                }
            },
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string",
                                "enum": [
                                    "INVALID_URL",
                                    "INVALID_REQUEST",
                                    "INVALID_API_KEY",
                                    "INSUFFICIENT_PERMISSIONS",
                                    "DOMAIN_BLOCKED",
                                    "LINK_NOT_FOUND",
                                    "NOT_FOUND",
                                    "METHOD_NOT_ALLOWED",
                                    "CONFLICT",
                                    "PAYLOAD_TOO_LARGE",
                                    "RATE_LIMIT_EXCEEDED",
                                    "MONTHLY_QUOTA_EXCEEDED",
                                    "DOMAIN_LIMIT_EXCEEDED",
                                    "INTERNAL_SERVER_ERROR",
                                    "SERVICE_UNAVAILABLE"
                                ]
                            },
                            "message": {
                                "type": "string"
                            },
                            "request_id": {
                                "type": "string"
                            }
                        }
                    }
                }
            }
        },
        "responses": {
            "Error": {
                "description": "Fehler",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Error"
                        }
                    }
                }
            }
        }
    }
}