{
  "openapi": "3.0.3",
  "info": {
    "title": "NEXONAPI File Translation",
    "version": "1.0.0",
    "description": "Translate PDF (up to 500 pages), DOC, DOCX, TXT and images. Uploads are limited to 128 MiB. Async jobs persist across service restarts and completed results are retained for up to 24 hours. URL inputs must be public HTTP(S) direct downloads. Private addresses and unsafe redirects are rejected."
  },
  "servers": [
    {
      "url": "http://127.0.0.1:13405",
      "description": "Default loopback address on the API host"
    }
  ],
  "paths": {
    "/openapi.json": {
      "get": {
        "summary": "Read the OpenAPI document",
        "responses": {
          "200": {
            "description": "OpenAPI document for this service.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          }
        }
      }
    },
    "/healthz": {
      "get": {
        "summary": "Check service health",
        "responses": {
          "200": {
            "description": "Service responds.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "status"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "ok"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/translate/file": {
      "get": {
        "summary": "Translate a file from a URL",
        "parameters": [
          {
            "$ref": "#/components/parameters/FileURL"
          },
          {
            "$ref": "#/components/parameters/Target"
          },
          {
            "$ref": "#/components/parameters/Source"
          },
          {
            "$ref": "#/components/parameters/Bilingual"
          },
          {
            "$ref": "#/components/parameters/Async"
          },
          {
            "$ref": "#/components/parameters/Format"
          }
        ],
        "responses": {
          "200": {
            "description": "Translation result or queued job receipt. A completed request without format=json returns an HTML download or text page.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              },
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadInput"
          },
          "413": {
            "$ref": "#/components/responses/InputTooLarge"
          },
          "422": {
            "$ref": "#/components/responses/Failed"
          },
          "429": {
            "$ref": "#/components/responses/QueueFull"
          },
          "500": {
            "$ref": "#/components/responses/StorageError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "post": {
        "summary": "Upload a file for translation",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/TranslationUpload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Translation result or queued job receipt. A completed request without format=json returns an HTML download or text page.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              },
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadInput"
          },
          "413": {
            "$ref": "#/components/responses/InputTooLarge"
          },
          "422": {
            "$ref": "#/components/responses/Failed"
          },
          "429": {
            "$ref": "#/components/responses/QueueFull"
          },
          "500": {
            "$ref": "#/components/responses/StorageError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/translate/file/async": {
      "get": {
        "summary": "Queue translation of a file URL",
        "parameters": [
          {
            "$ref": "#/components/parameters/FileURL"
          },
          {
            "$ref": "#/components/parameters/Target"
          },
          {
            "$ref": "#/components/parameters/Source"
          },
          {
            "$ref": "#/components/parameters/Bilingual"
          }
        ],
        "responses": {
          "200": {
            "description": "Accepted translation job. Follow status_url, then download_url or the translated text.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadInput"
          },
          "413": {
            "$ref": "#/components/responses/InputTooLarge"
          },
          "429": {
            "$ref": "#/components/responses/QueueFull"
          },
          "500": {
            "$ref": "#/components/responses/StorageError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      },
      "post": {
        "summary": "Upload and queue a file",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/TranslationUpload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted translation job. Follow status_url, then download_url or the translated text.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadInput"
          },
          "413": {
            "$ref": "#/components/responses/InputTooLarge"
          },
          "429": {
            "$ref": "#/components/responses/QueueFull"
          },
          "500": {
            "$ref": "#/components/responses/StorageError"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/translate/status/{job_id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/JobID"
        }
      ],
      "get": {
        "summary": "Get job progress",
        "responses": {
          "200": {
            "description": "Current status or final result. A failed job includes status=failed, success=false, and error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/translate/result/{job_id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/JobID"
        }
      ],
      "get": {
        "summary": "Get the translation result",
        "responses": {
          "200": {
            "description": "Current status or final result. A failed job includes status=failed, success=false, and error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/dl/{job_id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/JobID"
        }
      ],
      "get": {
        "summary": "Download a translated file",
        "responses": {
          "200": {
            "description": "Translated attachment.",
            "headers": {
              "Content-Disposition": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "206": {
            "description": "Requested byte range.",
            "content": {
              "application/octet-stream": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "416": {
            "description": "The requested byte range is unsatisfiable."
          }
        }
      },
      "head": {
        "summary": "Read translated-file download headers",
        "responses": {
          "200": {
            "description": "Translated attachment headers."
          },
          "404": {
            "description": "Job or download unavailable."
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "FileURL": {
        "name": "file",
        "in": "query",
        "description": "Public HTTP(S) direct download URL.",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uri",
          "maxLength": 8192
        }
      },
      "Target": {
        "name": "target",
        "in": "query",
        "description": "Target language code.",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8}){0,3}$",
          "example": "ar"
        }
      },
      "Source": {
        "name": "source",
        "in": "query",
        "description": "Source language code or auto detection.",
        "required": false,
        "schema": {
          "type": "string",
          "pattern": "^(auto|[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8}){0,3})$",
          "default": "auto"
        }
      },
      "Bilingual": {
        "name": "bilingual",
        "in": "query",
        "description": "Include original text alongside the translation where supported.",
        "required": false,
        "schema": {
          "type": "boolean",
          "default": false
        }
      },
      "Async": {
        "name": "async",
        "in": "query",
        "description": "Return a job receipt immediately. Otherwise wait for a small result before returning a job receipt.",
        "required": false,
        "schema": {
          "type": "boolean",
          "default": false
        }
      },
      "Format": {
        "name": "format",
        "in": "query",
        "description": "Use json for a JSON response when translation completes synchronously.",
        "required": false,
        "schema": {
          "type": "string",
          "enum": [
            "json"
          ]
        }
      },
      "JobID": {
        "name": "job_id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^[0-9a-f]{24}$"
        }
      }
    },
    "schemas": {
      "TranslationUpload": {
        "type": "object",
        "required": [
          "file",
          "target"
        ],
        "properties": {
          "file": {
            "type": "string",
            "format": "binary",
            "description": "Document or image, at most 128 MiB."
          },
          "target": {
            "type": "string",
            "pattern": "^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8}){0,3}$",
            "example": "ar"
          },
          "source": {
            "type": "string",
            "pattern": "^(auto|[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8}){0,3})$",
            "default": "auto"
          },
          "bilingual": {
            "type": "boolean",
            "default": false
          },
          "async": {
            "type": "boolean",
            "default": false
          },
          "format": {
            "type": "string",
            "enum": [
              "json"
            ]
          }
        }
      },
      "Job": {
        "type": "object",
        "required": [
          "success",
          "job_id",
          "status",
          "progress",
          "status_url",
          "result_url"
        ],
        "properties": {
          "success": {
            "type": "boolean"
          },
          "job_id": {
            "type": "string",
            "pattern": "^[0-9a-f]{24}$"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "processing",
              "done",
              "failed"
            ]
          },
          "progress": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "status_url": {
            "type": "string",
            "format": "uri-reference",
            "description": "Job status URL. The HTTPS gateway returns a full URL."
          },
          "result_url": {
            "type": "string",
            "format": "uri-reference",
            "description": "Job result URL. The HTTPS gateway returns a full URL."
          },
          "download_url": {
            "type": "string",
            "format": "uri-reference",
            "description": "File download URL when ready. The HTTPS gateway returns a full URL."
          },
          "text": {
            "type": "string",
            "description": "Translated text returned for an image result."
          },
          "error": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "success",
          "progress",
          "error"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "progress": {
            "type": "integer",
            "minimum": 0,
            "maximum": 100
          },
          "error": {
            "type": "string"
          }
        }
      }
    },
    "responses": {
      "BadInput": {
        "description": "Missing or invalid input or language.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Job or download is unknown or expired.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "InputTooLarge": {
        "description": "Upload exceeds the limit.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "QueueFull": {
        "description": "The translation queue is full.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "StorageError": {
        "description": "Could not save the input.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unavailable": {
        "description": "The translation service cannot currently accept the job.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Failed": {
        "description": "The accepted synchronous translation failed.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Job"
            }
          }
        }
      }
    }
  }
}
