Skip to content

Commit 8385ae4

Browse files
3.4.0 Release (#4258)
* 3.4.0 Release * Version 3.4 release * Full release notes * Update translation files * Update release documentation * Update release notes * Docs on supporting alternate schema formats * Add schema_renderers to DefaultRouter
1 parent 6defb8d commit 8385ae4

File tree

113 files changed

+5104
-5634
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+5104
-5634
lines changed

docs/api-guide/schemas.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ has to be rendered into the actual bytes that are used in the response.
6868
REST framework includes a renderer class for handling this media type, which
6969
is available as `renderers.CoreJSONRenderer`.
7070

71-
Other schema formats such as [Open API][open-api] (Formerly "Swagger"),
71+
Other schema formats such as [Open API][open-api] ("Swagger"),
7272
[JSON HyperSchema][json-hyperschema], or [API Blueprint][api-blueprint] can
7373
also be supported by implementing a custom renderer class.
7474

@@ -126,16 +126,29 @@ that include the Core JSON media type in their `Accept` header.
126126
}
127127

128128
This is a great zero-configuration option for when you want to get up and
129-
running really quickly. If you want a little more flexibility over the
130-
schema output then you'll need to consider using `SchemaGenerator` instead.
129+
running really quickly.
130+
131+
The only other available option to `DefaultRouter` is `schema_renderers`, which
132+
may be used to pass the set of renderer classes that can be used to render
133+
schema output.
134+
135+
from rest_framework.renderers import CoreJSONRenderer
136+
from my_custom_package import APIBlueprintRenderer
137+
138+
router = DefaultRouter(schema_title='Server Monitoring API', schema_renderers=[
139+
CoreJSONRenderer, APIBlueprintRenderer
140+
])
141+
142+
If you want more flexibility over the schema output then you'll need to consider
143+
using `SchemaGenerator` instead.
131144

132145
## Using SchemaGenerator
133146

134147
The most common way to add a schema to your API is to use the `SchemaGenerator`
135148
class to auto-generate the `Document` instance, and to return that from a view.
136149

137150
This option gives you the flexibility of setting up the schema endpoint
138-
with whatever behaviour you want. For example, you can apply different
151+
with whatever behavior you want. For example, you can apply different
139152
permission, throttling or authentication policies to the schema endpoint.
140153

141154
Here's an example of using `SchemaGenerator` together with a view to
@@ -210,6 +223,32 @@ You could then either:
210223

211224
---
212225

226+
# Alternate schema formats
227+
228+
In order to support an alternate schema format, you need to implement a custom renderer
229+
class that handles converting a `Document` instance into a bytestring representation.
230+
231+
If there is a Core API codec package that supports encoding into the format you
232+
want to use then implementing the renderer class can be done by using the codec.
233+
234+
## Example
235+
236+
For example, the `openapi_codec` package provides support for encoding or decoding
237+
to the Open API ("Swagger") format:
238+
239+
from rest_framework import renderers
240+
from openapi_codec import OpenAPICodec
241+
242+
class SwaggerRenderer(renderers.BaseRenderer):
243+
media_type = 'application/openapi+json;version=2.0'
244+
format = 'swagger'
245+
246+
def render(self, data, media_type=None, renderer_context=None):
247+
codec = OpenAPICodec()
248+
return OpenAPICodec.dump(data)
249+
250+
---
251+
213252
# API Reference
214253

215254
## SchemaGenerator

docs/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Right now we're over 58% of the way towards achieving that.
7878
</ul>
7979
<div style="clear: both; padding-bottom: 20px;"></div>
8080

81-
*Many thanks to all our [awesome sponsors][sponsors], and in particular to our premium backers, [Rover](http://jobs.rover.com/), [Sentry](https://getsentry.com/welcome/), and [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf).*
81+
*Many thanks to all our [wonderful sponsors][sponsors], and in particular to our premium backers, [Rover](http://jobs.rover.com/), [Sentry](https://getsentry.com/welcome/), and [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf).*
8282

8383
---
8484

@@ -243,6 +243,7 @@ General guides to using REST framework.
243243
* [3.1 Announcement][3.1-announcement]
244244
* [3.2 Announcement][3.2-announcement]
245245
* [3.3 Announcement][3.3-announcement]
246+
* [3.4 Announcement][3.4-announcement]
246247
* [Kickstarter Announcement][kickstarter-announcement]
247248
* [Mozilla Grant][mozilla-grant]
248249
* [Funding][funding]
@@ -368,6 +369,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
368369
[3.1-announcement]: topics/3.1-announcement.md
369370
[3.2-announcement]: topics/3.2-announcement.md
370371
[3.3-announcement]: topics/3.3-announcement.md
372+
[3.4-announcement]: topics/3.4-announcement.md
371373
[kickstarter-announcement]: topics/kickstarter-announcement.md
372374
[mozilla-grant]: topics/mozilla-grant.md
373375
[funding]: topics/funding.md

docs/topics/3.4-announcement.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<style>
2+
.promo li a {
3+
float: left;
4+
width: 130px;
5+
height: 20px;
6+
text-align: center;
7+
margin: 10px 30px;
8+
padding: 150px 0 0 0;
9+
background-position: 0 50%;
10+
background-size: 130px auto;
11+
background-repeat: no-repeat;
12+
font-size: 120%;
13+
color: black;
14+
}
15+
.promo li {
16+
list-style: none;
17+
}
18+
</style>
19+
20+
# Django REST framework 3.4
21+
22+
The 3.4 release is the first in a planned series that will be addressing schema
23+
generation, hypermedia support, API clients, and finally realtime support.
24+
25+
---
26+
27+
## Funding
28+
29+
The 3.4 release has been made possible a recent [Mozilla grant][moss], and by our
30+
[collaborative funding model][funding]. If you use REST framework commercially, and would
31+
like to see this work continue, we strongly encourage you to invest in its
32+
continued development by **[signing up for a paid plan][funding]**.
33+
34+
The initial aim is to provide a single full-time position on REST framework.
35+
Right now we're over 60% of the way towards achieving that.
36+
*Every single sign-up makes a significant impact.*
37+
38+
<ul class="premium-promo promo">
39+
<li><a href="http://jobs.rover.com/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/rover_130x130.png)">Rover.com</a></li>
40+
<li><a href="https://getsentry.com/welcome/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/sentry130.png)">Sentry</a></li>
41+
<li><a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/stream-130.png)">Stream</a></li>
42+
</ul>
43+
<div style="clear: both; padding-bottom: 20px;"></div>
44+
45+
*Many thanks to all our [awesome sponsors][sponsors], and in particular to our premium backers, [Rover](http://jobs.rover.com/), [Sentry](https://getsentry.com/welcome/), and [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf).*
46+
47+
---
48+
49+
## Schemas & client libraries
50+
51+
REST framework 3.4 brings built-in support for generating API schemas.
52+
53+
We provide this support by using [Core API][core-api], a Document Object Model
54+
for describing APIs.
55+
56+
Because Core API represents the API schema in an format-independent
57+
manner, we're able to render the Core API `Document` object into many different
58+
schema formats, by allowing the renderer class to determine how the internal
59+
representation maps onto the external schema format.
60+
61+
This approach should also open the door to a range of auto-generated API
62+
documentation options in the future, by rendering the `Document` object into
63+
HTML documentation pages.
64+
65+
Alongside the built-in schema support, we're also now providing the following:
66+
67+
* A [command line tool][command-line-client] for interacting with APIs.
68+
* A [Python client library][client-library] for interacting with APIs.
69+
70+
These API clients are dynamically driven, and able to interact with any API
71+
that exposes a supported schema format.
72+
73+
Dynamically driven clients allow you to interact with an API at an application
74+
layer interface, rather than a network layer interface, while still providing
75+
the benefits of RESTful Web API design.
76+
77+
We're expecting to expand the range of languages that we provide client libraries
78+
for over the coming months.
79+
80+
---
81+
82+
Current support for schema formats is as follows:
83+
84+
Name | Support | PyPI package
85+
---------------------------------|-------------------------------------|--------------------------------
86+
[Core JSON][core-json] | Schema generation & client support. | Built-in support in `coreapi`.
87+
[Swagger / OpenAPI][swagger] | Schema generation & client support. | The `openapi-codec` package.
88+
[JSON Hyper-Schema][hyperschema] | Currrently client support only. | The `hyperschema-codec` package.
89+
[API Blueprint][api-blueprint] | Not yet available. | Not yet available.
90+
91+
---
92+
93+
You can read more about any of this new functionality in the following:
94+
95+
* New tutorial section on [schemas & client libraries][tut-7].
96+
* Documentation page on [schema generation][schema-generation].
97+
* Topic page on [API clients][api-clients].
98+
99+
It is also worth noting that Marc Gibbons is currently working towards a 2.0 release of
100+
the popular Django REST Swagger package, which will tie in with our new built-in support.
101+
102+
---
103+
104+
## Supported versions
105+
106+
The 3.4.0 release adds support for Django 1.10.
107+
108+
The following versions of Python and Django are now supported:
109+
110+
* Django versions 1.8, 1.9, and 1.10.
111+
* Python versions 2.7, 3.2(\*), 3.3(\*), 3.4, 3.5.
112+
113+
(\*) Note that Python 3.2 and 3.3 are not supported from Django 1.9 onwards.
114+
115+
---
116+
117+
## Deprecations and changes
118+
119+
The 3.4 release includes very limited deprecation or behavioral changes, and
120+
should present a straightforward upgrade.
121+
122+
#### Use fields or exclude on serializer classes.
123+
124+
The following change in 3.3.0 is now escalated from "pending deprecation" to
125+
"deprecated". Its usage will continue to function but will raise warnings:
126+
127+
`ModelSerializer` and `HyperlinkedModelSerializer` should include either a `fields`
128+
option, or an `exclude` option. The `fields = '__all__'` shortcut may be used
129+
to explicitly include all fields.
130+
131+
#### Microsecond precision when returning time or datetime
132+
133+
Using the default JSON renderer and directly returning a `datetime` or `time`
134+
instance will now render with microsecond precision (6 digits), rather than
135+
millisecond precision (3 digits). This makes the output format consistent with the
136+
default string output of `serializers.DateTimeField` and `serializers.TimeField`.
137+
138+
This change *does not affect the default behavior when using serializers*,
139+
which is to serialize `datetime` and `time` instances into strings with
140+
microsecond precision.
141+
142+
The serializer behavior can be modified if needed, using the `DATETIME_FORMAT`
143+
and `TIME_FORMAT` settings.
144+
145+
The renderer behavior can be modified by setting a custom `encoder_class`
146+
attribute on a `JSONRenderer` subclass.
147+
148+
---
149+
150+
## Other improvements
151+
152+
This release includes further work from a huge number of [pull requests and issues][milestone].
153+
154+
Many thanks to all our contributors who've been involved in the release, either through raising issues, giving feedback, improving the documentation, or suggesting and implementing code changes.
155+
156+
The full set of itemized release notes [are available here][release-notes].
157+
158+
[sponsors]: https://fund.django-rest-framework.org/topics/funding/#our-sponsors
159+
[moss]: mozilla-grant.md
160+
[funding]: funding.md
161+
[core-api]: http://www.coreapi.org/
162+
[command-line-client]: api-clients#command-line-client
163+
[client-library]: api-clients#python-client-library
164+
[core-json]: http://www.coreapi.org/specification/encoding/#core-json-encoding
165+
[swagger]: https://openapis.org/specification
166+
[hyperschema]: http://json-schema.org/latest/json-schema-hypermedia.html
167+
[api-blueprint]: https://apiblueprint.org/
168+
[tut-7]: ../../tutorial/7-schemas-and-client-libraries/
169+
[schema-generation]: ../../api-guide/schemas/
170+
[api-clients]: api-clients.md
171+
[milestone]: https://github.com/tomchristie/django-rest-framework/milestone/35
172+
[release-notes]: release-notes#34

docs/topics/api-clients.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ exposes a supported schema format.
5959
To install the Core API command line client, use `pip`.
6060

6161
Note that the command-line client is a separate package to the
62-
python client library `coreapi`. Make sure to install `coreapi-cli`.
62+
python client library. Make sure to install `coreapi-cli`.
6363

6464
$ pip install coreapi-cli
6565

0 commit comments

Comments
 (0)