{
  "openapi": "3.0.3",
  "info": {
    "title": "dol.ink Public API",
    "version": "0.1.0-dev.19"
  },
  "servers": [
    {
      "url": "https://dol.ink"
    }
  ],
  "paths": {
    "/api/links": {
      "post": {
        "summary": "Create a short link without authentication",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "maxLength": 4096
                  },
                  "expiresIn": {
                    "type": "string",
                    "enum": [
                      "1h",
                      "1d",
                      "7d",
                      "30d"
                    ],
                    "default": "7d"
                  },
                  "code": {
                    "type": "string",
                    "pattern": "^[a-zA-Z0-9_-]{3,32}$"
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 120
                  },
                  "password": {
                    "type": "string",
                    "minLength": 4,
                    "maxLength": 128,
                    "writeOnly": true,
                    "description": "Optional access password; leave empty for no password."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "400": {
            "description": "Invalid input"
          },
          "409": {
            "description": "Code conflict"
          },
          "413": {
            "description": "Request exceeds 8 KiB"
          },
          "503": {
            "description": "Service unavailable"
          },
          "201": {
            "description": "Created. data.quota contains limit, remaining and resetAt. X-RateLimit-Limit/Remaining/Reset headers report the same daily quota.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "required": [
                        "code",
                        "url",
                        "shortUrl"
                      ],
                      "properties": {
                        "code": {
                          "type": "string"
                        },
                        "url": {
                          "type": "string",
                          "format": "uri"
                        },
                        "shortUrl": {
                          "type": "string",
                          "format": "uri"
                        },
                        "expires_at": {
                          "type": "string",
                          "format": "date-time",
                          "nullable": true
                        },
                        "active": {
                          "type": "boolean"
                        },
                        "clicks": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Daily creation quota exhausted. Retry-After is seconds until midnight Asia/Shanghai.",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer",
                  "enum": [
                    0
                  ]
                }
              },
              "X-RateLimit-Reset": {
                "schema": {
                  "type": "integer"
                },
                "description": "Reset Unix timestamp in seconds"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    },
                    "quota": {
                      "type": "object",
                      "properties": {
                        "limit": {
                          "type": "integer",
                          "enum": [
                            100
                          ]
                        },
                        "remaining": {
                          "type": "integer"
                        },
                        "resetAt": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "description": "Up to 100 successful creations per IP per calendar day (Asia/Shanghai), shared with the internal creation API. Deleting links does not refund quota."
      }
    },
    "/api/links/{code}/unlock": {
      "post": {
        "summary": "Verify an access password and set a long-lived HttpOnly access cookie",
        "security": [],
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "password"
                ],
                "properties": {
                  "password": {
                    "type": "string",
                    "maxLength": 128,
                    "writeOnly": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password accepted; sets a cookie and returns shortUrl"
          },
          "401": {
            "description": "Incorrect password"
          },
          "404": {
            "description": "Link unavailable"
          },
          "429": {
            "description": "More than 10 attempts in 10 minutes"
          }
        }
      }
    }
  }
}
