{
  "openapi": "3.1.0",
  "info": {
    "title": "Vaulted Money Local API",
    "version": "1.0.0",
    "description": "Local REST API of the Vaulted Money desktop app. Enable it in Settings; it listens on 127.0.0.1 only and needs the access token shown there."
  },
  "servers": [
    {
      "url": "http://127.0.0.1:47821/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/": {
      "get": {
        "operationId": "get",
        "summary": "List every endpoint",
        "tags": [
          "ledgers"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "operationId": "getOpenapi.json",
        "summary": "OpenAPI 3.1 description of this API (for client generators, Swagger UI, Postman)",
        "tags": [
          "openapi.json"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/health": {
      "get": {
        "operationId": "getHealth",
        "summary": "Liveness check",
        "tags": [
          "health"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers": {
      "get": {
        "operationId": "getLedgers",
        "summary": "List ledgers",
        "tags": [
          "ledgers"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postLedgers",
        "summary": "Create a ledger (names are unique, ignoring case)",
        "tags": [
          "ledgers"
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  },
                  "short_name": {
                    "type": "string"
                  },
                  "icon": {
                    "type": "string"
                  }
                },
                "required": [
                  "name",
                  "currency"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}": {
      "get": {
        "operationId": "getLedgersByLedgerId",
        "summary": "Get a ledger",
        "tags": [
          "ledgers"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchLedgersByLedgerId",
        "summary": "Update a ledger (names are unique, ignoring case)",
        "tags": [
          "ledgers"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  },
                  "short_name": {
                    "type": "string"
                  },
                  "icon": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteLedgersByLedgerId",
        "summary": "Delete a ledger and all of its data",
        "tags": [
          "ledgers"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/accounts": {
      "get": {
        "operationId": "getLedgersByLedgerIdAccounts",
        "summary": "List accounts with current balances",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postLedgersByLedgerIdAccounts",
        "summary": "Create an account",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  },
                  "starting_balance": {
                    "default": 0,
                    "type": "number"
                  },
                  "type": {
                    "default": "Checking",
                    "type": "string",
                    "enum": [
                      "Checking",
                      "Savings",
                      "Credit Card",
                      "Investment",
                      "Other"
                    ]
                  },
                  "credit_limit": {
                    "type": "number",
                    "minimum": 0
                  },
                  "remarks": {
                    "type": "string"
                  }
                },
                "required": [
                  "name",
                  "currency"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/accounts/{accountId}": {
      "get": {
        "operationId": "getLedgersByLedgerIdAccountsByAccountId",
        "summary": "Get an account",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchLedgersByLedgerIdAccountsByAccountId",
        "summary": "Update an account (a new name or currency propagates to its transactions and recurring transactions)",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  },
                  "starting_balance": {
                    "default": 0,
                    "type": "number"
                  },
                  "type": {
                    "default": "Checking",
                    "type": "string",
                    "enum": [
                      "Checking",
                      "Savings",
                      "Credit Card",
                      "Investment",
                      "Other"
                    ]
                  },
                  "credit_limit": {
                    "anyOf": [
                      {
                        "type": "number",
                        "minimum": 0
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "remarks": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteLedgersByLedgerIdAccountsByAccountId",
        "summary": "Delete an account and its recurring transactions and budgets (past transactions are kept)",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "accountId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/vendors": {
      "get": {
        "operationId": "getLedgersByLedgerIdVendors",
        "summary": "List vendors (add ?include_accounts=true to include accounts)",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "include_accounts",
            "in": "query",
            "required": false,
            "description": "true to include accounts",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postLedgersByLedgerIdVendors",
        "summary": "Create a vendor",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/vendors/merge": {
      "post": {
        "operationId": "postLedgersByLedgerIdVendorsMerge",
        "summary": "Merge vendors into a target: moves their transactions to the target, then deletes them with their recurring transactions and budgets",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "target": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sources": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                },
                "required": [
                  "target",
                  "sources"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/vendors/{vendorId}": {
      "get": {
        "operationId": "getLedgersByLedgerIdVendorsByVendorId",
        "summary": "Get a vendor",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "vendorId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchLedgersByLedgerIdVendorsByVendorId",
        "summary": "Rename a vendor (propagates to transactions, recurring transactions and budgets)",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "vendorId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteLedgersByLedgerIdVendorsByVendorId",
        "summary": "Delete a vendor and its recurring transactions and budgets (use the accounts endpoint for accounts)",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "vendorId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories": {
      "get": {
        "operationId": "getLedgersByLedgerIdCategories",
        "summary": "List categories with their sub-categories",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postLedgersByLedgerIdCategories",
        "summary": "Create a category (optionally with sub-categories)",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sub_categories": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories/merge": {
      "post": {
        "operationId": "postLedgersByLedgerIdCategoriesMerge",
        "summary": "Merge categories into a target: moves their transactions and sub-categories to the target, then deletes them with their recurring transactions and budgets",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "target": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sources": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                },
                "required": [
                  "target",
                  "sources"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories/{categoryId}": {
      "get": {
        "operationId": "getLedgersByLedgerIdCategoriesByCategoryId",
        "summary": "Get a category",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchLedgersByLedgerIdCategoriesByCategoryId",
        "summary": "Rename a category (propagates to transactions, recurring transactions and budgets)",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteLedgersByLedgerIdCategoriesByCategoryId",
        "summary": "Delete a category with its sub-categories, recurring transactions and budgets",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories/{categoryId}/sub-categories": {
      "get": {
        "operationId": "getLedgersByLedgerIdCategoriesByCategoryIdSubCategories",
        "summary": "List a category's sub-categories",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postLedgersByLedgerIdCategoriesByCategoryIdSubCategories",
        "summary": "Create a sub-category",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories/{categoryId}/sub-categories/{subCategoryId}": {
      "patch": {
        "operationId": "patchLedgersByLedgerIdCategoriesByCategoryIdSubCategoriesBySubCategoryId",
        "summary": "Rename a sub-category (propagates to transactions, recurring transactions and budgets)",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "subCategoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteLedgersByLedgerIdCategoriesByCategoryIdSubCategoriesBySubCategoryId",
        "summary": "Delete a sub-category (transactions keep their category; its budgets are removed)",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "categoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "subCategoryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions": {
      "get": {
        "operationId": "getLedgersByLedgerIdTransactions",
        "summary": "List transactions (filters: from, to, account, vendor, category, sub_category, min_amount, max_amount, type, search, exclude_transfers, limit, offset)",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "description": "Earliest date, YYYY-MM-DD",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Latest date, YYYY-MM-DD",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "account",
            "in": "query",
            "required": false,
            "description": "Exact account name",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "vendor",
            "in": "query",
            "required": false,
            "description": "Exact vendor name",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "description": "Exact category name",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sub_category",
            "in": "query",
            "required": false,
            "description": "Exact sub-category name",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "min_amount",
            "in": "query",
            "required": false,
            "description": "Minimum amount (signed)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "max_amount",
            "in": "query",
            "required": false,
            "description": "Maximum amount (signed)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "description": "income or expense",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "description": "Text to find in vendor, category, account, remarks",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "exclude_transfers",
            "in": "query",
            "required": false,
            "description": "true to hide transfers",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Page size, 1-1000 (default 100)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "description": "Rows to skip",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postLedgersByLedgerIdTransactions",
        "summary": "Create a transaction",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "account": {
                    "type": "string",
                    "minLength": 1
                  },
                  "vendor": {
                    "type": "string",
                    "minLength": 1
                  },
                  "category": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sub_category": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "remarks": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  }
                },
                "required": [
                  "date",
                  "amount",
                  "account",
                  "vendor",
                  "category"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/clear": {
      "post": {
        "operationId": "postLedgersByLedgerIdTransactionsClear",
        "summary": "Delete all transactions of a ledger (clear or empty it). Accounts, payees, categories, schedules and budgets stay. A safety copy is kept first. Body: {dry_run?, confirm_delete?}",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  },
                  "confirm_delete": {
                    "default": false,
                    "type": "boolean"
                  }
                },
                "additionalProperties": false
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/bulk": {
      "post": {
        "operationId": "postLedgersByLedgerIdTransactionsBulk",
        "summary": "Create up to 1000 transactions in one call",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "transactions": {
                    "minItems": 1,
                    "maxItems": 1000,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "date": {
                          "type": "string"
                        },
                        "amount": {
                          "type": "number"
                        },
                        "account": {
                          "type": "string",
                          "minLength": 1
                        },
                        "vendor": {
                          "type": "string",
                          "minLength": 1
                        },
                        "category": {
                          "type": "string",
                          "minLength": 1
                        },
                        "sub_category": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "remarks": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "currency": {
                          "type": "string",
                          "pattern": "^[A-Z]{3}$"
                        }
                      },
                      "required": [
                        "date",
                        "amount",
                        "account",
                        "vendor",
                        "category"
                      ]
                    }
                  }
                },
                "required": [
                  "transactions"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/transfer": {
      "post": {
        "operationId": "postLedgersByLedgerIdTransactionsTransfer",
        "summary": "Create a linked transfer between two accounts",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "from_account": {
                    "type": "string",
                    "minLength": 1
                  },
                  "to_account": {
                    "type": "string",
                    "minLength": 1
                  },
                  "amount": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  },
                  "to_amount": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  },
                  "date": {
                    "type": "string"
                  },
                  "remarks": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "from_account",
                  "to_account",
                  "amount",
                  "date"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/transfer/{transferId}": {
      "delete": {
        "operationId": "deleteLedgersByLedgerIdTransactionsTransferByTransferId",
        "summary": "Delete both legs of a transfer",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "transferId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/{transactionId}": {
      "get": {
        "operationId": "getLedgersByLedgerIdTransactionsByTransactionId",
        "summary": "Get a transaction",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "transactionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchLedgersByLedgerIdTransactionsByTransactionId",
        "summary": "Update a transaction (on a linked transfer the other leg follows what you changed, like the app)",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "transactionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "account": {
                    "type": "string",
                    "minLength": 1
                  },
                  "vendor": {
                    "type": "string",
                    "minLength": 1
                  },
                  "category": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sub_category": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "remarks": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteLedgersByLedgerIdTransactionsByTransactionId",
        "summary": "Delete a transaction (deleting one leg of a transfer deletes both, like the app)",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "transactionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/search/interpret": {
      "get": {
        "operationId": "getLedgersByLedgerIdSearchInterpret",
        "summary": "Interpret a natural-language search phrase into structured filters, as the search box does (changes nothing)",
        "tags": [
          "search"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "The phrase to read, e.g. \"starbuks over 20 last month\" (required)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "today",
            "in": "query",
            "required": false,
            "description": "YYYY-MM-DD to treat as today, for repeatable results (default: today)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "typos",
            "in": "query",
            "required": false,
            "description": "false to match names exactly, with no typo correction (default true)",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/detect-transfers": {
      "post": {
        "operationId": "postLedgersByLedgerIdTransactionsDetectTransfers",
        "summary": "Find and link transfer pairs (\"Detect Transfers\"), keeping their categories unless keep_categories is false. Body: {dry_run?, keep_categories?}",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  },
                  "keep_categories": {
                    "default": true,
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/cleanup-duplicates": {
      "post": {
        "operationId": "postLedgersByLedgerIdTransactionsCleanupDuplicates",
        "summary": "Delete duplicate recurring-schedule transactions (\"Cleanup Duplicates\"). Body: {dry_run?, confirm_delete?}",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  },
                  "confirm_delete": {
                    "default": false,
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/categorize-missing": {
      "post": {
        "operationId": "postLedgersByLedgerIdTransactionsCategorizeMissing",
        "summary": "Categorize uncategorized transactions from history, optionally with AI (\"Categorize Missing\"). Body: {dry_run?, use_ai?}",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  },
                  "use_ai": {
                    "default": false,
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/accounts/reconcile": {
      "post": {
        "operationId": "postLedgersByLedgerIdAccountsReconcile",
        "summary": "Create balance-adjustment transactions so accounts match real balances (\"Reconcile Balance\"). Body: {adjustments:[{account, actual_balance}], date?, dry_run?}",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  },
                  "adjustments": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "account": {
                          "type": "string",
                          "minLength": 1
                        },
                        "actual_balance": {
                          "type": "number"
                        }
                      },
                      "required": [
                        "account",
                        "actual_balance"
                      ]
                    }
                  },
                  "date": {
                    "type": "string"
                  }
                },
                "required": [
                  "adjustments"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/accounts/merge": {
      "post": {
        "operationId": "postLedgersByLedgerIdAccountsMerge",
        "summary": "Merge accounts into a target (\"De-duplicate\"): moves their transactions to the target, then deletes them with their recurring transactions and budgets. Body: {target, sources}",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "target": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sources": {
                    "minItems": 1,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1
                    }
                  }
                },
                "required": [
                  "target",
                  "sources"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/accounts/duplicates": {
      "get": {
        "operationId": "getLedgersByLedgerIdAccountsDuplicates",
        "summary": "Suggest accounts that look like duplicates (same name ignoring case/punctuation)",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/vendors/duplicates": {
      "get": {
        "operationId": "getLedgersByLedgerIdVendorsDuplicates",
        "summary": "Suggest vendors that look like duplicates",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories/duplicates": {
      "get": {
        "operationId": "getLedgersByLedgerIdCategoriesDuplicates",
        "summary": "Suggest categories that look like duplicates",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/vendors/unused": {
      "get": {
        "operationId": "getLedgersByLedgerIdVendorsUnused",
        "summary": "List vendors nothing refers to",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/vendors/cleanup": {
      "post": {
        "operationId": "postLedgersByLedgerIdVendorsCleanup",
        "summary": "Delete unused vendors (\"Cleanup Unused\"). Body: {ids?, dry_run?, confirm_delete?}",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  },
                  "confirm_delete": {
                    "default": false,
                    "type": "boolean"
                  },
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories/unused": {
      "get": {
        "operationId": "getLedgersByLedgerIdCategoriesUnused",
        "summary": "List categories nothing refers to",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories/cleanup": {
      "post": {
        "operationId": "postLedgersByLedgerIdCategoriesCleanup",
        "summary": "Delete unused categories (\"Cleanup Unused\"). Body: {ids?, dry_run?, confirm_delete?}",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  },
                  "confirm_delete": {
                    "default": false,
                    "type": "boolean"
                  },
                  "ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/export": {
      "get": {
        "operationId": "getLedgersByLedgerIdTransactionsExport",
        "summary": "Download transactions as CSV, same format as Export CSV in the app (accepts the list filters; ?delimiter=; or , )",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "delimiter",
            "in": "query",
            "required": false,
            "description": "; (default, matches the app) or , or tab",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "description": "Earliest date",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Latest date",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "account",
            "in": "query",
            "required": false,
            "description": "Exact account name",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "vendor",
            "in": "query",
            "required": false,
            "description": "Exact vendor name",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "description": "Exact category name",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "description": "income or expense",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "description": "Text filter",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "exclude_transfers",
            "in": "query",
            "required": false,
            "description": "true to hide transfers",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/transactions/import": {
      "post": {
        "operationId": "postLedgersByLedgerIdTransactionsImport",
        "summary": "Import transactions from CSV text, same format as Import CSV in the app: append to or replace the ledger's transactions, and optionally remove unused payees and categories. Body: {csv, delimiter?, detect_transfers?, keep_categories?, mode?, remove_unused?, skip_duplicates?, confirm_delete?, dry_run?}",
        "tags": [
          "transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "csv": {
                    "type": "string",
                    "minLength": 1
                  },
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  },
                  "delimiter": {
                    "default": ";",
                    "type": "string",
                    "enum": [
                      ";",
                      ",",
                      "\t"
                    ]
                  },
                  "detect_transfers": {
                    "default": false,
                    "type": "boolean"
                  },
                  "keep_categories": {
                    "default": true,
                    "type": "boolean"
                  },
                  "mode": {
                    "default": "append",
                    "type": "string",
                    "enum": [
                      "append",
                      "replace"
                    ]
                  },
                  "remove_unused": {
                    "default": false,
                    "type": "boolean"
                  },
                  "confirm_delete": {
                    "default": false,
                    "type": "boolean"
                  },
                  "skip_duplicates": {
                    "default": false,
                    "type": "boolean"
                  }
                },
                "required": [
                  "csv"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/accounts/export": {
      "get": {
        "operationId": "getLedgersByLedgerIdAccountsExport",
        "summary": "Download accounts as CSV",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/accounts/import": {
      "post": {
        "operationId": "postLedgersByLedgerIdAccountsImport",
        "summary": "Create accounts from CSV (columns: Account Name, Currency, Starting Balance, Remarks). Existing accounts are left unchanged. Body: {csv, dry_run?}",
        "tags": [
          "accounts"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "csv": {
                    "type": "string",
                    "minLength": 1
                  },
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  }
                },
                "required": [
                  "csv"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/vendors/export": {
      "get": {
        "operationId": "getLedgersByLedgerIdVendorsExport",
        "summary": "Download vendors as CSV",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/vendors/import": {
      "post": {
        "operationId": "postLedgersByLedgerIdVendorsImport",
        "summary": "Create vendors from CSV (column: Vendor Name). Existing names are left unchanged. Body: {csv, dry_run?}",
        "tags": [
          "vendors"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "csv": {
                    "type": "string",
                    "minLength": 1
                  },
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  }
                },
                "required": [
                  "csv"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories/export": {
      "get": {
        "operationId": "getLedgersByLedgerIdCategoriesExport",
        "summary": "Download categories and sub-categories as CSV",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/categories/import": {
      "post": {
        "operationId": "postLedgersByLedgerIdCategoriesImport",
        "summary": "Create categories and sub-categories from CSV (columns: Category Name, Sub Category Name). Body: {csv, dry_run?}",
        "tags": [
          "categories"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "csv": {
                    "type": "string",
                    "minLength": 1
                  },
                  "dry_run": {
                    "default": false,
                    "type": "boolean"
                  }
                },
                "required": [
                  "csv"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/history": {
      "get": {
        "operationId": "getLedgersByLedgerIdHistory",
        "summary": "List the change history of bulk actions",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/history/{runId}": {
      "get": {
        "operationId": "getLedgersByLedgerIdHistoryByRunId",
        "summary": "Get one change history run with its transactions",
        "tags": [
          "history"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "runId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/scheduled-transactions": {
      "get": {
        "operationId": "getLedgersByLedgerIdScheduledTransactions",
        "summary": "List recurring (scheduled) transactions",
        "tags": [
          "scheduled-transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postLedgersByLedgerIdScheduledTransactions",
        "summary": "Create a recurring transaction",
        "tags": [
          "scheduled-transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "account": {
                    "type": "string",
                    "minLength": 1
                  },
                  "vendor": {
                    "type": "string",
                    "minLength": 1
                  },
                  "category": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sub_category": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "frequency": {
                    "type": "string",
                    "pattern": "^(Daily|Weekly|Monthly|Yearly|One-time|[1-9]\\d*[dwmy])$"
                  },
                  "end_date": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "remarks": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  },
                  "ignored_dates": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                },
                "required": [
                  "date",
                  "amount",
                  "account",
                  "vendor",
                  "category",
                  "frequency"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/scheduled-transactions/{scheduledId}": {
      "get": {
        "operationId": "getLedgersByLedgerIdScheduledTransactionsByScheduledId",
        "summary": "Get a recurring transaction",
        "tags": [
          "scheduled-transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "scheduledId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchLedgersByLedgerIdScheduledTransactionsByScheduledId",
        "summary": "Update a recurring transaction",
        "tags": [
          "scheduled-transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "scheduledId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "date": {
                    "type": "string"
                  },
                  "amount": {
                    "type": "number"
                  },
                  "account": {
                    "type": "string",
                    "minLength": 1
                  },
                  "vendor": {
                    "type": "string",
                    "minLength": 1
                  },
                  "category": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sub_category": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "frequency": {
                    "type": "string",
                    "pattern": "^(Daily|Weekly|Monthly|Yearly|One-time|[1-9]\\d*[dwmy])$"
                  },
                  "end_date": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "remarks": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  },
                  "ignored_dates": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteLedgersByLedgerIdScheduledTransactionsByScheduledId",
        "summary": "Delete a recurring transaction (created transactions are kept)",
        "tags": [
          "scheduled-transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "scheduledId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/scheduled-transactions/{scheduledId}/skip": {
      "post": {
        "operationId": "postLedgersByLedgerIdScheduledTransactionsByScheduledIdSkip",
        "summary": "Skip one occurrence by date (adds it to ignored_dates)",
        "tags": [
          "scheduled-transactions"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "scheduledId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/budgets": {
      "get": {
        "operationId": "getLedgersByLedgerIdBudgets",
        "summary": "List budgets and savings goals with current spending",
        "tags": [
          "budgets"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postLedgersByLedgerIdBudgets",
        "summary": "Create a budget or savings goal",
        "tags": [
          "budgets"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "budget_scope": {
                    "default": "category",
                    "type": "string",
                    "enum": [
                      "category",
                      "sub_category",
                      "account",
                      "vendor"
                    ]
                  },
                  "category": {
                    "type": "string",
                    "minLength": 1
                  },
                  "sub_category": {
                    "type": "string",
                    "minLength": 1
                  },
                  "scope_name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "target_amount": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  },
                  "frequency": {
                    "default": "Monthly",
                    "type": "string",
                    "pattern": "^(Monthly|Quarterly|Yearly|One-time|[1-9]\\d*[dwmy])$"
                  },
                  "start_date": {
                    "type": "string"
                  },
                  "end_date": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "is_active": {
                    "default": true,
                    "type": "boolean"
                  },
                  "is_goal": {
                    "default": false,
                    "type": "boolean"
                  },
                  "target_date": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "monthly_contribution": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "goal_context": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "account_scope_values": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "target_amount"
                ]
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/budgets/history": {
      "get": {
        "operationId": "getLedgersByLedgerIdBudgetsHistory",
        "summary": "Budget history: spent versus target for each past period, to see which budgets are regularly missed",
        "tags": [
          "budgets"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "periods",
            "in": "query",
            "required": false,
            "description": "How many periods to look back, 1-24 (default 6)",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/budgets/{budgetId}": {
      "get": {
        "operationId": "getLedgersByLedgerIdBudgetsByBudgetId",
        "summary": "Get a budget with current spending",
        "tags": [
          "budgets"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "budgetId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchLedgersByLedgerIdBudgetsByBudgetId",
        "summary": "Update a budget",
        "tags": [
          "budgets"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "budgetId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "target_amount": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  },
                  "currency": {
                    "type": "string",
                    "pattern": "^[A-Z]{3}$"
                  },
                  "frequency": {
                    "type": "string",
                    "pattern": "^(Monthly|Quarterly|Yearly|One-time|[1-9]\\d*[dwmy])$"
                  },
                  "start_date": {
                    "type": "string"
                  },
                  "end_date": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "is_active": {
                    "type": "boolean"
                  },
                  "target_date": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "monthly_contribution": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "goal_context": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "account_scope_values": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteLedgersByLedgerIdBudgetsByBudgetId",
        "summary": "Delete a budget",
        "tags": [
          "budgets"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "budgetId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/currencies": {
      "get": {
        "operationId": "getCurrencies",
        "summary": "List active currencies, exchange rates and the base currency",
        "tags": [
          "currencies"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postCurrencies",
        "summary": "Add a currency with an initial rate (relative to USD)",
        "tags": [
          "currencies"
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "pattern": "^[A-Z0-9]{2,10}$"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "symbol": {
                    "type": "string",
                    "minLength": 1
                  },
                  "rate": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  }
                },
                "required": [
                  "code",
                  "name",
                  "symbol",
                  "rate"
                ]
              }
            }
          }
        }
      }
    },
    "/currencies/base": {
      "put": {
        "operationId": "putCurrenciesBase",
        "summary": "Set the base (display) currency",
        "tags": [
          "currencies"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/currencies/refresh-rates": {
      "post": {
        "operationId": "postCurrenciesRefreshRates",
        "summary": "Fetch the latest exchange rates from Frankfurter",
        "tags": [
          "currencies"
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/currencies/{code}": {
      "get": {
        "operationId": "getCurrenciesByCode",
        "summary": "Get a currency",
        "tags": [
          "currencies"
        ],
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchCurrenciesByCode",
        "summary": "Update a currency's name, symbol or exchange rate",
        "tags": [
          "currencies"
        ],
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "symbol": {
                    "type": "string",
                    "minLength": 1
                  },
                  "rate": {
                    "type": "number",
                    "exclusiveMinimum": 0
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteCurrenciesByCode",
        "summary": "Remove a currency (the base currency cannot be removed)",
        "tags": [
          "currencies"
        ],
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/settings": {
      "get": {
        "operationId": "getSettings",
        "summary": "Read global settings (currency, language, future months, AI provider)",
        "tags": [
          "settings"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchSettings",
        "summary": "Change global settings. Body: any of {base_currency, language, future_months, default_ai_provider_id (null = disabled)}",
        "tags": [
          "settings"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "base_currency": {
                    "type": "string",
                    "minLength": 1
                  },
                  "language": {
                    "type": "string",
                    "minLength": 1
                  },
                  "future_months": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 120
                  },
                  "default_ai_provider_id": {
                    "anyOf": [
                      {
                        "type": "string",
                        "minLength": 1
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    "/ai-providers": {
      "get": {
        "operationId": "getAiProviders",
        "summary": "List AI providers (API keys are never returned)",
        "tags": [
          "ai-providers"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postAiProviders",
        "summary": "Add an AI provider, optionally with its API key",
        "tags": [
          "ai-providers"
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "OPENAI",
                      "GEMINI",
                      "ANTHROPIC",
                      "MISTRAL",
                      "PERPLEXITY",
                      "CUSTOM"
                    ]
                  },
                  "baseUrl": {
                    "type": "string",
                    "format": "uri"
                  },
                  "model": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "isDefault": {
                    "type": "boolean"
                  },
                  "api_key": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "name",
                  "type",
                  "baseUrl"
                ]
              }
            }
          }
        }
      }
    },
    "/ai-providers/{providerId}": {
      "get": {
        "operationId": "getAiProvidersByProviderId",
        "summary": "Get an AI provider",
        "tags": [
          "ai-providers"
        ],
        "parameters": [
          {
            "name": "providerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchAiProvidersByProviderId",
        "summary": "Update an AI provider",
        "tags": [
          "ai-providers"
        ],
        "parameters": [
          {
            "name": "providerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "type": {
                    "type": "string",
                    "enum": [
                      "OPENAI",
                      "GEMINI",
                      "ANTHROPIC",
                      "MISTRAL",
                      "PERPLEXITY",
                      "CUSTOM"
                    ]
                  },
                  "baseUrl": {
                    "type": "string",
                    "format": "uri"
                  },
                  "model": {
                    "type": "string"
                  },
                  "description": {
                    "type": "string"
                  },
                  "isDefault": {
                    "type": "boolean"
                  },
                  "api_key": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteAiProvidersByProviderId",
        "summary": "Delete an AI provider and its stored API key",
        "tags": [
          "ai-providers"
        ],
        "parameters": [
          {
            "name": "providerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ai-providers/{providerId}/default": {
      "put": {
        "operationId": "putAiProvidersByProviderIdDefault",
        "summary": "Make this the default AI provider",
        "tags": [
          "ai-providers"
        ],
        "parameters": [
          {
            "name": "providerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ai-providers/{providerId}/api-key": {
      "put": {
        "operationId": "putAiProvidersByProviderIdApiKey",
        "summary": "Set the provider's API key (stored on this device only)",
        "tags": [
          "ai-providers"
        ],
        "parameters": [
          {
            "name": "providerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteAiProvidersByProviderIdApiKey",
        "summary": "Remove the provider's API key",
        "tags": [
          "ai-providers"
        ],
        "parameters": [
          {
            "name": "providerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/languages": {
      "get": {
        "operationId": "getLanguages",
        "summary": "List available languages and the active one",
        "tags": [
          "languages"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/languages/current": {
      "put": {
        "operationId": "putLanguagesCurrent",
        "summary": "Switch the app language",
        "tags": [
          "languages"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/languages/custom": {
      "post": {
        "operationId": "postLanguagesCustom",
        "summary": "Add or replace a custom language with its translations",
        "tags": [
          "languages"
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "code": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 20
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1
                  },
                  "translations": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  }
                },
                "required": [
                  "code",
                  "name",
                  "translations"
                ]
              }
            }
          }
        }
      }
    },
    "/languages/custom/{code}": {
      "delete": {
        "operationId": "deleteLanguagesCustomByCode",
        "summary": "Remove a custom language",
        "tags": [
          "languages"
        ],
        "parameters": [
          {
            "name": "code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/backups/export": {
      "get": {
        "operationId": "getBackupsExport",
        "summary": "Download an unencrypted backup of everything, or one ledger with ?ledger_id=",
        "tags": [
          "backups"
        ],
        "parameters": [
          {
            "name": "ledger_id",
            "in": "query",
            "required": false,
            "description": "Limit the backup to one ledger",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postBackupsExport",
        "summary": "Generate a backup download, optionally for one ledger and/or password-encrypted",
        "tags": [
          "backups"
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "ledger_id": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string",
                    "minLength": 1
                  }
                }
              }
            }
          }
        }
      }
    },
    "/backups/import": {
      "post": {
        "operationId": "postBackupsImport",
        "summary": "Import a backup: mode \"add\" puts its ledgers beside the existing ones; the default \"replace\" is DESTRUCTIVE and requires confirm_replace=true",
        "tags": [
          "backups"
        ],
        "parameters": [],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "content": {
                    "type": "string",
                    "minLength": 1
                  },
                  "backup": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string"
                    },
                    "additionalProperties": {}
                  },
                  "password": {
                    "type": "string",
                    "minLength": 1
                  },
                  "ledger_id": {
                    "type": "string"
                  },
                  "force": {
                    "default": false,
                    "type": "boolean"
                  },
                  "mode": {
                    "default": "replace",
                    "type": "string",
                    "enum": [
                      "replace",
                      "add"
                    ]
                  },
                  "remove_unused": {
                    "default": false,
                    "type": "boolean"
                  },
                  "confirm_replace": {
                    "default": false,
                    "type": "boolean"
                  },
                  "continue_without_safety_copy": {
                    "default": false,
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/backups/safety": {
      "get": {
        "operationId": "getBackupsSafety",
        "summary": "List automatic safety copies made before imports, AI changes and sync",
        "tags": [
          "backups"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/backups/safety/{safetyId}/restore": {
      "post": {
        "operationId": "postBackupsSafetyBySafetyIdRestore",
        "summary": "Restore an automatic safety copy (mirrors the Restore button on the Backup screen)",
        "tags": [
          "backups"
        ],
        "parameters": [
          {
            "name": "safetyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "confirm_restore": {
                    "type": "boolean",
                    "const": true
                  },
                  "continue_without_safety_copy": {
                    "default": false,
                    "type": "boolean"
                  }
                },
                "required": [
                  "confirm_restore"
                ]
              }
            }
          }
        }
      }
    },
    "/backups/safety/{safetyId}": {
      "delete": {
        "operationId": "deleteBackupsSafetyBySafetyId",
        "summary": "Delete an automatic safety copy",
        "tags": [
          "backups"
        ],
        "parameters": [
          {
            "name": "safetyId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "confirm_delete": {
                    "type": "boolean",
                    "const": true
                  }
                },
                "required": [
                  "confirm_delete"
                ]
              }
            }
          }
        }
      }
    },
    "/backups/schedules": {
      "get": {
        "operationId": "getBackupsSchedules",
        "summary": "List scheduled backup configurations",
        "tags": [
          "backups"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/backups/schedules/{scheduleId}": {
      "patch": {
        "operationId": "patchBackupsSchedulesByScheduleId",
        "summary": "Enable/disable a scheduled backup or change its frequency (only encrypted schedules can be enabled)",
        "tags": [
          "backups"
        ],
        "parameters": [
          {
            "name": "scheduleId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "type": "object",
                "properties": {
                  "is_active": {
                    "type": "boolean"
                  },
                  "frequency_ms": {
                    "type": "integer",
                    "minimum": 60000,
                    "maximum": 9007199254740991
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteBackupsSchedulesByScheduleId",
        "summary": "Delete a scheduled backup configuration",
        "tags": [
          "backups"
        ],
        "parameters": [
          {
            "name": "scheduleId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/analytics": {
      "get": {
        "operationId": "getLedgersByLedgerIdAnalytics",
        "summary": "Generate spending analytics (from, to, group_by=day|week|month, currency, include_transfers; format=csv or download=true to download)",
        "tags": [
          "analytics"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "description": "Earliest date",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Latest date",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group_by",
            "in": "query",
            "required": false,
            "description": "day, week or month (default month)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "currency",
            "in": "query",
            "required": false,
            "description": "Report currency (default: ledger currency)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "include_transfers",
            "in": "query",
            "required": false,
            "description": "true to include transfers",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "json (default) or csv",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "download",
            "in": "query",
            "required": false,
            "description": "true to receive JSON as a file",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/insights": {
      "get": {
        "operationId": "getLedgersByLedgerIdInsights",
        "summary": "Generate insights: budget health and 30-day spending/activity trends (format=csv or download=true to download)",
        "tags": [
          "insights"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "json (default) or csv",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "download",
            "in": "query",
            "required": false,
            "description": "true to receive JSON as a file",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/reports": {
      "get": {
        "operationId": "getReports",
        "summary": "List available report types",
        "tags": [
          "reports"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/ledgers/{ledgerId}/reports/{reportType}": {
      "get": {
        "operationId": "getLedgersByLedgerIdReportsByReportType",
        "summary": "Generate a report: income-expense, net-worth or trends (from, to, currency; format=csv or download=true to download)",
        "tags": [
          "reports"
        ],
        "parameters": [
          {
            "name": "ledgerId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "reportType",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "description": "Earliest date",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Latest date (as-of date for net-worth)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "currency",
            "in": "query",
            "required": false,
            "description": "Report currency",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "description": "json (default) or csv",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "download",
            "in": "query",
            "required": false,
            "description": "true to receive JSON as a file",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success. JSON, or a file download for export endpoints and ?format=csv."
          },
          "400": {
            "description": "Validation error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid bearer token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {}
            }
          }
        }
      }
    }
  }
}
