URLs and settings for OpenAPI generation

API docs are now always available, no more toggle to enable them.
This commit is contained in:
Ned Batchelder
2019-09-17 16:16:42 -04:00
parent 28d2788ade
commit d585a8f71d
10 changed files with 44 additions and 29 deletions

View File

@@ -305,9 +305,6 @@ FEATURES = {
# Prevent auto auth from creating superusers or modifying existing users
'RESTRICT_AUTOMATIC_AUTH': True,
# Set this to true to make API docs available at /api-docs/.
'ENABLE_API_DOCS': False,
}
ENABLE_JASMINE = False
@@ -1802,6 +1799,10 @@ COURSE_ABOUT_VISIBILITY_PERMISSION = 'see_exists'
DEFAULT_COURSE_VISIBILITY_IN_CATALOG = "both"
DEFAULT_MOBILE_AVAILABLE = False
# How long to cache OpenAPI schemas and UI, in seconds.
OPENAPI_CACHE_TIMEOUT = 0
################# Mobile URLS ##########################
# These are URLs to the app store for mobile.

View File

@@ -105,10 +105,6 @@ def should_show_debug_toolbar(request):
return True
########################### API DOCS #################################
FEATURES['ENABLE_API_DOCS'] = True
################################ MILESTONES ################################
FEATURES['MILESTONES_APP'] = True
@@ -186,6 +182,9 @@ from openedx.core.djangoapps.plugins import constants as plugin_constants, plugi
plugin_settings.add_plugins(__name__, plugin_constants.ProjectType.CMS, plugin_constants.SettingsType.DEVSTACK)
OPENAPI_CACHE_TIMEOUT = 0
###############################################################################
# See if the developer has any local overrides.
if os.path.isfile(join(dirname(abspath(__file__)), 'private.py')):

View File

@@ -135,6 +135,9 @@ DEFAULT_MOBILE_AVAILABLE = ENV_TOKENS.get(
DEFAULT_MOBILE_AVAILABLE
)
# How long to cache OpenAPI schemas and UI, in seconds.
OPENAPI_CACHE_TIMEOUT = ENV_TOKENS.get('OPENAPI_CACHE_TIMEOUT', 60 * 60)
# MEDIA_ROOT specifies the directory where user-uploaded files are stored.
MEDIA_ROOT = ENV_TOKENS.get('MEDIA_ROOT', MEDIA_ROOT)
MEDIA_URL = ENV_TOKENS.get('MEDIA_URL', MEDIA_URL)

View File

@@ -270,12 +270,19 @@ urlpatterns += [
url(r'^500$', handler500),
]
if settings.FEATURES.get('ENABLE_API_DOCS'):
urlpatterns += [
url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
url(r'^api-docs/$', schema_view.with_ui('swagger', cache_timeout=0)),
]
# API docs.
urlpatterns += [
url(
r'^swagger(?P<format>\.json|\.yaml)$',
schema_view.without_ui(cache_timeout=settings.OPENAPI_CACHE_TIMEOUT), name='schema-json',
),
url(
r'^swagger/$',
schema_view.with_ui('swagger', cache_timeout=settings.OPENAPI_CACHE_TIMEOUT),
name='schema-swagger-ui',
),
url(r'^api-docs/$', schema_view.with_ui('swagger', cache_timeout=settings.OPENAPI_CACHE_TIMEOUT)),
]
if 'openedx.testing.coverage_context_listener' in settings.INSTALLED_APPS:
urlpatterns += [