{
  "openapi": "3.1.0",
  "info": {
    "title": "ShareWith API",
    "version": "1.0.0",
    "summary": "Read and write files on a ShareWith server.",
    "description": "ShareWith is a self-hosted file manager. This API works on the files of the account that owns the API key, and can be restricted to a single folder when the key is created. Paths are relative to that root; a leading slash is optional and `..` is rejected.",
    "contact": {
      "name": "ShareWith",
      "url": "https://sharewith.xyz"
    }
  },
  "servers": [
    {
      "url": "https://sharewith.xyz"
    }
  ],
  "security": [
    {
      "ApiKey": []
    }
  ],
  "tags": [
    {
      "name": "Files",
      "description": "Browse and change files"
    },
    {
      "name": "Account",
      "description": "Who the key belongs to"
    },
    {
      "name": "Keys",
      "description": "Manage API keys"
    }
  ],
  "paths": {
    "/api/v1/locations": {
      "get": {
        "operationId": "listLocations",
        "summary": "List every reachable location",
        "description": "Returns the caller's own files plus each shared folder and mounted connector, with the virtual path prefix to use for it. Start here rather than guessing mount ids.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/api/v1/files": {
      "get": {
        "operationId": "listFiles",
        "summary": "List a folder",
        "description": "Returns the folders and files directly inside `path`. Folders come first. Listing the root also returns shared folders and connector mounts, each flagged with `mount`. A path may start at the caller's own root, or with \"__adm_<id>/\" for a folder an administrator shared with them, or \"__conn_<id>/\" for a mounted FTP/SFTP/Google Drive connector. Call /api/v1/locations to discover the ids.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": false,
            "description": "Folder to list. Omit for the root. A path may start at the caller's own root, or with \"__adm_<id>/\" for a folder an administrator shared with them, or \"__conn_<id>/\" for a mounted FTP/SFTP/Google Drive connector. Call /api/v1/locations to discover the ids.",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "delete": {
        "operationId": "deleteItem",
        "summary": "Delete a file or folder",
        "description": "Deletes a file, or a folder and everything inside it. This cannot be undone.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": true,
            "description": "Item to delete.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/files/download": {
      "get": {
        "operationId": "downloadFile",
        "summary": "Download a file",
        "description": "Streams the file. Supports `Range` requests, so large downloads can be resumed.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "The file contents",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": true,
            "description": "File to download.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/files/upload": {
      "post": {
        "operationId": "uploadFile",
        "summary": "Upload a file",
        "description": "Send the file as multipart/form-data in a field named `file`. An existing file with the same name is overwritten.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": false,
            "description": "Destination folder. Omit for the root.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary"
                  }
                },
                "required": [
                  "file"
                ]
              }
            }
          }
        }
      }
    },
    "/api/v1/files/folder": {
      "post": {
        "operationId": "createFolder",
        "summary": "Create a folder",
        "description": "Creates a folder, including any missing parents.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": false,
            "description": "Parent folder.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "name",
            "in": "query",
            "required": true,
            "description": "Name of the new folder.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/files/file": {
      "post": {
        "operationId": "createFile",
        "summary": "Create an empty file",
        "description": "Creates a zero-byte file. Does nothing if the name is taken.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": false,
            "description": "Parent folder.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "name",
            "in": "query",
            "required": true,
            "description": "Name of the new file.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/files/move": {
      "put": {
        "operationId": "moveItem",
        "summary": "Move a file or folder",
        "description": "Moves an item into another folder. Source and destination may be on different backends (own files, shared folder, FTP/Drive mount); the content is streamed across.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "description": "Item to move.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "description": "Destination folder. Omit for the root.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/files/copy": {
      "put": {
        "operationId": "copyItem",
        "summary": "Copy a file or folder",
        "description": "Copies an item into another folder, leaving the source in place. Folders are copied recursively. This is how to pull data out of a read-only shared folder.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": true,
            "description": "Item to copy.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": true,
            "description": "Destination folder. Omit for the root.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/files/rename": {
      "put": {
        "operationId": "renameItem",
        "summary": "Rename a file or folder",
        "description": "Renames an item in place. `newName` must not contain a path separator.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": true,
            "description": "Item to rename.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "newName",
            "in": "query",
            "required": true,
            "description": "New name.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/files/info": {
      "get": {
        "operationId": "getFileInfo",
        "summary": "Read one item's details",
        "description": "Returns name, size, timestamps and whether the item is a folder.",
        "tags": [
          "Files"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "path",
            "in": "query",
            "required": true,
            "description": "Item to inspect.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/account": {
      "get": {
        "operationId": "getAccount",
        "summary": "Read the calling account",
        "description": "Returns the username, role and storage usage behind the API key.",
        "tags": [
          "Account"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    },
    "/api/v1/keys": {
      "get": {
        "operationId": "listKeys",
        "summary": "List your API keys",
        "description": "Returns the keys belonging to the calling account, without the secret values.",
        "tags": [
          "Keys"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      },
      "post": {
        "operationId": "createKey",
        "summary": "Create an API key",
        "description": "Creates a key. The secret is returned once and cannot be retrieved again.",
        "tags": [
          "Keys"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "name",
            "in": "query",
            "required": true,
            "description": "Label to recognise the key by.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "folder",
            "in": "query",
            "required": false,
            "description": "Restrict the key to this folder.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/keys/{id}": {
      "delete": {
        "operationId": "revokeKey",
        "summary": "Revoke an API key",
        "description": "Immediately stops the key from working.",
        "tags": [
          "Keys"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Id of the key to revoke.",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Create one from the API panel in the file manager."
      }
    },
    "schemas": {
      "Success": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "const": true
          },
          "data": {
            "description": "Payload; shape depends on the endpoint."
          }
        },
        "required": [
          "success"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "const": false
          },
          "error": {
            "type": "string"
          }
        },
        "required": [
          "success",
          "error"
        ]
      },
      "FileItem": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "path": {
            "type": "string",
            "description": "Relative to the key's root."
          },
          "isDirectory": {
            "type": "boolean"
          },
          "size": {
            "type": "integer",
            "description": "Bytes; 0 for folders."
          },
          "modifiedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  }
}