{
  "openapi": "3.1.0",
  "info": {
    "title": "Rhino Drive Public API",
    "version": "2026-07-01",
    "description": "API specification for the Rhino Drive cloud storage service."
  },
  "servers": [
    {
      "url": "https://api-drive.rhinoc.ru/v1",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "summary": "Get the current account",
        "operationId": "getCurrentAccount",
        "responses": {
          "200": {
            "description": "Account profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                }
              }
            }
          }
        }
      }
    },
    "/files": {
      "get": {
        "summary": "List files",
        "operationId": "listFiles",
        "parameters": [
          {
            "name": "parent_id",
            "in": "query",
            "schema": {
              "type": ["string", "null"]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": ["string", "null"]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated file list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": ["items"],
                  "properties": {
                    "items": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/File"
                      }
                    },
                    "next_cursor": {
                      "type": ["string", "null"]
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Create an upload",
        "operationId": "createUpload",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["name", "size"],
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "size": {
                    "type": "integer",
                    "minimum": 0
                  },
                  "parent_id": {
                    "type": ["string", "null"]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Upload session created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UploadSession"
                }
              }
            }
          }
        }
      }
    },
    "/files/{file_id}": {
      "get": {
        "summary": "Get file metadata",
        "operationId": "getFile",
        "parameters": [
          {
            "$ref": "#/components/parameters/FileId"
          }
        ],
        "responses": {
          "200": {
            "description": "File metadata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/File"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/files/{file_id}/share-links": {
      "post": {
        "summary": "Create a protected share link",
        "operationId": "createShareLink",
        "parameters": [
          {
            "$ref": "#/components/parameters/FileId"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "expires_at": {
                    "type": ["string", "null"],
                    "format": "date-time"
                  },
                  "password_required": {
                    "type": "boolean",
                    "default": false
                  },
                  "allow_download": {
                    "type": "boolean",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Share link created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ShareLink"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "parameters": {
      "FileId": {
        "name": "file_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^fil_[a-zA-Z0-9]{16,32}$"
        }
      }
    },
    "responses": {
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Account": {
        "type": "object",
        "required": ["id", "display_name", "email", "storage"],
        "properties": {
          "id": {
            "type": "string",
            "examples": ["acc_N8Y2C4P6W0R5T9KM"]
          },
          "display_name": {
            "type": "string",
            "examples": ["Анна Смирнова"]
          },
          "email": {
            "type": "string",
            "format": "email",
            "examples": ["anna.smirnova@rhinoc.ru"]
          },
          "storage": {
            "type": "object",
            "required": ["used_bytes", "quota_bytes"],
            "properties": {
              "used_bytes": {
                "type": "integer",
                "examples": [60988535603]
              },
              "quota_bytes": {
                "type": "integer",
                "examples": [107374182400]
              }
            }
          }
        }
      },
      "File": {
        "type": "object",
        "required": ["id", "name", "kind", "size", "modified_at"],
        "properties": {
          "id": {
            "type": "string",
            "examples": ["fil_2yG8d7Kq3vP0nM5L"]
          },
          "name": {
            "type": "string",
            "examples": ["Презентация продукта.pptx"]
          },
          "kind": {
            "type": "string",
            "enum": ["file", "folder"]
          },
          "size": {
            "type": "integer",
            "examples": [26004685]
          },
          "content_type": {
            "type": ["string", "null"],
            "examples": ["application/vnd.openxmlformats-officedocument.presentationml.presentation"]
          },
          "sha256": {
            "type": ["string", "null"]
          },
          "modified_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "UploadSession": {
        "type": "object",
        "required": ["id", "upload_url", "expires_at"],
        "properties": {
          "id": {
            "type": "string"
          },
          "upload_url": {
            "type": "string",
            "format": "uri"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ShareLink": {
        "type": "object",
        "required": ["id", "url", "created_at"],
        "properties": {
          "id": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": ["string", "null"],
            "format": "date-time"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": ["code", "message"],
        "properties": {
          "code": {
            "type": "string",
            "examples": ["file_not_found"]
          },
          "message": {
            "type": "string",
            "examples": ["The requested file does not exist."]
          },
          "request_id": {
            "type": "string",
            "examples": ["req_01K13CZJ6MB3K1JZ44E71NC6B3"]
          }
        }
      }
    }
  }
}
