mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-01 19:10:12 +03:00
feature(Secure API docs): added new flag to switch on/off the authentication needed to view the documentation of the APIs
This commit is contained in:
parent
7c6e34c14f
commit
3799a8b23a
|
@ -1,4 +1,5 @@
|
||||||
from django.conf.urls import include, url
|
from django.conf.urls import include, url
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
|
||||||
from rest_framework.renderers import (
|
from rest_framework.renderers import (
|
||||||
CoreJSONRenderer, DocumentationRenderer, SchemaJSRenderer
|
CoreJSONRenderer, DocumentationRenderer, SchemaJSRenderer
|
||||||
|
@ -77,8 +78,14 @@ def include_docs_urls(
|
||||||
authentication_classes=authentication_classes,
|
authentication_classes=authentication_classes,
|
||||||
permission_classes=permission_classes,
|
permission_classes=permission_classes,
|
||||||
)
|
)
|
||||||
|
if api_settings.SECURE_DOCS is False:
|
||||||
urls = [
|
urls = [
|
||||||
url(r'^$', docs_view, name='docs-index'),
|
url(r'^$', docs_view, name='docs-index'),
|
||||||
url(r'^schema.js$', schema_js_view, name='schema-js')
|
url(r'^schema.js$', schema_js_view, name='schema-js')
|
||||||
]
|
]
|
||||||
|
else:
|
||||||
|
urls = [
|
||||||
|
url(r'^$', login_required(docs_view), name='docs-index'),
|
||||||
|
url(r'^schema.js$', login_required(schema_js_view), name='schema-js')
|
||||||
|
]
|
||||||
return include((urls, 'api-docs'), namespace='api-docs')
|
return include((urls, 'api-docs'), namespace='api-docs')
|
||||||
|
|
|
@ -128,6 +128,9 @@ DEFAULTS = {
|
||||||
'retrieve': 'read',
|
'retrieve': 'read',
|
||||||
'destroy': 'delete'
|
'destroy': 'delete'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
'SECURE_DOCS': False
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user