mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Allow customizing the SchemaGenerator class for docs
This commit is contained in:
parent
bd768d6253
commit
51a6c076e2
|
@ -3,10 +3,10 @@ from django.conf.urls import include, url
|
||||||
from rest_framework.renderers import (
|
from rest_framework.renderers import (
|
||||||
CoreJSONRenderer, DocumentationRenderer, SchemaJSRenderer
|
CoreJSONRenderer, DocumentationRenderer, SchemaJSRenderer
|
||||||
)
|
)
|
||||||
from rest_framework.schemas import get_schema_view
|
from rest_framework.schemas import SchemaGenerator, get_schema_view
|
||||||
|
|
||||||
|
|
||||||
def get_docs_view(title=None, description=None, schema_url=None, public=True):
|
def get_docs_view(title=None, description=None, schema_url=None, public=True, generator_class=SchemaGenerator):
|
||||||
renderer_classes = [DocumentationRenderer, CoreJSONRenderer]
|
renderer_classes = [DocumentationRenderer, CoreJSONRenderer]
|
||||||
|
|
||||||
return get_schema_view(
|
return get_schema_view(
|
||||||
|
@ -14,11 +14,12 @@ def get_docs_view(title=None, description=None, schema_url=None, public=True):
|
||||||
url=schema_url,
|
url=schema_url,
|
||||||
description=description,
|
description=description,
|
||||||
renderer_classes=renderer_classes,
|
renderer_classes=renderer_classes,
|
||||||
public=public
|
public=public,
|
||||||
|
generator_class=generator_class,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_schemajs_view(title=None, description=None, schema_url=None, public=True):
|
def get_schemajs_view(title=None, description=None, schema_url=None, public=True, generator_class=SchemaGenerator):
|
||||||
renderer_classes = [SchemaJSRenderer]
|
renderer_classes = [SchemaJSRenderer]
|
||||||
|
|
||||||
return get_schema_view(
|
return get_schema_view(
|
||||||
|
@ -26,22 +27,25 @@ def get_schemajs_view(title=None, description=None, schema_url=None, public=True
|
||||||
url=schema_url,
|
url=schema_url,
|
||||||
description=description,
|
description=description,
|
||||||
renderer_classes=renderer_classes,
|
renderer_classes=renderer_classes,
|
||||||
public=public
|
public=public,
|
||||||
|
generator_class=generator_class,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def include_docs_urls(title=None, description=None, schema_url=None, public=True):
|
def include_docs_urls(title=None, description=None, schema_url=None, public=True, generator_class=SchemaGenerator):
|
||||||
docs_view = get_docs_view(
|
docs_view = get_docs_view(
|
||||||
title=title,
|
title=title,
|
||||||
description=description,
|
description=description,
|
||||||
schema_url=schema_url,
|
schema_url=schema_url,
|
||||||
public=public
|
public=public,
|
||||||
|
generator_class=generator_class,
|
||||||
)
|
)
|
||||||
schema_js_view = get_schemajs_view(
|
schema_js_view = get_schemajs_view(
|
||||||
title=title,
|
title=title,
|
||||||
description=description,
|
description=description,
|
||||||
schema_url=schema_url,
|
schema_url=schema_url,
|
||||||
public=public
|
public=public,
|
||||||
|
generator_class=generator_class,
|
||||||
)
|
)
|
||||||
urls = [
|
urls = [
|
||||||
url(r'^$', docs_view, name='docs-index'),
|
url(r'^$', docs_view, name='docs-index'),
|
||||||
|
|
|
@ -694,11 +694,19 @@ class SchemaView(APIView):
|
||||||
return Response(schema)
|
return Response(schema)
|
||||||
|
|
||||||
|
|
||||||
def get_schema_view(title=None, url=None, description=None, urlconf=None, renderer_classes=None, public=False):
|
def get_schema_view(
|
||||||
|
title=None,
|
||||||
|
url=None,
|
||||||
|
description=None,
|
||||||
|
urlconf=None,
|
||||||
|
renderer_classes=None,
|
||||||
|
public=False,
|
||||||
|
generator_class=SchemaGenerator,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Return a schema view.
|
Return a schema view.
|
||||||
"""
|
"""
|
||||||
generator = SchemaGenerator(title=title, url=url, description=description, urlconf=urlconf)
|
generator = generator_class(title=title, url=url, description=description, urlconf=urlconf)
|
||||||
return SchemaView.as_view(
|
return SchemaView.as_view(
|
||||||
renderer_classes=renderer_classes,
|
renderer_classes=renderer_classes,
|
||||||
schema_generator=generator,
|
schema_generator=generator,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user