mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-25 00:34:21 +03:00
Merge pull request #4979 from linovia/feature/improve_schema_shortcut
Restrict doc & schema shortcuts to a subset of urls
This commit is contained in:
commit
aafd0a644f
|
@ -170,6 +170,22 @@ May be used to pass the set of renderer classes that can be used to render the A
|
|||
renderer_classes=[CoreJSONRenderer, APIBlueprintRenderer]
|
||||
)
|
||||
|
||||
#### `patterns`
|
||||
|
||||
List of url patterns to limit the schema introspection to. If you only want the `myproject.api` urls
|
||||
to be exposed in the schema:
|
||||
|
||||
schema_url_patterns = [
|
||||
url(r'^api/', include('myproject.api.urls')),
|
||||
]
|
||||
|
||||
schema_view = get_schema_view(
|
||||
title='Server Monitoring API',
|
||||
url='https://www.example.org/api/',
|
||||
patterns=schema_url_patterns,
|
||||
)
|
||||
|
||||
|
||||
## Using an explicit schema view
|
||||
|
||||
If you need a little more control than the `get_schema_view()` shortcut gives you,
|
||||
|
|
|
@ -6,7 +6,9 @@ from rest_framework.renderers import (
|
|||
from rest_framework.schemas import SchemaGenerator, get_schema_view
|
||||
|
||||
|
||||
def get_docs_view(title=None, description=None, schema_url=None, public=True, generator_class=SchemaGenerator):
|
||||
def get_docs_view(
|
||||
title=None, description=None, schema_url=None, public=True,
|
||||
patterns=None, generator_class=SchemaGenerator):
|
||||
renderer_classes = [DocumentationRenderer, CoreJSONRenderer]
|
||||
|
||||
return get_schema_view(
|
||||
|
@ -15,11 +17,14 @@ def get_docs_view(title=None, description=None, schema_url=None, public=True, ge
|
|||
description=description,
|
||||
renderer_classes=renderer_classes,
|
||||
public=public,
|
||||
patterns=patterns,
|
||||
generator_class=generator_class,
|
||||
)
|
||||
|
||||
|
||||
def get_schemajs_view(title=None, description=None, schema_url=None, public=True, generator_class=SchemaGenerator):
|
||||
def get_schemajs_view(
|
||||
title=None, description=None, schema_url=None, public=True,
|
||||
patterns=None, generator_class=SchemaGenerator):
|
||||
renderer_classes = [SchemaJSRenderer]
|
||||
|
||||
return get_schema_view(
|
||||
|
@ -28,16 +33,20 @@ def get_schemajs_view(title=None, description=None, schema_url=None, public=True
|
|||
description=description,
|
||||
renderer_classes=renderer_classes,
|
||||
public=public,
|
||||
patterns=patterns,
|
||||
generator_class=generator_class,
|
||||
)
|
||||
|
||||
|
||||
def include_docs_urls(title=None, description=None, schema_url=None, public=True, generator_class=SchemaGenerator):
|
||||
def include_docs_urls(
|
||||
title=None, description=None, schema_url=None, public=True,
|
||||
patterns=None, generator_class=SchemaGenerator):
|
||||
docs_view = get_docs_view(
|
||||
title=title,
|
||||
description=description,
|
||||
schema_url=schema_url,
|
||||
public=public,
|
||||
patterns=patterns,
|
||||
generator_class=generator_class,
|
||||
)
|
||||
schema_js_view = get_schemajs_view(
|
||||
|
@ -45,6 +54,7 @@ def include_docs_urls(title=None, description=None, schema_url=None, public=True
|
|||
description=description,
|
||||
schema_url=schema_url,
|
||||
public=public,
|
||||
patterns=patterns,
|
||||
generator_class=generator_class,
|
||||
)
|
||||
urls = [
|
||||
|
|
|
@ -695,18 +695,15 @@ class SchemaView(APIView):
|
|||
|
||||
|
||||
def get_schema_view(
|
||||
title=None,
|
||||
url=None,
|
||||
description=None,
|
||||
urlconf=None,
|
||||
renderer_classes=None,
|
||||
public=False,
|
||||
generator_class=SchemaGenerator,
|
||||
):
|
||||
title=None, url=None, description=None, urlconf=None, renderer_classes=None,
|
||||
public=False, patterns=None, generator_class=SchemaGenerator):
|
||||
"""
|
||||
Return a schema view.
|
||||
"""
|
||||
generator = generator_class(title=title, url=url, description=description, urlconf=urlconf)
|
||||
generator = generator_class(
|
||||
title=title, url=url, description=description,
|
||||
urlconf=urlconf, patterns=patterns,
|
||||
)
|
||||
return SchemaView.as_view(
|
||||
renderer_classes=renderer_classes,
|
||||
schema_generator=generator,
|
||||
|
|
Loading…
Reference in New Issue
Block a user