{
  "openapi": "3.1.0",
  "info": {
    "title": "PDFxtract",
    "version": "1.1.0",
    "description": "Ключ из кабинета передаётся по HTTPS в Authorization: Bearer <token>. Для браузерных изменений с cookie передайте заголовок X-CSRFToken."
  },
  "servers": [
    {
      "url": "/api/v1"
    }
  ],
  "security": [
    {
      "token": []
    }
  ],
  "components": {
    "securitySchemes": {
      "token": {
        "type": "http",
        "scheme": "bearer"
      },
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "sessionid"
      },
      "csrf": {
        "type": "apiKey",
        "in": "header",
        "name": "X-CSRFToken"
      }
    },
    "schemas": {
      "BatchInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 150
          },
          "fields": {
            "type": "array",
            "items": {
              "oneOf": [
                {
                  "type": "string",
                  "maxLength": 100
                },
                {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string",
                      "maxLength": 100
                    },
                    "type": {
                      "enum": [
                        "text",
                        "identifier",
                        "date",
                        "money",
                        "integer",
                        "number",
                        "numeric",
                        "decimal"
                      ]
                    }
                  },
                  "required": [
                    "name"
                  ]
                }
              ]
            },
            "minItems": 1,
            "maxItems": 30
          },
          "mode": {
            "enum": [
              "standard",
              "advanced"
            ]
          },
          "instructions": {
            "type": "string",
            "maxLength": 1000
          },
          "field_types": {
            "type": "object",
            "additionalProperties": {
              "enum": [
                "text",
                "identifier",
                "date",
                "money",
                "integer",
                "number",
                "numeric",
                "decimal"
              ]
            }
          },
          "template_id": {
            "type": "integer"
          },
          "template_version": {
            "type": "integer"
          },
          "field_pages": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "minItems": 1,
              "maxItems": 100,
              "items": {
                "type": "integer",
                "minimum": 1,
                "maximum": 100
              }
            }
          }
        },
        "anyOf": [
          {
            "required": [
              "fields"
            ]
          },
          {
            "required": [
              "template_id"
            ]
          }
        ]
      },
      "Batch": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "enum": [
              "draft",
              "queued",
              "processing",
              "completed",
              "partial",
              "failed",
              "cancelled"
            ]
          },
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Document"
            }
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Result"
            }
          },
          "field_types": {
            "type": "object"
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "task_id": { "type": "integer" },
                "index": { "type": "integer", "minimum": 0 },
                "revision": { "type": "integer", "minimum": 0 },
                "document_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "filename": {
                  "type": "string"
                },
                "page": {
                  "type": "integer"
                },
                "item": {
                  "type": "object",
                  "properties": {
                    "description": {
                      "type": "string"
                    },
                    "quantity": {
                      "type": [
                        "string",
                        "number",
                        "boolean",
                        "null"
                      ]
                    },
                    "unit_price": {
                      "type": [
                        "string",
                        "number",
                        "boolean",
                        "null"
                      ]
                    },
                    "total": {
                      "type": [
                        "string",
                        "number",
                        "boolean",
                        "null"
                      ]
                    },
                    "page": {
                      "type": "integer"
                    },
                    "status": {
                      "enum": [
                        "verified",
                        "review"
                      ]
                    },
                    "bbox": {
                      "anyOf": [
                        {
                          "type": "array",
                          "items": {
                            "type": "number",
                            "minimum": 0,
                            "maximum": 1
                          },
                          "minItems": 4,
                          "maxItems": 4
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "source": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "pages": {
            "type": "array",
            "description": "Состояние и режим обработки каждой страницы.",
            "items": {
              "type": "object",
              "required": [
                "document_id",
                "page",
                "status",
                "mode",
                "metadata"
              ],
              "properties": {
                "document_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "page": {
                  "type": "integer",
                  "minimum": 1
                },
                "status": {
                  "type": "string"
                },
                "mode": {"enum": ["standard", "advanced"]},
                "metadata": {
                  "type": "object",
                  "properties": {
                    "units": {
                      "type": "object",
                      "additionalProperties": {"type": "string", "pattern": "^[A-Z]{3}$"}
                    }
                  }
                }
              }
            }
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "filename": {
                  "type": "string"
                },
                "page": {
                  "type": "integer"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          },
          "spent": {
            "type": "integer"
          },
          "quoted": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "mode": {
            "enum": [
              "standard",
              "advanced"
            ]
          },
          "document_count": {
            "type": "integer"
          },
          "page_count": {
            "type": "integer"
          },
          "done_pages": {
            "type": "integer"
          },
          "field_count": {
            "type": "integer"
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "instructions": {
            "type": "string"
          },
          "quote_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "template_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "template_version": {
            "type": [
              "integer",
              "null"
            ]
          },
          "result_version": {
            "type": "integer"
          },
          "results_expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "field_pages": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "minItems": 1,
              "maxItems": 100,
              "items": {
                "type": "integer",
                "minimum": 1,
                "maximum": 100
              }
            }
          }
        }
      },
      "Document": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "pages": {
            "type": "integer"
          },
          "selected_pages": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "advanced_pages": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "expired": {
            "type": "boolean"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "kind": {
            "enum": [
              "pdf",
              "image"
            ]
          }
        }
      },
      "Result": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "document_id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "enum": [
              "verified",
              "missing",
              "review",
              "corrected"
            ]
          },
          "value": {
            "type": [
              "string",
              "number",
              "boolean",
              "null"
            ]
          },
          "page": {
            "type": "integer"
          },
          "bbox": {
            "anyOf": [
              {
                "type": "array",
                "items": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "minItems": 4,
                "maxItems": 4
              },
              {
                "type": "null"
              }
            ]
          },
          "filename": {
            "type": "string"
          },
          "raw": {
            "type": [
              "string",
              "null"
            ]
          },
          "source": {
            "type": "string"
          },
          "history": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "previous": {
                  "type": [
                    "string",
                    "number",
                    "boolean",
                    "null"
                  ]
                },
                "value": {
                  "type": [
                    "string",
                    "number",
                    "boolean",
                    "null"
                  ]
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                },
                "id": {
                  "type": "integer"
                },
                "action": {
                  "enum": [
                    "set",
                    "undo"
                  ]
                },
                "reverts_id": {
                  "type": [
                    "integer",
                    "null"
                  ]
                },
                "can_undo": {
                  "type": "boolean"
                }
              }
            }
          },
          "reason": {
            "type": "string",
            "description": "Причина ручной проверки, когда она известна"
          },
          "undo_edit_id": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Quote": {
        "type": "object",
        "properties": {
          "quote_id": {
            "type": "string"
          },
          "balance": {
            "type": "integer"
          },
          "pages": {
            "type": "integer"
          },
          "credits": {
            "type": "integer"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "breakdown": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "document_id": {
                  "type": "string",
                  "format": "uuid"
                },
                "page": {
                  "type": "integer"
                },
                "mode": {
                  "enum": [
                    "standard",
                    "advanced"
                  ]
                },
                "credits": {
                  "enum": [
                    1,
                    3
                  ]
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "BatchSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "status": {
            "enum": [
              "draft",
              "queued",
              "processing",
              "completed",
              "partial",
              "failed",
              "cancelled"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "mode": {
            "enum": [
              "standard",
              "advanced"
            ]
          },
          "document_count": {
            "type": "integer"
          },
          "page_count": {
            "type": "integer"
          },
          "done_pages": {
            "type": "integer"
          },
          "field_count": {
            "type": "integer"
          },
          "spent": {
            "type": "integer"
          },
          "quoted": {
            "type": "integer"
          },
          "template_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "template_version": {
            "type": [
              "integer",
              "null"
            ]
          },
          "result_version": {
            "type": "integer"
          },
          "results_expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Upload": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Batch"
          },
          {
            "type": "object",
            "properties": {
              "uploaded_count": {"type": "integer", "minimum": 0},
              "upload_duplicates": {
                "type": "array",
                "items": {
                  "type": "object",
                  "required": ["filename", "existing_filename"],
                  "properties": {
                    "filename": {"type": "string"},
                    "existing_filename": {"type": "string"}
                  }
                }
              },
              "upload_errors": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "filename": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        ]
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "instructions": {
            "type": "string"
          },
          "field_types": {
            "type": "object",
            "additionalProperties": {
              "enum": [
                "text",
                "identifier",
                "date",
                "money",
                "integer",
                "number",
                "numeric",
                "decimal"
              ]
            }
          },
          "mode": {
            "enum": [
              "standard",
              "advanced"
            ]
          },
          "version": {
            "type": "integer"
          },
          "field_pages": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "minItems": 1,
              "maxItems": 100,
              "items": {
                "type": "integer",
                "minimum": 1,
                "maximum": 100
              }
            }
          }
        }
      },
      "Token": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "scopes": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "enum": [
                "read",
                "write",
                "run",
                "delete"
              ]
            }
          }
        }
      },
      "TemplateVersion": {
        "type": "object",
        "properties": {
          "version": {
            "type": "integer"
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "name": {
            "type": "string"
          },
          "fields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "instructions": {
            "type": "string"
          },
          "field_types": {
            "type": "object",
            "additionalProperties": {
              "enum": [
                "text",
                "identifier",
                "date",
                "money",
                "integer",
                "number",
                "numeric",
                "decimal"
              ]
            }
          },
          "mode": {
            "enum": [
              "standard",
              "advanced"
            ]
          },
          "field_pages": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "minItems": 1,
              "maxItems": 100,
              "items": {
                "type": "integer",
                "minimum": 1,
                "maximum": 100
              }
            }
          }
        }
      },
      "TemplateDetail": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Template"
          },
          {
            "type": "object",
            "properties": {
              "versions": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/TemplateVersion"
                }
              }
            }
          }
        ]
      }
    }
  },
  "paths": {
    "/me": {
      "get": {
        "summary": "Аккаунт и баланс",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "username": {
                      "type": "string"
                    },
                    "balance": {
                      "type": "integer"
                    },
                    "templates": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Template"
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "security": [
          {
            "token": []
          },
          {
            "session": []
          }
        ],
        "x-token-scope": "read"
      }
    },
    "/batches": {
      "get": {
        "summary": "Список партий",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "batches": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/BatchSummary"
                      }
                    },
                    "next_offset": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {"name": "q", "in": "query", "description": "Часть названия партии", "schema": {"type": "string"}},
          {"name": "status", "in": "query", "description": "Состояние партии или errors для партий с ошибками", "schema": {"enum": ["draft", "queued", "processing", "completed", "partial", "failed", "cancelled", "errors"]}},
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": []
          }
        ],
        "x-token-scope": "read"
      },
      "post": {
        "summary": "Создать партию",
        "responses": {
          "200": {
            "description": "Партия, ранее созданная с этим ключом",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "201": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BatchInput"
              }
            }
          }
        },
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "write"
      }
    },
    "/batches/{id}": {
      "get": {
        "summary": "Результат партии",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": []
          }
        ],
        "x-token-scope": "read"
      },
      "patch": {
        "summary": "Редактировать черновик",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "maxLength": 150
                  },
                  "fields": {
                    "type": "array",
                    "items": {
                      "oneOf": [
                        {
                          "type": "string",
                          "maxLength": 100
                        },
                        {
                          "type": "object",
                          "properties": {
                            "name": {
                              "type": "string",
                              "maxLength": 100
                            },
                            "type": {
                              "enum": [
                                "text",
                                "identifier",
                                "date",
                                "money",
                                "integer",
                                "number",
                                "numeric",
                                "decimal"
                              ]
                            }
                          },
                          "required": [
                            "name"
                          ]
                        }
                      ]
                    },
                    "minItems": 1,
                    "maxItems": 30
                  },
                  "mode": {
                    "enum": [
                      "standard",
                      "advanced"
                    ]
                  },
                  "instructions": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "field_types": {
                    "type": "object",
                    "additionalProperties": {
                      "enum": [
                        "text",
                        "identifier",
                        "date",
                        "money",
                        "integer",
                        "number",
                        "numeric",
                        "decimal"
                      ]
                    }
                  },
                  "template_id": {
                    "type": "integer"
                  },
                  "template_version": {
                    "type": "integer"
                  },
                  "field_pages": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "array",
                      "minItems": 1,
                      "maxItems": 100,
                      "items": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 100
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "write"
      },
      "delete": {
        "summary": "Удалить партию",
        "responses": {
          "204": {
            "description": "Успешный ответ"
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "delete"
      }
    },
    "/batches/{id}/documents": {
      "post": {
        "summary": "Загрузить документы",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Upload"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                },
                "required": [
                  "files"
                ]
              }
            }
          }
        },
        "description": "PDF, PNG или JPEG. До 25 МиБ на файл, 64 МиБ на запрос, до 25 файлов в партии.",
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "write"
      }
    },
    "/batches/{id}/documents/{doc_id}": {
      "patch": {
        "summary": "Выбрать страницы",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "selected_pages": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    }
                  },
                  "advanced_pages": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "doc_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "write"
      },
      "delete": {
        "summary": "Удалить документ из черновика",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "doc_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "delete"
      }
    },
    "/batches/{id}/documents/{doc_id}/pages/{page}": {
      "get": {
        "summary": "Просмотреть страницу",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "doc_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "page",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": []
          }
        ],
        "x-token-scope": "read"
      }
    },
    "/batches/{id}/quote": {
      "post": {
        "summary": "Рассчитать стоимость",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Quote"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "run"
      }
    },
    "/batches/{id}/run": {
      "post": {
        "summary": "Начать обработку",
        "responses": {
          "202": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Batch"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "job_id": {
                          "type": "string",
                          "format": "uuid"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "quote_id": {
                    "type": "string"
                  }
                },
                "required": [
                  "quote_id"
                ]
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "header",
            "name": "Idempotency-Key",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "run"
      }
    },
    "/batches/{id}/cancel": {
      "post": {
        "summary": "Отменить оставшиеся страницы",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "run"
      }
    },
    "/batches/{id}/retry": {
      "post": {
        "summary": "Подготовить повтор",
        "responses": {
          "201": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "run"
      }
    },
    "/batches/{id}/items/{task_id}/{index}": {
      "parameters": [
        {"name":"id","in":"path","required":true,"schema":{"type":"string","format":"uuid"}},
        {"name":"task_id","in":"path","required":true,"schema":{"type":"integer","minimum":1}},
        {"name":"index","in":"path","required":true,"schema":{"type":"integer","minimum":0}}
      ],
      "get": {
        "summary": "История правок товарной строки",
        "security": [{"token":[]},{"session":[]}],
        "parameters": [{"name":"offset","in":"query","schema":{"type":"integer","minimum":0}}],
        "responses": {
          "200":{"description":"До 50 правок по убыванию даты","content":{"application/json":{"schema":{
            "type":"object","properties":{
              "history":{"type":"array","items":{"type":"object","properties":{
                "id":{"type":"integer"},"previous":{"type":"object"},"values":{"type":"object"},"at":{"type":"string","format":"date-time"}
              }}},
              "next_offset":{"type":["integer","null"]}
            }
          }}}},
          "404":{"description":"Товарная строка не найдена"}
        }
      },
      "patch": {
        "summary":"Исправить товарную строку или вернуть значения до выбранной правки",
        "security":[{"token":[]},{"session":[],"csrf":[]}],
        "requestBody":{"required":true,"content":{"application/json":{"schema":{
          "type":"object","required":["revision"],"oneOf":[{"required":["values"]},{"required":["restore_edit"]}],
          "properties":{
            "revision":{"type":"integer","minimum":0},
            "restore_edit":{"type":"integer","minimum":1},
            "values":{"type":"object","minProperties":1,"additionalProperties":false,"properties":{
              "description":{"type":"string","minLength":1,"maxLength":4000},
              "quantity":{"type":["number","string","null"]},"unit_price":{"type":["number","string","null"]},"total":{"type":["number","string","null"]}
            }}
          }
        }}}},
        "responses":{
          "200":{"description":"Версия строки и общая версия результата партии","content":{"application/json":{"schema":{
            "type":"object","properties":{"revision":{"type":"integer"},"result_version":{"type":"integer"}}
          }}}},
          "400":{"description":"Неверные поля или значения"},
          "404":{"description":"Товарная строка не найдена"},
          "409":{"description":"Значения изменились после чтения строки"}
        }
      }
    },
    "/batches/{id}/results/{rid}": {
      "patch": {
        "summary": "Исправить значение",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "value": {
                    "type": [
                      "string",
                      "number",
                      "boolean",
                      "null"
                    ]
                  }
                },
                "required": [
                  "value"
                ]
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "rid",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "write"
      }
    },
    "/batches/{id}/export": {
      "get": {
        "summary": "Скачать таблицу",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "X-Result-Version": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "format",
            "schema": {
              "enum": [
                "csv",
                "xlsx"
              ]
            }
          },
          {
            "in": "query",
            "name": "table",
            "schema": {
              "enum": [
                "documents",
                "items"
              ]
            }
          },
          {
            "in": "query",
            "name": "ticket",
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": []
          }
        ],
        "x-token-scope": "read"
      }
    },
    "/templates": {
      "get": {
        "summary": "Библиотека шаблонов",
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "templates": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Template"
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "security": [
          {
            "token": []
          },
          {
            "session": []
          }
        ],
        "x-token-scope": "read"
      },
      "post": {
        "summary": "Сохранить шаблон",
        "responses": {
          "201": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Template"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/BatchInput"
                  },
                  {
                    "required": [
                      "fields"
                    ]
                  }
                ]
              }
            }
          }
        },
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "write"
      }
    },
    "/templates/{tid}": {
      "delete": {
        "summary": "Удалить шаблон",
        "responses": {
          "204": {
            "description": "Успешный ответ"
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "tid",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "x-token-scope": "delete"
      },
      "get": {
        "summary": "Схема и версии шаблона",
        "parameters": [
          {
            "in": "path",
            "name": "tid",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateDetail"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "x-token-scope": "read"
      },
      "patch": {
        "summary": "Сохранить следующую версию шаблона",
        "parameters": [
          {
            "in": "path",
            "name": "tid",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateDetail"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "version": {
                    "type": "integer"
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 150
                  },
                  "fields": {
                    "type": "array",
                    "items": {
                      "oneOf": [
                        {
                          "type": "string",
                          "maxLength": 100
                        },
                        {
                          "type": "object",
                          "properties": {
                            "name": {
                              "type": "string",
                              "maxLength": 100
                            },
                            "type": {
                              "enum": [
                                "text",
                                "identifier",
                                "date",
                                "money",
                                "integer",
                                "number",
                                "numeric",
                                "decimal"
                              ]
                            }
                          },
                          "required": [
                            "name"
                          ]
                        }
                      ]
                    },
                    "minItems": 1,
                    "maxItems": 30
                  },
                  "mode": {
                    "enum": [
                      "standard",
                      "advanced"
                    ]
                  },
                  "instructions": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "field_types": {
                    "type": "object",
                    "additionalProperties": {
                      "enum": [
                        "text",
                        "identifier",
                        "date",
                        "money",
                        "integer",
                        "number",
                        "numeric",
                        "decimal"
                      ]
                    }
                  },
                  "field_pages": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "array",
                      "minItems": 1,
                      "maxItems": 100,
                      "items": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 100
                      }
                    }
                  }
                },
                "required": [
                  "version"
                ]
              }
            }
          }
        },
        "x-token-scope": "write"
      }
    },
    "/tokens": {
      "get": {
        "summary": "Ключи API текущего пользователя",
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tokens": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Token"
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Выпустить токен из кабинета",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 80
                  },
                  "scopes": {
                    "type": "array",
                    "minItems": 1,
                    "uniqueItems": true,
                    "items": {
                      "enum": [
                        "read",
                        "write",
                        "run",
                        "delete"
                      ]
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "integer"
                    },
                    "name": {
                      "type": "string"
                    },
                    "token": {
                      "type": "string"
                    },
                    "scopes": {
                      "type": "array",
                      "minItems": 1,
                      "uniqueItems": true,
                      "items": {
                        "enum": [
                          "read",
                          "write",
                          "run",
                          "delete"
                        ]
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/tokens/{tid}": {
      "delete": {
        "summary": "Отозвать токен из кабинета",
        "security": [
          {
            "session": [],
            "csrf": []
          }
        ],
        "parameters": [
          {
            "name": "tid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Отозван"
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/batches/{id}/results/{rid}/history": {
      "get": {
        "summary": "История исправлений",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "rid",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "history": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "previous": {
                            "type": [
                              "string",
                              "number",
                              "boolean",
                              "null"
                            ]
                          },
                          "value": {
                            "type": [
                              "string",
                              "number",
                              "boolean",
                              "null"
                            ]
                          },
                          "at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "id": {
                            "type": "integer"
                          },
                          "action": {
                            "enum": [
                              "set",
                              "undo"
                            ]
                          },
                          "reverts_id": {
                            "type": [
                              "integer",
                              "null"
                            ]
                          },
                          "can_undo": {
                            "type": "boolean"
                          }
                        }
                      }
                    },
                    "next_offset": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "x-token-scope": "read"
      }
    },
    "/batches/{id}/results/{rid}/undo": {
      "post": {
        "summary": "Отменить последнее действующее исправление",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "rid",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Batch"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "edit_id": {
                    "type": "integer"
                  }
                },
                "required": [
                  "edit_id"
                ]
              }
            }
          }
        },
        "x-token-scope": "write"
      }
    },
    "/batches/{id}/export-link": {
      "post": {
        "summary": "Ссылка на текущую версию результата на пять минут",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string"
                    },
                    "version": {
                      "type": "integer"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "x-token-scope": "read",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "format": {
                    "enum": [
                      "csv",
                      "xlsx"
                    ]
                  },
                  "table": {
                    "enum": [
                      "documents",
                      "items"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    "/batches/{id}/documents/{doc_id}/original-link": {
      "post": {
        "summary": "Получить ссылку на исходный файл",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "doc_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": [],
            "csrf": []
          }
        ],
        "responses": {
          "200": {
            "description": "Успешный ответ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string"
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "x-token-scope": "read"
      }
    },
    "/batches/{id}/documents/{doc_id}/original": {
      "get": {
        "summary": "Скачать исходный файл в течение срока ссылки",
        "responses": {
          "200": {
            "description": "Исходный загруженный файл",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "default": {
            "description": "Ошибка запроса",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Превышен лимит запросов",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "doc_id",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "ticket",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "security": [
          {
            "token": []
          },
          {
            "session": []
          }
        ],
        "x-token-scope": "read"
      }
    }
  }
}
