mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 22:04:48 +03:00
Add schema_renderers to DefaultRouter
This commit is contained in:
parent
2edc7ae3a8
commit
70011fed88
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user