mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Merge branch 'master' into localizedfloatfield
This commit is contained in:
commit
377279816b
|
@ -54,7 +54,7 @@ There is a live example API for testing purposes, [available here][sandbox].
|
|||
# Requirements
|
||||
|
||||
* Python (2.7, 3.2, 3.3, 3.4, 3.5)
|
||||
* Django (1.8, 1.9, 1.10)
|
||||
* Django (1.8, 1.9, 1.10, 1.11)
|
||||
|
||||
# Installation
|
||||
|
||||
|
|
|
@ -432,8 +432,11 @@ The method should return a rendered HTML string.
|
|||
## Pagination & schemas
|
||||
|
||||
You can also make the filter controls available to the schema autogeneration
|
||||
that REST framework provides, by implementing a `get_schema_fields()` method,
|
||||
which should return a list of `coreapi.Field` instances.
|
||||
that REST framework provides, by implementing a `get_schema_fields()` method. This method should have the following signature:
|
||||
|
||||
`get_schema_fields(self, view)`
|
||||
|
||||
The method should return a list of `coreapi.Field` instances.
|
||||
|
||||
# Third party packages
|
||||
|
||||
|
|
|
@ -279,8 +279,11 @@ API responses for list endpoints will now include a `Link` header, instead of in
|
|||
## Pagination & schemas
|
||||
|
||||
You can also make the pagination controls available to the schema autogeneration
|
||||
that REST framework provides, by implementing a `get_schema_fields()` method,
|
||||
which should return a list of `coreapi.Field` instances.
|
||||
that REST framework provides, by implementing a `get_schema_fields()` method. This method should have the following signature:
|
||||
|
||||
`get_schema_fields(self, view)`
|
||||
|
||||
The method should return a list of `coreapi.Field` instances.
|
||||
|
||||
---
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ continued development by **[signing up for a paid plan][funding]**.
|
|||
REST framework requires the following:
|
||||
|
||||
* Python (2.7, 3.2, 3.3, 3.4, 3.5)
|
||||
* Django (1.8, 1.9, 1.10)
|
||||
* Django (1.8, 1.9, 1.10, 1.11)
|
||||
|
||||
The following packages are optional:
|
||||
|
||||
|
@ -310,7 +310,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
[markdown]: http://pypi.python.org/pypi/Markdown/
|
||||
[django-filter]: http://pypi.python.org/pypi/django-filter
|
||||
[django-crispy-forms]: https://github.com/maraujop/django-crispy-forms
|
||||
[django-guardian]: https://github.com/lukaszb/django-guardian
|
||||
[django-guardian]: https://github.com/django-guardian/django-guardian
|
||||
[0.4]: https://github.com/encode/django-rest-framework/tree/0.4.X
|
||||
[image]: img/quickstart.png
|
||||
[index]: .
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Optional packages which may be used with REST framework.
|
||||
markdown==2.6.4
|
||||
django-guardian==1.4.6
|
||||
django-guardian==1.4.8
|
||||
django-filter==1.0.0
|
||||
coreapi==2.2.4
|
||||
coreschema==0.0.4
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -316,6 +316,7 @@ class DefaultRouter(SimpleRouter):
|
|||
default_schema_renderers = None
|
||||
APIRootView = APIRootView
|
||||
APISchemaView = SchemaView
|
||||
SchemaGenerator = SchemaGenerator
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'schema_title' in kwargs:
|
||||
|
@ -342,7 +343,7 @@ class DefaultRouter(SimpleRouter):
|
|||
"""
|
||||
Return a schema root view.
|
||||
"""
|
||||
schema_generator = SchemaGenerator(
|
||||
schema_generator = self.SchemaGenerator(
|
||||
title=self.schema_title,
|
||||
url=self.schema_url,
|
||||
patterns=api_urls
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user