Skip to content

Commit

Permalink
feat(api): include servers in OpenAPI specification
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Oct 1, 2024
1 parent f60acb2 commit ef3e9a0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion weblate/api/spectacular.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from django.utils.translation import gettext_lazy


def get_spectacular_settings(installed_apps: list[str]) -> None:
def get_spectacular_settings(
installed_apps: list[str], site_url: str, site_title: str
) -> None:
settings = {
# Use redoc from sidecar
# TODO: Should bundle it internally
Expand All @@ -30,6 +32,9 @@ def get_spectacular_settings(installed_apps: list[str]) -> None:
},
},
},
"SERVERS": [
{"url": site_url, "description": site_title},
],
# Document only API (not webauthn and other drf endpoints)
"SERVE_URLCONF": "weblate.api.urls",
"TITLE": gettext_lazy("Weblate's REST API"),
Expand Down
2 changes: 1 addition & 1 deletion weblate/settings_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@
"UNAUTHENTICATED_USER": "weblate.auth.models.get_anonymous",
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}
SPECTACULAR_SETTINGS = get_spectacular_settings(INSTALLED_APPS)
SPECTACULAR_SETTINGS = get_spectacular_settings(INSTALLED_APPS, SITE_URL, SITE_TITLE)

# Fonts CDN URL
FONTS_CDN_URL = None
Expand Down
2 changes: 1 addition & 1 deletion weblate/settings_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@
"UNAUTHENTICATED_USER": "weblate.auth.models.get_anonymous",
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
}
SPECTACULAR_SETTINGS = get_spectacular_settings(INSTALLED_APPS)
SPECTACULAR_SETTINGS = get_spectacular_settings(INSTALLED_APPS, SITE_URL, SITE_TITLE)

Check failure on line 835 in weblate/settings_example.py

View workflow job for this annotation

GitHub Actions / mypy

"get_spectacular_settings" does not return a value (it only ever returns None)

# Fonts CDN URL
FONTS_CDN_URL = None
Expand Down

0 comments on commit ef3e9a0

Please sign in to comment.