Skip to content
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
9 changes: 6 additions & 3 deletions cms/lib/spectacular.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ def cms_api_filter(endpoints):
CMS_PATH_PATTERN = re.compile(r"^/api/contentstore/v\d+/")

for path, path_regex, method, callback in endpoints:
if CMS_PATH_PATTERN.match(path) or (
path.startswith("/api/courses/")
and "bulk_enable_disable_discussions" in path
if (
CMS_PATH_PATTERN.match(path)
or (
path.startswith("/api/courses/")
and "bulk_enable_disable_discussions" in path
)
):
filtered.append((path, path_regex, method, callback))

Expand Down
13 changes: 13 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,7 @@

# API Documentation
'drf_yasg',
'drf_spectacular',

# edx-drf-extensions
'csrf.apps.CsrfAppConfig', # Enables frontend apps to retrieve CSRF tokens.
Expand Down Expand Up @@ -2125,6 +2126,18 @@
'DEEP_LINKING': True,
}

###################### drf-spectacular (LMS enrollment schema) ######################
SPECTACULAR_SETTINGS = {
'TITLE': 'LMS Enrollment API',
'VERSION': '0.1.0',
'SERVE_INCLUDE_SCHEMA': False,
'PREPROCESSING_HOOKS': ['lms.lib.spectacular.lms_api_filter'],
'SCHEMA_PATH_PREFIX': '/api/enrollment',
'SCHEMA_PATH_PREFIX_TRIM': '/api/enrollment',
# SERVERS is environment-specific (LMS_ROOT_URL differs per env) and is
# set in devstack.py / production.py.
}

######################### MARKETING SITE ###############################

MKTG_URL_LINK_MAP.update({ # noqa: F405
Expand Down
5 changes: 5 additions & 0 deletions lms/envs/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,11 @@ def should_show_debug_toolbar(request): # pylint: disable=missing-function-docs
'COMPLETE',
]

###################### drf-spectacular (LMS enrollment schema) ######################
SPECTACULAR_SETTINGS['SERVERS'] = [ # noqa: F405
{'url': LMS_ROOT_URL, 'description': 'Local'}, # noqa: F405
]

################# New settings must go ABOVE this line #################
########################################################################
# See if the developer has any local overrides.
Expand Down
5 changes: 5 additions & 0 deletions lms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ def get_env_setting(setting):
MIDDLEWARE.extend(_YAML_TOKENS.get('EXTRA_MIDDLEWARE_CLASSES', [])) # noqa: F405


###################### drf-spectacular (LMS enrollment schema) ######################

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add this in common and duplicate in both devstack and production?

SPECTACULAR_SETTINGS['SERVERS'] = [ # noqa: F405
{'url': LMS_ROOT_URL, 'description': 'Local'}, # noqa: F405
]

#######################################################################################################################
#### DERIVE ANY DERIVED SETTINGS
####
Expand Down
17 changes: 17 additions & 0 deletions lms/lib/spectacular.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Helper functions for drf-spectacular (LMS schema)."""

import re


def lms_api_filter(endpoints):
"""
Pre-processing hook: keep only enrollment v2 endpoints tagged for the SDK.
"""
filtered = []
ENROLLMENT_PATH_PATTERN = re.compile(r"^/api/enrollment/v\d+/")

for path, path_regex, method, callback in endpoints:
if ENROLLMENT_PATH_PATTERN.match(path):
filtered.append((path, path_regex, method, callback))

return filtered
6 changes: 6 additions & 0 deletions lms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.urls import include, path, re_path
from django.utils.translation import gettext_lazy as _
from django.views.generic.base import RedirectView
from drf_spectacular.views import SpectacularAPIView
from edx_api_doc_tools import make_docs_urls
from edx_django_utils.plugins import get_plugin_url_patterns
from submissions import urls as submissions_urls
Expand Down Expand Up @@ -1068,3 +1069,8 @@
urlpatterns += [
path('xqueue/', include((submissions_urls, 'submissions'), namespace='submissions')),
]

# LMS API schema for openedx-platform-sdk generation.
urlpatterns += [
path('lms-api/schema/', SpectacularAPIView.as_view(), name='lms-schema'),
]
1 change: 1 addition & 0 deletions openedx/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ def add_optional_apps(optional_apps, installed_apps):
'registration_validation': '30/minute',
'high_service_user': '2000/minute',
},
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}

# .. setting_name: REGISTRATION_VALIDATION_RATELIMIT
Expand Down
Loading