diff --git a/cms/lib/spectacular.py b/cms/lib/spectacular.py index 0f4364f3b4..0a4ac831d3 100644 --- a/cms/lib/spectacular.py +++ b/cms/lib/spectacular.py @@ -1,4 +1,6 @@ -""" Helper functions for drf-spectacular """ +"""Helper functions for drf-spectacular""" + +import re def cms_api_filter(endpoints): @@ -7,17 +9,15 @@ def cms_api_filter(endpoints): Filter out endpoints that are not part of the CMS API. """ filtered = [] - for (path, path_regex, method, callback) in endpoints: - # Add only paths to the list that are part of the CMS API - if ( - # Don't just replace this with /v1 when switching to a later version of the CMS API. - # That would include some unintended endpoints. - path.startswith("/api/contentstore/v0/xblock") or - path.startswith("/api/contentstore/v0/videos") or - path.startswith("/api/contentstore/v0/video_transcripts") or - path.startswith("/api/contentstore/v0/file_assets") or - path.startswith("/api/contentstore/v0/youtube_transcripts") or - path.startswith("/api/courses/") and "bulk_enable_disable_discussions" in path + CMS_PATH_PATTERN = re.compile( + r"^/api/contentstore/v0/(xblock|videos|video_transcripts|file_assets|youtube_transcripts)" + ) + + 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 ): filtered.append((path, path_regex, method, callback)) + return filtered