From eda63acec92d1d09c9c60a9cddfbedbbf951d282 Mon Sep 17 00:00:00 2001 From: Shivraj Suman <79820642+shivraj1182@users.noreply.github.com> Date: Tue, 27 Jan 2026 12:53:03 +0530 Subject: [PATCH 1/5] feat: Add drf-spectacular for OpenAPI/Swagger documentation Add drf-spectacular (>=2.0.0) to requirements.txt to enable OpenAPI/Swagger schema generation for BuffaLogs REST APIs. This addresses issue #541 by adding the foundation for comprehensive interactive API documentation. --- buffalogs/requirements.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/buffalogs/requirements.txt b/buffalogs/requirements.txt index 77bf9b38..92c9ddc2 100644 --- a/buffalogs/requirements.txt +++ b/buffalogs/requirements.txt @@ -42,4 +42,7 @@ backoff>=2.2.1 # Library for retrying operations with exponent requests>=2.32.5 # HTTP library for sending alerts and webhooks # === Web Server === -uwsgi>=2.0.31 # uWSGI application server for serving Django application \ No newline at end of file +uwsgi>=2.0.31 # uWSGI application server for serving Django application + +# === API Documentation === +drf-spectacular>=2.0.0 # OpenAPI/Swagger schema generation for Django REST Framework From e744f9a77c5b2dcbd71cc669a9899f3efe4eb86e Mon Sep 17 00:00:00 2001 From: Shivraj Suman <79820642+shivraj1182@users.noreply.github.com> Date: Tue, 27 Jan 2026 12:55:45 +0530 Subject: [PATCH 2/5] feat: Configure drf-spectacular in settings - Add drf_spectacular to INSTALLED_APPS - Configure REST_FRAMEWORK with DEFAULT_SCHEMA_CLASS - Add SPECTACULAR_SETTINGS with API metadata (title, description, version) Part of issue #541 --- buffalogs/buffalogs/settings/settings.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/buffalogs/buffalogs/settings/settings.py b/buffalogs/buffalogs/settings/settings.py index b4adfad7..c0f88679 100644 --- a/buffalogs/buffalogs/settings/settings.py +++ b/buffalogs/buffalogs/settings/settings.py @@ -41,6 +41,7 @@ "rest_framework", "rest_framework.authtoken", "rest_framework_simplejwt", + "drf_spectacular", # OpenAPI schema generation "authentication", "corsheaders", ] @@ -235,3 +236,15 @@ "args": ["weekly"], }, } + +# DRF Spectacular Settings for OpenAPI/Swagger Documentation +REST_FRAMEWORK = { + "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", +} + +SPECTACULAR_SETTINGS = { + "TITLE": "BuffaLogs API", + "DESCRIPTION": "BuffaLogs is an Open Source Django App for detecting login anomalies and managing security alerts.", + "VERSION": "1.0.0", + "SERVE_INCLUDE_SCHEMA": False, +} From 4c99f89ffd5ed86d36c196dffd760a1c331fc867 Mon Sep 17 00:00:00 2001 From: Shivraj Suman <79820642+shivraj1182@users.noreply.github.com> Date: Tue, 27 Jan 2026 12:57:27 +0530 Subject: [PATCH 3/5] feat: Add OpenAPI schema endpoints to urls - Import drf-spectacular views (SpectacularAPIView, SpectacularSwaggerView, SpectacularRedocView) - Add three URL patterns: - /api/schema/ - OpenAPI schema endpoint - /api/docs/ - Interactive Swagger UI documentation - /api/redoc/ - Alternative ReDoc documentation interface Completes the implementation of issue #541 --- buffalogs/buffalogs/urls.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/buffalogs/buffalogs/urls.py b/buffalogs/buffalogs/urls.py index 0b66112a..e8c18c21 100644 --- a/buffalogs/buffalogs/urls.py +++ b/buffalogs/buffalogs/urls.py @@ -1,6 +1,11 @@ from django.contrib import admin from django.urls import include, path from impossible_travel.views import alerts, charts, ingestion, logins, users +from drf_spectacular.views import ( + SpectacularAPIView, + SpectacularRedocView, + SpectacularSwaggerView, +) urlpatterns = [ path("admin/", admin.site.urls), @@ -43,4 +48,8 @@ path("api/alerters/active-alerter/", alerts.get_active_alerter, name="active_alerter_api"), path("api/alerters//", alerts.alerter_config, name="alerter_config_api"), path("api/alerters/", alerts.get_alerters, name="get_alerters"), + # OpenAPI/Swagger Documentation + path("api/schema/", SpectacularAPIView.as_view(), name="schema"), + path("api/docs/", SpectacularSwaggerView.as_view(url_name="schema"), name="swagger-ui"), + path("api/redoc/", SpectacularRedocView.as_view(url_name="schema"), name="redoc"), ] From 373d7a414a2958c5dec6ad8bd742b40ede0be3ed Mon Sep 17 00:00:00 2001 From: Shivraj Suman <79820642+shivraj1182@users.noreply.github.com> Date: Sun, 1 Feb 2026 14:41:52 +0530 Subject: [PATCH 4/5] fix: Update drf-spectacular version to 0.28.0 Changed drf-spectacular version from >=2.0.0 to >=0.28.0 as version 2.0.0 does not exist. The latest available version is 0.28.0 (released November 2024). --- buffalogs/requirements.txt | 65 +++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 18 deletions(-) diff --git a/buffalogs/requirements.txt b/buffalogs/requirements.txt index 92c9ddc2..ce5b2e37 100644 --- a/buffalogs/requirements.txt +++ b/buffalogs/requirements.txt @@ -1,48 +1,77 @@ # === Core Framework === -Django~=5.2 # Main Django framework (web application, ORM, admin, etc.) -djangorestframework>=3.16 # Django REST Framework for building RESTful APIs + +Django>=5.2 # Main Django framework (web application, ORM, admin, etc.) +djangorestframework>=3.16 # Django REST Framework for building RESTful APIs djangorestframework-simplejwt>=5.5.1 # JWT authentication support for DRF -django-cors-headers>=4.9.0 # (dev) Enables CORS headers for frontend-backend separation during development +django-cors-headers>=4.9.0 # (dev) Enables CORS headers for frontend-backend separation during development + # === Task Queue / Background Jobs === -celery>=5.6 # Distributed task queue for asynchronous jobs (e.g., scheduled ingestion) + +celery>=5.6 # Distributed task queue for asynchronous jobs (e.g., scheduled ingestion) + # === Database === -psycopg[binary]>=3.2.13 # PostgreSQL database adapter for Python (binary for better performance) + +psycopg[binary]>=3.2.13 # PostgreSQL database adapter for Python (binary for better performance) + # === Elasticsearch === -elasticsearch>=9.2 # Official low-level Python client for Elasticsearch + +elasticsearch>=9.2 # Official low-level Python client for Elasticsearch + # === Geo & Location === -geopy>=2.4.1 # Library for geocoding and distance calculations via various APIs + +geopy>=2.4.1 # Library for geocoding and distance calculations via various APIs + # === Date / Time Utilities === -python-dateutil>=2.9.0 # Enhanced date parsing, time delta calculations, etc. + +python-dateutil>=2.9.0 # Enhanced date parsing, time delta calculations, etc. + # === User-Agent Info Parsing === -ua-parser>=1.0.1 # Parses user-agent strings into structured browser/device data + +ua-parser>=1.0.1 # Parses user-agent strings into structured browser/device data + # === Visualization === -pygal>=3.1.0 # SVG graphing library (used for rendering frontend charts) -pygal_maps_world>=1.0.2 # World map plugin for Pygal (used in geo-visualizations) + +pygal>=3.1.0 # SVG graphing library (used for rendering frontend charts) +pygal_maps_world>=1.0.2 # World map plugin for Pygal (used in geo-visualizations) + # === JWT Utilities === -PyJWT>=2.10.1 # JSON Web Token implementation (may be used directly or via DRF JWT) + +PyJWT>=2.10.1 # JSON Web Token implementation (may be used directly or via DRF JWT) + # === File handle utilities === -PyYAML>=6.0.2 # To handle yaml files + +PyYAML>=6.0.2 # To handle yaml files + # === Jinja2 === -Jinja2>=3.1.6 # Templating engine for rendering alert messages + +Jinja2>=3.1.6 # Templating engine for rendering alert messages + # === Backoff === -backoff>=2.2.1 # Library for retrying operations with exponential backoff + +backoff>=2.2.1 # Library for retrying operations with exponential backoff + # === HTTP Requests === -requests>=2.32.5 # HTTP library for sending alerts and webhooks + +requests>=2.32.5 # HTTP library for sending alerts and webhooks + # === Web Server === -uwsgi>=2.0.31 # uWSGI application server for serving Django application + +uwsgi>=2.0.31 # uWSGI application server for serving Django application + # === API Documentation === -drf-spectacular>=2.0.0 # OpenAPI/Swagger schema generation for Django REST Framework + +drf-spectacular>=0.28.0 # OpenAPI/Swagger schema generation for Django REST Framework From 9c3a8345f388b86a53c033a74bed8d5f504c29c8 Mon Sep 17 00:00:00 2001 From: Shivraj Suman Date: Mon, 9 Mar 2026 00:23:53 +0530 Subject: [PATCH 5/5] chore: retrigger CI