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 += [

View File

@@ -411,9 +411,6 @@ FEATURES = {
# Sets the default browser support. For more information go to http://browser-update.org/customize.html
'UNSUPPORTED_BROWSER_ALERT_VERSIONS': "{i:10,f:-3,o:-3,s:-3,c:-3}",
# Set this to true to make API docs available at /api-docs/.
'ENABLE_API_DOCS': False,
# Whether to display the account deletion section the account settings page
'ENABLE_ACCOUNT_DELETION': True,
@@ -2530,6 +2527,9 @@ SWAGGER_SETTINGS = {
'DEFAULT_INFO': 'openedx.core.openapi.openapi_info',
}
# How long to cache OpenAPI schemas and UI, in seconds.
OPENAPI_CACHE_TIMEOUT = 0
######################### MARKETING SITE ###############################
EDXMKTG_LOGGED_IN_COOKIE_NAME = 'edxloggedin'
EDXMKTG_USER_INFO_COOKIE_NAME = 'edx-user-info'

View File

@@ -100,10 +100,6 @@ def should_show_debug_toolbar(request):
return False
return True
########################### API DOCS #################################
FEATURES['ENABLE_API_DOCS'] = True
########################### PIPELINE #################################
PIPELINE['PIPELINE_ENABLED'] = False
@@ -282,6 +278,8 @@ REST_FRAMEWORK['DEFAULT_RENDERER_CLASSES'] += (
'rest_framework.renderers.BrowsableAPIRenderer',
)
OPENAPI_CACHE_TIMEOUT = 0
#####################################################################
# See if the developer has any local overrides.
if os.path.isfile(join(dirname(abspath(__file__)), 'private.py')):

View File

@@ -1051,6 +1051,9 @@ ICP_LICENSE_INFO = ENV_TOKENS.get('ICP_LICENSE_INFO', {})
############## Settings for CourseGraph ############################
COURSEGRAPH_JOB_QUEUE = ENV_TOKENS.get('COURSEGRAPH_JOB_QUEUE', DEFAULT_PRIORITY_QUEUE)
# How long to cache OpenAPI schemas and UI, in seconds.
OPENAPI_CACHE_TIMEOUT = ENV_TOKENS.get('OPENAPI_CACHE_TIMEOUT', 60 * 60)
########################## Parental controls config #######################
# The age at which a learner no longer requires parental consent, or None

View File

@@ -91,8 +91,6 @@ FEATURES['ENABLE_ENROLLMENT_TRACK_USER_PARTITION'] = True
FEATURES['ENABLE_BULK_ENROLLMENT_VIEW'] = True
FEATURES['ENABLE_API_DOCS'] = True
DEFAULT_MOBILE_AVAILABLE = True
# Need wiki for courseware views to work. TODO (vshnayder): shouldn't need it.

View File

@@ -28,6 +28,5 @@ class LmsModuleTests(TestCase):
"""
Tests that requests to the `/api-docs/` endpoint do not raise an exception.
"""
assert settings.FEATURES['ENABLE_API_DOCS']
response = self.client.get('/api-docs/')
self.assertEqual(200, response.status_code)

View File

@@ -949,12 +949,19 @@ if settings.BRANCH_IO_KEY:
url(r'^text-me-the-app', student_views.text_me_the_app, name='text_me_the_app'),
]
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)),
]
# edx-drf-extensions csrf app
urlpatterns += [