Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api][tools] Add swagger URL and UI for public APIs #3776

Merged
merged 11 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions desktop/core/base_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ git+https://github.com/gethue/django-babel.git
django-utils-six==2.0
six==1.16.0
psutil==5.8.0
drf-spectacular[sidecar]==0.27.2
-e file://${ROOT}/desktop/core/ext-py3/boto-2.49.0
-e file://${ROOT}/desktop/core/ext-py3/django-axes-5.13.0
-e file://${ROOT}/desktop/core/ext-py3/djangosaml2-0.18.0
Expand Down
14 changes: 13 additions & 1 deletion desktop/core/src/desktop/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@
# 'django_celery_results',
'rest_framework',
'rest_framework.authtoken',
'drf_spectacular',
'drf_spectacular_sidecar'
]

WEBPACK_LOADER = {
Expand Down Expand Up @@ -325,8 +327,18 @@
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.IsAuthenticated',
],
'DEFAULT_AUTHENTICATION_CLASSES': desktop.conf.AUTH.API_AUTH.get()
'DEFAULT_AUTHENTICATION_CLASSES': desktop.conf.AUTH.API_AUTH.get(),
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}

SPECTACULAR_SETTINGS = {
'TITLE': 'Hue Public API',
'VERSION': '1.0.0',
'SWAGGER_UI_DIST': 'SIDECAR',
'SWAGGER_UI_FAVICON_HREF': 'SIDECAR',
}


if desktop.conf.is_custom_jwt_auth_enabled() and \
'desktop.auth.api_authentications.JwtAuthentication' not in REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES']:
REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'].insert(0, 'desktop.auth.api_authentications.JwtAuthentication')
Expand Down
24 changes: 8 additions & 16 deletions desktop/core/src/desktop/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import

import re
import sys
import logging

from django.conf import settings
from django.urls import include, re_path
from django.views.static import serve
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView
from rest_framework_simplejwt.views import (
TokenObtainPairView,
TokenRefreshView,
TokenVerifyView,
)

# FIXME: This could be replaced with hooking into the `AppConfig.ready()`
# signal in Django 1.7:
#
# https://docs.djangoproject.com/en/1.7/ref/applications/#django.apps.AppConfig.ready
#
import desktop.lib.metrics.file_reporter
from desktop import api as desktop_api, api2 as desktop_api2, api_public_urls_v1, appmanager, views as desktop_views
from desktop.auth import views as desktop_auth_views
Expand All @@ -46,10 +39,6 @@

desktop.lib.metrics.file_reporter.start_file_reporter()

if sys.version_info[0] > 2:
from django.urls import include, re_path
else:
from django.conf.urls import include, url as re_path

# Django expects handler404 and handler500 to be defined.
# django.conf.urls provides them. But we want to override them.
Expand Down Expand Up @@ -202,9 +191,12 @@
]

dynamic_patterns += [
re_path('^api/v1/token/auth/?$', TokenObtainPairView.as_view(), name='token_obtain'),
re_path('^api/v1/token/verify/?$', TokenVerifyView.as_view(), name='token_verify'),
re_path('^api/v1/token/refresh/?$', TokenRefreshView.as_view(), name='token_refresh'),
re_path(r'^api/schema/?$', SpectacularAPIView.as_view(), name='schema'),
re_path(r'^api/swagger/?$', SpectacularSwaggerView.as_view(), name='swagger-ui'),

re_path(r'^api/v1/token/auth/?$', TokenObtainPairView.as_view(), name='token_obtain'),
re_path(r'^api/v1/token/verify/?$', TokenVerifyView.as_view(), name='token_verify'),
re_path(r'^api/v1/token/refresh/?$', TokenRefreshView.as_view(), name='token_refresh'),

re_path(r'^api/v1/', include(('desktop.api_public_urls_v1', 'api'), 'api')),
]
Expand Down
Loading