{
  "openapi": "3.0.0",
  "info": {
    "title": "API Проверки Контента",
    "version": "0.0.1",
    "description": "API для проверки контента на наличие запрещенных слов.\n\n## Авторизация\nДля использования API требуется Access Token и API Key (купленный ключ). Access Token передается в заголовке `Authorization: Bearer <your_jwt_token>`, а API Key передается в поле `token` в теле запроса или в параметрах запроса.\n\nДля получения Access Token, пожалуйста, свяжитесь с поддержкой: support@normaslov.ru\nКупить API Key можно на странице [/payment](/payment)\nИнтеграция по API возможна при покупке от `200 000 символов`.\n\n## Порядок использования API\n\n### 1. Текст или Ссылка\n1. `POST /api/external/v1/validations` - Отправьте запрос с типом `text` или `link`. Обязательно передайте `token` (ваш ключ).\n2. `GET /api/external/v1/validations/{id}` - Проверьте статус и результат по ID.\n\n### 2. Файлы\n1. `POST /api/external/v1/validations` - Отправьте запрос с типом `file`. Передайте `token`. Получите `uploadToken`.\n2. `POST /api/external/v1/validations/upload` - Загрузите файл, передав `uploadToken` в теле запроса.\n3. `GET /api/external/v1/validations/{id}` - Проверьте статус и результат по ID.\n\n### 3. Дополнительно\n- `GET /api/external/v1/tokens/stats` - Проверка остатка символов по ключу.\n- `GET /api/external/v1/tokens/history` - История всех ваших проверок по ключу.\n\n## Лимиты Использования\n- **RPS**: 10 запросов в секунду.\n\n## Поддержка Контента\n- **Текст**: Прямая отправка текста.\n- **Файл**: Форматы PDF, DOCX, TXT (до 5МБ).\n- **Ссылка**: URL на внешний контент."
  },
  "tags": [
    {
      "name": "Validations",
      "description": "Операции проверки контента."
    },
    {
      "name": "Tokens",
      "description": "Операции с токенами."
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": false
          },
          "error": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string",
                "example": "Неверные параметры запроса"
              },
              "code": {
                "type": "string",
                "example": "error"
              }
            }
          }
        }
      },
      "TokenStatisticsResponse": {
        "type": "object",
        "properties": {
          "remainingSymbols": {
            "type": "integer",
            "description": "Остаток символов."
          }
        }
      },
      "TokenHistoryEntry": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "symbolsUsed": {
            "type": "integer"
          },
          "type": {
            "type": "string"
          },
          "info": {
            "type": "string",
            "nullable": true
          },
          "usedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "TokenHistoryData": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TokenHistoryEntry"
            }
          },
          "hasMore": {
            "type": "boolean"
          }
        }
      },
      "ValidationCreatedResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "type": {
            "type": "string",
            "enum": ["text", "file", "link"]
          },
          "status": {
            "type": "string",
            "enum": ["pending", "processing", "completed", "failed"]
          },
          "submittedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ValidationDetailedResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "type": {
            "type": "string",
            "enum": ["text", "file", "link"]
          },
          "status": {
            "type": "string",
            "enum": ["pending", "processing", "completed", "failed"]
          },
          "hasProhibitedWords": {
            "type": "boolean"
          },
          "submittedAt": {
            "type": "string",
            "format": "date-time"
          },
          "completedAt": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "statistics": {
            "type": "object",
            "properties": {
              "symbolCount": {
                "type": "integer"
              },
              "used": {
                "type": "integer"
              },
              "prohibitedWordCount": {
                "type": "integer"
              }
            }
          },
          "prohibitedWords": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "start": {
                  "type": "integer"
                },
                "end": {
                  "type": "integer"
                },
                "word": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "TextValidationRequest": {
        "type": "object",
        "required": ["type", "content", "token"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["text"],
            "description": "Тип контента."
          },
          "content": {
            "type": "string",
            "description": "Текст для проверки."
          },
          "token": {
            "type": "string",
            "description": "Ключ доступа (bearer токен также поддерживается в заголовке)."
          }
        }
      },
      "FileValidationRequest": {
        "type": "object",
        "required": ["type", "token"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["file"],
            "description": "Тип контента."
          },
          "token": {
            "type": "string",
            "description": "Ключ доступа."
          }
        },
        "description": "После создания этой заявки, используйте /validations/upload для загрузки файла."
      },
      "LinkValidationRequest": {
        "type": "object",
        "required": ["type", "link", "token"],
        "properties": {
          "type": {
            "type": "string",
            "enum": ["link"],
            "description": "Тип контента."
          },
          "link": {
            "type": "string",
            "format": "uri",
            "description": "URL для проверки."
          },
          "token": {
            "type": "string",
            "description": "Ключ доступа."
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/api/external/v1/validations": {
      "post": {
        "tags": ["Validations"],
        "summary": "Создать новую проверку",
        "description": "Отправить текст, ссылку или файл на проверку.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/TextValidationRequest"
                  },
                  {
                    "$ref": "#/components/schemas/FileValidationRequest"
                  },
                  {
                    "$ref": "#/components/schemas/LinkValidationRequest"
                  }
                ]
              },
              "examples": {
                "Text": {
                  "summary": "Проверка текста",
                  "value": {
                    "type": "text",
                    "content": "Пример текста для проверки на наличие запрещенных слов.",
                    "token": "купленный_ключ"
                  }
                },
                "File": {
                  "summary": "Проверка файла",
                  "value": {
                    "type": "file",
                    "token": "купленный_ключ"
                  }
                },
                "Link": {
                  "summary": "Проверка ссылки",
                  "value": {
                    "type": "link",
                    "link": "https://example.com",
                    "token": "купленный_ключ"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Проверка успешно создана.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "oneOf": [
                        {
                          "$ref": "#/components/schemas/ValidationCreatedResponse"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "validation": {
                              "$ref": "#/components/schemas/ValidationCreatedResponse"
                            },
                            "uploadToken": {
                              "type": "string"
                            },
                            "expiresIn": {
                              "type": "integer"
                            }
                          }
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Неверные параметры запроса.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Слишком много запросов.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Превышен лимит запросов. Пожалуйста, попробуйте позже.",
                    "code": "rate_limit_exceeded"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Внутренняя ошибка сервера.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Произошла внутренняя ошибка сервера.",
                    "code": "internal_error"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/external/v1/validations/upload": {
      "post": {
        "tags": ["Validations"],
        "summary": "Загрузить файл для проверки",
        "description": "Загрузить бинарный файл для ранее созданной проверки, используя токен загрузки. Максимальный размер файла: 5МБ.",
        "parameters": [
          {
            "in": "header",
            "name": "X-Upload-Token",
            "schema": {
              "type": "string"
            },
            "required": true,
            "description": "Токен, полученный при создании проверки."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Файл успешно загружен.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "type": "object",
                      "nullable": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Неверный файл или отсутствует токен.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Слишком много запросов.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Превышен лимит запросов.",
                    "code": "rate_limit_exceeded"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Внутренняя ошибка сервера.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Внутренняя ошибка сервера.",
                    "code": "internal_error"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/external/v1/validations/{id}": {
      "get": {
        "tags": ["Validations"],
        "summary": "Получить детали проверки",
        "description": "Получить статус и результаты проверки.",
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "required": true,
            "description": "ID проверки."
          }
        ],
        "responses": {
          "200": {
            "description": "Детали проверки успешно получены.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/ValidationDetailedResponse"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Неверный формат ID.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Проверка не найдена.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Проверка не найдена",
                    "code": "not_found"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Слишком много запросов.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Превышен лимит запросов.",
                    "code": "rate_limit_exceeded"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Внутренняя ошибка сервера.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Внутренняя ошибка сервера.",
                    "code": "internal_error"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/external/v1/tokens/stats": {
      "get": {
        "tags": ["Tokens"],
        "summary": "Получить статистику ключей",
        "description": "Возвращает информацию о ключе.",
        "parameters": [
          {
            "in": "query",
            "name": "token",
            "schema": {
              "type": "string"
            },
            "required": true,
            "description": "Ключ"
          }
        ],
        "responses": {
          "200": {
            "description": "Статистика успешно получена.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/TokenStatisticsResponse"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Неавторизованный запрос.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Слишком много запросов.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Превышен лимит запросов.",
                    "code": "rate_limit_exceeded"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Внутренняя ошибка сервера.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Внутренняя ошибка сервера.",
                    "code": "internal_error"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/external/v1/tokens/history": {
      "get": {
        "tags": ["Tokens"],
        "summary": "Получить историю использования ключа",
        "description": "Возвращает список проверок, выполненных с использованием данного ключа.",
        "parameters": [
          {
            "in": "query",
            "name": "token",
            "schema": {
              "type": "string"
            },
            "required": true,
            "description": "Ключ"
          },
          {
            "in": "query",
            "name": "page",
            "schema": {
              "type": "integer",
              "default": 1
            },
            "required": false,
            "description": "Номер страницы."
          },
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "default": 20
            },
            "required": false,
            "description": "Количество записей на странице."
          }
        ],
        "responses": {
          "200": {
            "description": "История успешно получена.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "message": {
                      "type": "string"
                    },
                    "data": {
                      "$ref": "#/components/schemas/TokenHistoryData"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Неавторизованный запрос.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Слишком много запросов.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Превышен лимит запросов.",
                    "code": "rate_limit_exceeded"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Внутренняя ошибка сервера.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                },
                "example": {
                  "success": false,
                  "error": {
                    "message": "Внутренняя ошибка сервера.",
                    "code": "internal_error"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
