From a0bb9a069c7280b1b02eb1ffb43e25bb70191b15 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Wed, 9 Jul 2025 10:59:13 -0400 Subject: [PATCH 1/3] Improve swagger def --- libretranslate/app.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/libretranslate/app.py b/libretranslate/app.py index 022c53c..47d65c4 100644 --- a/libretranslate/app.py +++ b/libretranslate/app.py @@ -492,18 +492,19 @@ def create_app(args): @limiter.exempt def langs(): """ - Retrieve list of supported languages + Get Supported Languages --- tags: - translate responses: 200: - description: List of languages + description: List of supported languages schema: id: languages type: array items: type: object + description: Supported language properties: code: type: string @@ -539,7 +540,7 @@ def create_app(args): @access_check def translate(): """ - Translate text from a language to another + Translate Text --- tags: - translate @@ -560,7 +561,7 @@ def create_app(args): type: string example: en required: true - description: Source language code + description: Source language code or "auto" for auto detection - in: formData name: target schema: @@ -795,7 +796,7 @@ def create_app(args): @access_check def translate_file(): """ - Translate file from a language to another + Translate a File --- tags: - translate @@ -813,7 +814,7 @@ def create_app(args): type: string example: en required: true - description: Source language code + description: Source language code or "auto" for auto detection - in: formData name: target schema: @@ -1240,6 +1241,8 @@ def create_app(args): swag = swagger(app) swag["info"]["version"] = get_version() swag["info"]["title"] = "LibreTranslate" + swag["info"]["description"] = "Free and Open Source Machine Translation API." + swag["info"]["license"] = {"name": "AGPL-3.0"} @app.route(api_url) @limiter.exempt From 8b55f92b11dbf66401c7ed08d8421aec6daa8466 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Wed, 9 Jul 2025 11:22:46 -0400 Subject: [PATCH 2/3] Updated /translate definition --- libretranslate/app.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/libretranslate/app.py b/libretranslate/app.py index 47d65c4..c15c747 100644 --- a/libretranslate/app.py +++ b/libretranslate/app.py @@ -598,7 +598,7 @@ def create_app(args): description: API key responses: 200: - description: Translated text + description: Translation schema: id: translate type: object @@ -608,6 +608,41 @@ def create_app(args): - type: string - type: array description: Translated text(s) + detectedLanguage: + oneOf: + - type: object + properties: + confidence: + type: number + format: float + description: Confidence score (0-100) of the detected language + language: + type: string + description: Detected language code + - type: array + items: + type: object + properties: + confidence: + type: number + format: float + description: Confidence score (0-100) of the detected language + language: + type: string + description: Detected language code + alternatives: + oneOf: + - type: array + items: + type: string + - type: array + items: + type: array + items: + type: string + description: Alternative translations + required: + - translatedText 400: description: Invalid request schema: From b9b0c9e59969515232c761bac8cef6c0a1207a70 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Wed, 9 Jul 2025 16:16:12 -0400 Subject: [PATCH 3/3] Improve swagger definition --- VERSION | 2 +- libretranslate/app.py | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index 943f9cb..f8a696c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7.1 +1.7.2 diff --git a/libretranslate/app.py b/libretranslate/app.py index c15c747..2b090c2 100644 --- a/libretranslate/app.py +++ b/libretranslate/app.py @@ -615,10 +615,13 @@ def create_app(args): confidence: type: number format: float - description: Confidence score (0-100) of the detected language + minimum: 0 + maximum: 100 + description: Confidence value + example: 100 language: type: string - description: Detected language code + description: Language code - type: array items: type: object @@ -626,10 +629,13 @@ def create_app(args): confidence: type: number format: float - description: Confidence score (0-100) of the detected language + minimum: 0 + maximum: 100 + description: Confidence value + example: 100 language: type: string - description: Detected language code + description: Language code alternatives: oneOf: - type: array @@ -1006,7 +1012,7 @@ def create_app(args): @access_check def detect(): """ - Detect the language of a single text + Detect Language of Text --- tags: - translate @@ -1036,7 +1042,7 @@ def create_app(args): properties: confidence: type: number - format: integer + format: float minimum: 0 maximum: 100 description: Confidence value @@ -1097,10 +1103,10 @@ def create_app(args): @limiter.exempt def frontend_settings(): """ - Retrieve frontend specific settings + Retrieve Frontend Settings --- tags: - - frontend + - misc responses: 200: description: frontend settings @@ -1177,10 +1183,10 @@ def create_app(args): @bp.post("/suggest") def suggest(): """ - Submit a suggestion to improve a translation + Submit a Suggestion to Improve a Translation --- tags: - - feedback + - misc parameters: - in: formData name: q