Skip to content

Commit

Permalink
Added swagger to gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
Tansito committed May 8, 2023
1 parent 116c0fc commit c26aae1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions gateway/main/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"allauth.socialaccount.providers.keycloak",
"dj_rest_auth",
"dj_rest_auth.registration",
"drf_yasg",
"api",
]

Expand Down Expand Up @@ -199,3 +200,5 @@

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"

SWAGGER_SETTINGS = {"LOGIN_URL": "/api-auth/login/", "LOGOUT_URL": "/api-auth/logout/"}
24 changes: 23 additions & 1 deletion gateway/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,23 @@
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include, re_path
from rest_framework import routers
from rest_framework import routers, permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi

from api.views import KeycloakLogin, KeycloakUsersView

router = routers.DefaultRouter()

schema = get_schema_view( # pylint: disable=invalid-name
openapi.Info(
title="Gateway API",
default_version="v1",
description="List of available API endpoints for the Gateway.",
),
public=True,
permission_classes=[permissions.AllowAny],
)

urlpatterns = [
path("dj-rest-auth/", include("dj_rest_auth.urls")),
Expand All @@ -33,6 +44,17 @@
path("admin/", admin.site.urls),
path("", include("django_prometheus.urls")),
re_path(r"^api/v1/", include(("api.v1.urls", "api"), namespace="v1")),
# docs
re_path(
r"^swagger(?P<format>\.json|\.yaml)$",
schema.without_ui(cache_timeout=0),
name="schema-json",
),
re_path(
r"^swagger/$",
schema.with_ui("swagger", cache_timeout=0),
name="schema-swagger-ui",
),
]

if settings.DEBUG:
Expand Down
1 change: 1 addition & 0 deletions gateway/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ ray[default]>=2.3.0
Django>=4.1.7
gunicorn>=20.1.0
requests>=2.28.2
drf-yasg>=1.21.5
2 changes: 1 addition & 1 deletion repository/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
default_version="v1",
description="List of available API endpoint for Program repository.",
),
public=False,
public=True,
permission_classes=[permissions.AllowAny],
)

Expand Down

0 comments on commit c26aae1

Please sign in to comment.