From 70b2ba83ba566f141bc4ff632902641c2ab6f8b0 Mon Sep 17 00:00:00 2001 From: Alan Orth Date: Tue, 22 Dec 2020 12:50:03 +0200 Subject: [PATCH] Allow configuration of Swagger and OpenAPI JSON URL When running in production your statistics API might be deployed to a path like /rest/statistics instead of at the root. --- dspace_statistics_api/app.py | 8 ++++---- dspace_statistics_api/config.py | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dspace_statistics_api/app.py b/dspace_statistics_api/app.py index fe6ffa2..4e50d90 100644 --- a/dspace_statistics_api/app.py +++ b/dspace_statistics_api/app.py @@ -6,6 +6,8 @@ from .database import DatabaseManager from .stats import get_downloads, get_views from .util import set_statistics_scope, validate_post_parameters from .config import VERSION +from .config import SWAGGERUI_URL +from .config import SWAGGERUI_SCHEMA_URL class RootResource: @@ -198,14 +200,12 @@ api.add_route("/collections", AllStatisticsResource()) api.add_route("/collection/{id_:uuid}", SingleStatisticsResource()) # Swagger configuration -SWAGGERUI_URL = "/swagger" # without trailing slash -SCHEMA_URL = "/docs/openapi.json" -api.add_route("/docs/openapi.json", OpenAPIJSONResource()) +api.add_route(SWAGGERUI_SCHEMA_URL, OpenAPIJSONResource()) register_swaggerui_app( api, SWAGGERUI_URL, - SCHEMA_URL, + SWAGGERUI_SCHEMA_URL, config={ "supportedSubmitMethods": ["get", "post"], }, diff --git a/dspace_statistics_api/config.py b/dspace_statistics_api/config.py index 3fc33ca..f397be4 100644 --- a/dspace_statistics_api/config.py +++ b/dspace_statistics_api/config.py @@ -9,6 +9,13 @@ DATABASE_PASS = os.environ.get("DATABASE_PASS", "dspacestatistics") DATABASE_HOST = os.environ.get("DATABASE_HOST", "localhost") DATABASE_PORT = os.environ.get("DATABASE_PORT", "5432") +# SwaggerUI configuration + +# URI path where the Swagger UI should be available (without trailing slash) +SWAGGERUI_URL = os.environ.get("SWAGGERUI_URL", "/swagger") +# URI path to the OpenAPI JSON schema +SWAGGERUI_SCHEMA_URL = os.environ.get("SWAGGERUI_SCHEMA_URL", "/docs/openapi.json") + VERSION = "1.4.0-dev" # vim: set sw=4 ts=4 expandtab: