{
  "openapi": "3.0.3",
  "info": {
    "title": "Mailganer Email Fix API",
    "version": "0.1.0",
    "description": "Разбор опечаток в списке email по тем же правилам, что UI `/tools/email-fix` (#22503).\n\nПубличный REST (#21407): `POST /tools/email-fix/v1`. Анонимно — SmartCaptcha + квота IP. Партнёр — Bearer `tools_keys` service `email_fix`."
  },
  "servers": [
    {
      "url": "https://mailganer.com",
      "description": "Production"
    },
    {
      "url": "https://newland.mailganer.com",
      "description": "Staging"
    }
  ],
  "paths": {
    "/tools/email-fix/v1/status": {
      "get": {
        "summary": "Статус сервиса и квоты",
        "operationId": "emailFixStatus",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" },
                    "service": { "type": "string" },
                    "daily_limit": { "type": "integer" },
                    "remaining": { "type": "integer" },
                    "max_lines": { "type": "integer" },
                    "captcha_mode": { "type": "string" },
                    "captcha_site_key": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/tools/email-fix/v1": {
      "post": {
        "summary": "Разобрать список адресов",
        "operationId": "emailFixAnalyze",
        "security": [
          { "BearerAuth": [] },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "emails": {
                    "type": "array",
                    "items": { "type": "string" },
                    "maxItems": 500,
                    "description": "Массив строк. Альтернатива полю text."
                  },
                  "text": {
                    "type": "string",
                    "description": "Многострочный текст, по одному адресу или ячейке на строку."
                  },
                  "smart_token": {
                    "type": "string",
                    "description": "Yandex SmartCaptcha. Нужен без Bearer."
                  }
                }
              },
              "examples": {
                "emails": {
                  "value": {
                    "emails": ["test@gamil.com", "name-@mail.ru", "a@x.com;b@y.com"],
                    "smart_token": "<token>"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Результат разбора",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AnalyzeResult" }
              }
            }
          },
          "400": { "description": "Пустой батч или битый JSON" },
          "401": { "description": "Неверный Bearer" },
          "403": { "description": "Captcha failed" },
          "413": { "description": "Слишком много строк или тело" },
          "429": { "description": "Квота" },
          "503": { "description": "Captcha не настроена" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Ключ tools_keys с service=email_fix"
      }
    },
    "schemas": {
      "AnalyzeRow": {
        "type": "object",
        "properties": {
          "raw": { "type": "string" },
          "kind": {
            "type": "string",
            "enum": [
              "ok",
              "hyphen",
              "homoglyph",
              "latin_typo",
              "multi",
              "cyrillic_unknown",
              "invalid",
              "empty"
            ]
          },
          "reason": { "type": "string" },
          "suggestion": { "type": "string" },
          "fixable": { "type": "boolean" }
        }
      },
      "AnalyzeResult": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "rows": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/AnalyzeRow" }
          },
          "summary": {
            "type": "object",
            "properties": {
              "ok": { "type": "integer" },
              "suggest": { "type": "integer" },
              "reasonOnly": { "type": "integer" }
            }
          }
        }
      }
    }
  }
}
