🩹(backend) fix swagger and redoc documentation urls

Use canonical documentation routes and add a regression test.
This commit is contained in:
Rahulchourasiya
2026-04-09 22:17:46 +05:30
committed by aleb_the_flash
parent 1eefc49f8d
commit 5ea5460b17
3 changed files with 22 additions and 2 deletions
+3
View File
@@ -25,6 +25,9 @@ and this project adheres to
- 🚀 (paas) remove buildpack requirements.txt to use the new uv.lock #1349
- ✨(backend) allow room configuration and access level via external api #1260
### Fixed
- 🩹(backend) fix swagger and redoc documentation URLs
## [1.16.0] - 2026-05-13
### Added
@@ -4,6 +4,7 @@ Test suite for generated openapi schema.
import json
from io import StringIO
from unittest.mock import patch
from django.core.management import call_command
from django.test import Client
@@ -40,3 +41,19 @@ def test_openapi_client_schema():
"core/tests/swagger/swagger.json", "r", encoding="utf-8"
) as expected_schema:
assert response.json() == json.load(expected_schema)
@patch(
"django.contrib.staticfiles.storage.staticfiles_storage.url",
side_effect=lambda name: f"/static/{name}",
)
# pylint: disable=unused-argument
def test_openapi_documentation_routes(mock_staticfiles):
"""Swagger and ReDoc documentation should be served on canonical URLs."""
client = Client()
swagger_response = client.get("/v1.0/swagger/")
redoc_response = client.get("/v1.0/redoc/")
assert swagger_response.status_code == 200
assert redoc_response.status_code == 200
+2 -2
View File
@@ -37,12 +37,12 @@ if settings.USE_SWAGGER or settings.DEBUG:
name="client-api-schema",
),
path(
f"{settings.API_VERSION}//swagger/",
f"{settings.API_VERSION}/swagger/",
SpectacularSwaggerView.as_view(url_name="client-api-schema"),
name="swagger-ui-schema",
),
re_path(
f"{settings.API_VERSION}//redoc/",
f"{settings.API_VERSION}/redoc/",
SpectacularRedocView.as_view(url_name="client-api-schema"),
name="redoc-schema",
),