Skip to content

Commit 8812e6c

Browse files
author
Carlton Gibson
authored
Merge pull request #5448 from carltongibson/pr/5309-docs-view-custom-auth
Allow setting custom authentication and permissions on docs view.
2 parents 107e8b3 + 1bcee8c commit 8812e6c

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

docs/api-guide/schemas.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,15 @@ to be exposed in the schema:
334334
May be used to specify a `SchemaGenerator` subclass to be passed to the
335335
`SchemaView`.
336336

337+
#### `authentication_classes`
338+
339+
May be used to specify the list of authentication classes that will apply to the schema endpoint.
340+
Defaults to `settings.DEFAULT_AUTHENTICATION_CLASSES`
341+
342+
#### `permission_classes`
343+
344+
May be used to specify the list of permission classes that will apply to the schema endpoint.
345+
Defaults to `settings.DEFAULT_PERMISSION_CLASSES`
337346

338347

339348
## Using an explicit schema view

rest_framework/documentation.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
CoreJSONRenderer, DocumentationRenderer, SchemaJSRenderer
55
)
66
from rest_framework.schemas import SchemaGenerator, get_schema_view
7+
from rest_framework.settings import api_settings
78

89

910
def get_docs_view(
1011
title=None, description=None, schema_url=None, public=True,
11-
patterns=None, generator_class=SchemaGenerator):
12+
patterns=None, generator_class=SchemaGenerator,
13+
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
14+
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES):
1215
renderer_classes = [DocumentationRenderer, CoreJSONRenderer]
1316

1417
return get_schema_view(
@@ -19,12 +22,16 @@ def get_docs_view(
1922
public=public,
2023
patterns=patterns,
2124
generator_class=generator_class,
25+
authentication_classes=authentication_classes,
26+
permission_classes=permission_classes,
2227
)
2328

2429

2530
def get_schemajs_view(
2631
title=None, description=None, schema_url=None, public=True,
27-
patterns=None, generator_class=SchemaGenerator):
32+
patterns=None, generator_class=SchemaGenerator,
33+
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
34+
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES):
2835
renderer_classes = [SchemaJSRenderer]
2936

3037
return get_schema_view(
@@ -35,19 +42,25 @@ def get_schemajs_view(
3542
public=public,
3643
patterns=patterns,
3744
generator_class=generator_class,
45+
authentication_classes=authentication_classes,
46+
permission_classes=permission_classes,
3847
)
3948

4049

4150
def include_docs_urls(
4251
title=None, description=None, schema_url=None, public=True,
43-
patterns=None, generator_class=SchemaGenerator):
52+
patterns=None, generator_class=SchemaGenerator,
53+
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
54+
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES):
4455
docs_view = get_docs_view(
4556
title=title,
4657
description=description,
4758
schema_url=schema_url,
4859
public=public,
4960
patterns=patterns,
5061
generator_class=generator_class,
62+
authentication_classes=authentication_classes,
63+
permission_classes=permission_classes,
5164
)
5265
schema_js_view = get_schemajs_view(
5366
title=title,
@@ -56,6 +69,8 @@ def include_docs_urls(
5669
public=public,
5770
patterns=patterns,
5871
generator_class=generator_class,
72+
authentication_classes=authentication_classes,
73+
permission_classes=permission_classes,
5974
)
6075
urls = [
6176
url(r'^$', docs_view, name='docs-index'),

rest_framework/schemas/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@
2020
2121
Other access should target the submodules directly
2222
"""
23+
from rest_framework.settings import api_settings
24+
2325
from .generators import SchemaGenerator
2426
from .inspectors import AutoSchema, ManualSchema # noqa
2527

2628

2729
def get_schema_view(
2830
title=None, url=None, description=None, urlconf=None, renderer_classes=None,
29-
public=False, patterns=None, generator_class=SchemaGenerator):
31+
public=False, patterns=None, generator_class=SchemaGenerator,
32+
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
33+
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES):
3034
"""
3135
Return a schema view.
3236
"""
@@ -40,4 +44,6 @@ def get_schema_view(
4044
renderer_classes=renderer_classes,
4145
schema_generator=generator,
4246
public=public,
47+
authentication_classes=authentication_classes,
48+
permission_classes=permission_classes,
4349
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy