From 51a6c076e27931c89a37d76301975e7e548e3324 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 18 Apr 2017 13:44:43 +0300 Subject: [PATCH] Allow customizing the SchemaGenerator class for docs --- rest_framework/documentation.py | 20 ++++++++++++-------- rest_framework/schemas.py | 12 ++++++++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/rest_framework/documentation.py b/rest_framework/documentation.py index 3a56b7cb1..a95259ddc 100644 --- a/rest_framework/documentation.py +++ b/rest_framework/documentation.py @@ -3,10 +3,10 @@ from django.conf.urls import include, url from rest_framework.renderers import ( 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] return get_schema_view( @@ -14,11 +14,12 @@ def get_docs_view(title=None, description=None, schema_url=None, public=True): url=schema_url, description=description, 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] return get_schema_view( @@ -26,22 +27,25 @@ def get_schemajs_view(title=None, description=None, schema_url=None, public=True url=schema_url, description=description, 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( title=title, description=description, schema_url=schema_url, - public=public + public=public, + generator_class=generator_class, ) schema_js_view = get_schemajs_view( title=title, description=description, schema_url=schema_url, - public=public + public=public, + generator_class=generator_class, ) urls = [ url(r'^$', docs_view, name='docs-index'), diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index ec6d7f3c3..859a6c9bd 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -694,11 +694,19 @@ class SchemaView(APIView): 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. """ - 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( renderer_classes=renderer_classes, schema_generator=generator,