Add schema_renderers to DefaultRouter

This commit is contained in:
Tom Christie 2016-07-13 15:29:26 +01:00
parent 2edc7ae3a8
commit 70011fed88
2 changed files with 17 additions and 3 deletions

View File

@ -126,8 +126,21 @@ that include the Core JSON media type in their `Accept` header.
}
This is a great zero-configuration option for when you want to get up and
running really quickly. If you want a little more flexibility over the
schema output then you'll need to consider using `SchemaGenerator` instead.
running really quickly.
The only other available option to `DefaultRouter` is `schema_renderers`, which
may be used to pass the set of renderer classes that can be used to render
schema output.
from rest_framework.renderers import CoreJSONRenderer
from my_custom_package import APIBlueprintRenderer
router = DefaultRouter(schema_title='Server Monitoring API', schema_renderers=[
CoreJSONRenderer, APIBlueprintRenderer
])
If you want more flexibility over the schema output then you'll need to consider
using `SchemaGenerator` instead.
## Using SchemaGenerator

View File

@ -273,10 +273,11 @@ class DefaultRouter(SimpleRouter):
include_root_view = True
include_format_suffixes = True
root_view_name = 'api-root'
schema_renderers = [renderers.CoreJSONRenderer]
default_schema_renderers = [renderers.CoreJSONRenderer]
def __init__(self, *args, **kwargs):
self.schema_title = kwargs.pop('schema_title', None)
self.schema_renderers = kwargs.pop('schema_renderers', self.default_schema_renderers)
super(DefaultRouter, self).__init__(*args, **kwargs)
def get_api_root_view(self, schema_urls=None):