{
  "openapi": "3.1.0",
  "info": {
    "title": "easymarkdown API",
    "version": "1",
    "description": "Documents, folders, history and search for easymarkdown. Human-readable reference: https://easymarkdown.io/docs/api. Within v1, changes are additive only."
  },
  "servers": [
    {
      "url": "https://easymarkdown.io/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/documents": {
      "get": {
        "operationId": "listDocuments",
        "summary": "List documents, newest first",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentList"
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Title contains (case-insensitive). Use /search for content."
          },
          {
            "name": "folder_id",
            "in": "query",
            "schema": {
              "type": [
                "integer",
                "string"
              ]
            },
            "description": "Only this folder; empty (`?folder_id=`) for unfiled documents."
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/Status"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500
            },
            "description": "Page size. Without it, every document comes back in one response."
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 1000
            },
            "description": "`meta.next_cursor` from the previous page."
          }
        ]
      },
      "post": {
        "operationId": "createDocument",
        "summary": "Create a document",
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreatedDocument"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 255,
                    "default": "Untitled"
                  },
                  "content": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "Markdown, up to 512 KB (bytes)."
                  },
                  "folder_id": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "description": "One of your folders; null for unfiled."
                  },
                  "status": {
                    "$ref": "#/components/schemas/Status"
                  }
                },
                "required": []
              }
            }
          }
        }
      }
    },
    "/documents/{document}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DocumentId"
        }
      ],
      "get": {
        "operationId": "getDocument",
        "summary": "Get a document with its content",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Document"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "operationId": "updateDocument",
        "summary": "Update title, content or status",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdatedDocument"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "title": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "content": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "status": {
                    "$ref": "#/components/schemas/Status"
                  },
                  "updated_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "The updated_at you read. 409 if the server copy is more than 2 s newer."
                  }
                },
                "required": []
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteDocument",
        "summary": "Delete a document and its history",
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/documents/{document}/content": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DocumentId"
        }
      ],
      "get": {
        "operationId": "getDocumentContent",
        "summary": "The Markdown itself, byte for byte",
        "responses": {
          "200": {
            "description": "OK",
            "headers": {
              "X-Updated-At": {
                "description": "The document's updated_at: send it back on PUT for the lock.",
                "schema": {
                  "type": "string",
                  "format": "date-time"
                }
              }
            },
            "content": {
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "operationId": "putDocumentContent",
        "summary": "Replace the content with the raw request body",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UpdatedDocument"
                }
              }
            }
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "parameters": [
          {
            "name": "X-Updated-At",
            "in": "header",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "From a read; 409 if the document changed since (2 s tolerance)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "text/markdown": {
              "schema": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "/documents/{document}/move": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DocumentId"
        }
      ],
      "post": {
        "operationId": "moveDocument",
        "summary": "Move a document to a folder and/or reorder it",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MovedDocument"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "folder_id": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "description": "Required (null = unfiled)."
                  },
                  "place": {
                    "type": "string",
                    "enum": [
                      "top",
                      "bottom",
                      "before",
                      "after"
                    ]
                  },
                  "anchor_id": {
                    "type": "integer",
                    "description": "Required with before/after: a sibling document."
                  }
                },
                "required": [
                  "folder_id",
                  "place"
                ]
              }
            }
          }
        }
      }
    },
    "/documents/{document}/snapshots": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DocumentId"
        }
      ],
      "get": {
        "operationId": "listSnapshots",
        "summary": "History entries and named snapshots, newest first",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SnapshotList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "parameters": [
          {
            "name": "kind",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "manual",
                "auto"
              ]
            }
          }
        ]
      },
      "post": {
        "operationId": "createSnapshot",
        "summary": "Save a named snapshot (10/min per account)",
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Snapshot"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  }
                },
                "required": []
              }
            }
          }
        }
      }
    },
    "/documents/{document}/snapshots/{snapshot}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DocumentId"
        },
        {
          "$ref": "#/components/parameters/SnapshotId"
        }
      ],
      "get": {
        "operationId": "getSnapshot",
        "summary": "One history entry or snapshot, with content",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SnapshotWithContent"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "delete": {
        "operationId": "deleteSnapshot",
        "summary": "Delete a snapshot or history entry",
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/documents/{document}/snapshots/{snapshot}/restore": {
      "parameters": [
        {
          "$ref": "#/components/parameters/DocumentId"
        },
        {
          "$ref": "#/components/parameters/SnapshotId"
        }
      ],
      "post": {
        "operationId": "restoreSnapshot",
        "summary": "Restore a version (the current content is kept as \"Before restore\")",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestoredDocument"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        }
      }
    },
    "/folders": {
      "get": {
        "operationId": "listFolders",
        "summary": "Every folder and project (projects have parent_id null)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FolderList"
                }
              }
            },
            "headers": {
              "X-RateLimit-Limit": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-RateLimit-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "operationId": "createFolder",
        "summary": "Create a folder or project",
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Folder"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "parent_id": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "description": "One of your folders; null = a project."
                  },
                  "status": {
                    "$ref": "#/components/schemas/Status"
                  }
                },
                "required": [
                  "name"
                ]
              }
            }
          }
        }
      }
    },
    "/folders/{folder}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/FolderId"
        }
      ],
      "patch": {
        "operationId": "updateFolder",
        "summary": "Rename or set the status",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Folder"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 255
                  },
                  "status": {
                    "$ref": "#/components/schemas/Status"
                  }
                },
                "required": []
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteFolder",
        "summary": "Delete an empty folder",
        "responses": {
          "204": {
            "description": "Deleted."
          },
          "409": {
            "description": "`folder_not_empty`: move or delete its contents first.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/folders/{folder}/move": {
      "parameters": [
        {
          "$ref": "#/components/parameters/FolderId"
        }
      ],
      "post": {
        "operationId": "moveFolder",
        "summary": "Move a folder under another and/or reorder it",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Folder"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "parent_id": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "description": "Required (null = top level). Not itself or a subfolder."
                  },
                  "place": {
                    "type": "string",
                    "enum": [
                      "top",
                      "bottom",
                      "before",
                      "after"
                    ]
                  },
                  "anchor_id": {
                    "type": "integer",
                    "description": "Required with before/after: a sibling folder."
                  }
                },
                "required": [
                  "parent_id",
                  "place"
                ]
              }
            }
          }
        }
      }
    },
    "/search": {
      "get": {
        "operationId": "search",
        "summary": "Search folder names, document titles and content (50 results per type)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResults"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "402": {
            "$ref": "#/components/responses/PaymentRequired"
          },
          "403": {
            "$ref": "#/components/responses/MissingAbility"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "422": {
            "$ref": "#/components/responses/Unprocessable"
          }
        },
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 200
            }
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "An API key from Settings → API keys. New keys look like `12|emd_…`."
      }
    },
    "parameters": {
      "DocumentId": {
        "name": "document",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Document id."
      },
      "SnapshotId": {
        "name": "snapshot",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Snapshot or history entry id (of that document)."
      },
      "FolderId": {
        "name": "folder",
        "in": "path",
        "required": true,
        "schema": {
          "type": "integer"
        },
        "description": "Folder id."
      }
    },
    "schemas": {
      "Status": {
        "type": "string",
        "enum": [
          "draft",
          "review",
          "approved",
          "done",
          "archived"
        ]
      },
      "DocumentListItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "folder_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "position": {
            "type": "integer"
          },
          "word_count": {
            "type": "integer"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_accessed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "readOnly": true,
            "description": "Opens the document in the workspace (/dashboard?doc={id})."
          }
        },
        "required": [
          "id",
          "folder_id",
          "title",
          "slug",
          "status",
          "position",
          "word_count",
          "updated_at",
          "last_accessed_at",
          "url"
        ]
      },
      "Document": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "folder_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "position": {
            "type": "integer"
          },
          "content": {
            "type": "string"
          },
          "word_count": {
            "type": "integer"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "last_accessed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "readOnly": true,
            "description": "Opens the document in the workspace (/dashboard?doc={id})."
          }
        },
        "required": [
          "id",
          "folder_id",
          "title",
          "slug",
          "status",
          "position",
          "content",
          "word_count",
          "updated_at",
          "last_accessed_at",
          "url"
        ]
      },
      "CreatedDocument": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "folder_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "position": {
            "type": "integer"
          },
          "content": {
            "type": "string"
          },
          "word_count": {
            "type": "integer"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "readOnly": true,
            "description": "Opens the document in the workspace (/dashboard?doc={id})."
          }
        },
        "required": [
          "id",
          "folder_id",
          "title",
          "slug",
          "status",
          "position",
          "content",
          "word_count",
          "updated_at",
          "url"
        ]
      },
      "UpdatedDocument": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "folder_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "position": {
            "type": "integer"
          },
          "word_count": {
            "type": "integer"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "readOnly": true,
            "description": "Opens the document in the workspace (/dashboard?doc={id})."
          }
        },
        "required": [
          "id",
          "folder_id",
          "title",
          "slug",
          "status",
          "position",
          "word_count",
          "updated_at",
          "url"
        ]
      },
      "MovedDocument": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "folder_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "position": {
            "type": "integer"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "folder_id",
          "position",
          "updated_at"
        ]
      },
      "RestoredDocument": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "content": {
            "type": "string"
          },
          "word_count": {
            "type": "integer"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "content",
          "word_count",
          "updated_at"
        ]
      },
      "DocumentList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentListItem"
            }
          },
          "meta": {
            "type": "object",
            "properties": {
              "total": {
                "type": "integer",
                "description": "Rows in this response (with `limit`: in this page)."
              },
              "next_cursor": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Only with `limit`. Pass as `cursor` for the next page; null on the last page."
              }
            },
            "required": [
              "total"
            ]
          }
        },
        "required": [
          "data",
          "meta"
        ]
      },
      "Folder": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "parent_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "name": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "position": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "parent_id",
          "name",
          "status",
          "position",
          "created_at",
          "updated_at"
        ]
      },
      "FolderList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Folder"
            }
          },
          "meta": {
            "type": "object",
            "properties": {
              "total": {
                "type": "integer"
              }
            },
            "required": [
              "total"
            ]
          }
        },
        "required": [
          "data",
          "meta"
        ]
      },
      "Snapshot": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "kind": {
            "type": "string",
            "enum": [
              "manual",
              "auto"
            ],
            "description": "manual = named snapshot, auto = history entry"
          },
          "name": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "word_count": {
            "type": "integer"
          },
          "source": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "web",
              "api",
              null
            ],
            "description": "Who wrote it (history entries)."
          },
          "token_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "The API key's name when source is api."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "kind",
          "name",
          "title",
          "word_count",
          "source",
          "token_name",
          "created_at"
        ]
      },
      "SnapshotWithContent": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Snapshot"
          },
          {
            "type": "object",
            "properties": {
              "content": {
                "type": "string"
              }
            },
            "required": [
              "content"
            ]
          }
        ]
      },
      "SnapshotList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Snapshot"
            }
          }
        },
        "required": [
          "data"
        ]
      },
      "SearchResults": {
        "type": "object",
        "properties": {
          "folders": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "parent_id": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "name": {
                  "type": "string"
                },
                "status": {
                  "$ref": "#/components/schemas/Status"
                },
                "path": {
                  "type": "string",
                  "description": "Parent folders joined with \" / \"; empty at the top level."
                }
              },
              "required": [
                "id",
                "parent_id",
                "name",
                "status",
                "path"
              ]
            }
          },
          "documents": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "integer"
                },
                "folder_id": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "title": {
                  "type": "string"
                },
                "status": {
                  "$ref": "#/components/schemas/Status"
                },
                "updated_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "path": {
                  "type": "string"
                },
                "snippet": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "id",
                "folder_id",
                "title",
                "status",
                "updated_at",
                "path",
                "snippet"
              ]
            }
          }
        },
        "required": [
          "folders",
          "documents"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          },
          "code": {
            "type": "string",
            "enum": [
              "unauthenticated",
              "subscription_required",
              "subscription_ended",
              "missing_ability",
              "not_found",
              "conflict",
              "folder_not_empty",
              "validation_failed",
              "content_too_large",
              "storage_limit",
              "row_limit",
              "rate_limited",
              "server_error"
            ]
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "description": "Per-field messages, with validation_failed only."
          }
        },
        "required": [
          "message",
          "code"
        ]
      }
    },
    "responses": {
      "Unauthenticated": {
        "description": "`unauthenticated`: missing, invalid, revoked or expired key.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PaymentRequired": {
        "description": "`subscription_required` (never paid) or `subscription_ended` (lapsed: reads still work).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "MissingAbility": {
        "description": "`missing_ability`: the key lacks documents:read (GET) or documents:write (everything else).",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "`not_found`: missing, or it belongs to another account.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Conflict": {
        "description": "`conflict`: the document changed since the `updated_at` / `X-Updated-At` you sent.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unprocessable": {
        "description": "`validation_failed` (see `errors`), `content_too_large`, `storage_limit` or `row_limit`.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "`rate_limited`: 60/min per key, 300/min across an account's keys.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        },
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait.",
            "schema": {
              "type": "integer"
            }
          }
        }
      }
    }
  }
}
