Debian Codegraph @

docs/community/3.9-announcement.md

raw ◀ ▶
1 Debian patch touch this file
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.9
21
22 The 3.9 release gives access to _extra actions_ in the Browsable API, introduces composable permissions and built-in [OpenAPI][openapi] schema support. (Formerly known as Swagger)
23
24 ---
25
26 ## Funding
27
28 If you use REST framework commercially and would like to see this work continue, we strongly encourage you to invest in its continued development by
29 **[signing up for a paid&nbsp;plan][funding]**.
30
31 *Many thanks to all our [wonderful sponsors][sponsors], and in particular to our premium backers, [Rover](https://www.rover.com/careers/), [Sentry](https://sentry.io/welcome/), [Stream](https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf), [Auklet](https://auklet.io/), [Rollbar](https://rollbar.com), [Cadre](https://cadre.com), [Load Impact](https://loadimpact.com/?utm_campaign=Sponsorship%20links&utm_source=drf&utm_medium=drf), and [Kloudless](https://hubs.ly/H0f30Lf0).*
32
33 ---
34
35 ## Built-in OpenAPI schema support
36
37 REST framework now has a first-pass at directly including OpenAPI schema support. (Formerly known as Swagger)
38
39 Specifically:
40
41 * There are now `OpenAPIRenderer`, and `JSONOpenAPIRenderer` classes that deal with encoding `coreapi.Document` instances into OpenAPI YAML or OpenAPI JSON.
42 * The `get_schema_view(...)` method now defaults to OpenAPI YAML, with CoreJSON as a secondary
43 option if it is selected via HTTP content negotiation.
44 * There is a new management command `generateschema`, which you can use to dump
45 the schema into your repository.
46
47 Here's an example of adding an OpenAPI schema to the URL conf:
48
49 ```python
50 from rest_framework.schemas import get_schema_view
51 from rest_framework.renderers import JSONOpenAPIRenderer
52 from django.urls import path
53
54 schema_view = get_schema_view(
55 title="Server Monitoring API",
56 url="https://www.example.org/api/",
57 renderer_classes=[JSONOpenAPIRenderer],
58 )
59
60 urlpatterns = [path("schema.json", schema_view), ...]
61 ```
62
63 And here's how you can use the `generateschema` management command:
64
65 ```shell
66 $ python manage.py generateschema --format openapi > schema.yml
67 ```
68
69 There's lots of different tooling that you can use for working with OpenAPI
70 schemas. One option that we're working on is the [API Star](https://docs.apistar.com/)
71 command line tool.
72
73 You can use `apistar` to validate your API schema:
74
75 ```shell
76 $ apistar validate --path schema.json --format openapi
77 ✓ Valid OpenAPI schema.
78 ```
79
80 Or to build API documentation:
81
82 ```shell
83 $ apistar docs --path schema.json --format openapi
84 ✓ Documentation built at "build/index.html".
85 ```
86
87 API Star also includes a [dynamic client library](https://docs.apistar.com/client-library/)
88 that uses an API schema to automatically provide a client library interface for making requests.
89
90 ## Composable permission classes
91
92 You can now compose permission classes using the and/or operators, `&` and `|`.
93
94 For example...
95
96 ```python
97 permission_classes = [IsAuthenticated & (ReadOnly | IsAdminUser)]
98 ```
99
100 If you're using custom permission classes then make sure that you are subclassing
101 from `BasePermission` in order to enable this support.
102
103 ## ViewSet _Extra Actions_ available in the Browsable API
104
105 Following the introduction of the `action` decorator in v3.8, _extra actions_ defined on a ViewSet are now available
106 from the Browsable API.
107
•108 [Extra Actions displayed in the Browsable API](https://user-images.githubusercontent.com/2370209/32976956-1ca9ab7e-cbf1-11e7-981a-a20cb1e83d63.png)
109
110 When defined, a dropdown of "Extra Actions", appropriately filtered to detail/non-detail actions, is displayed.
111
112 ---
113
114 ## Supported Versions
115
116 REST framework 3.9 supports Django versions 1.11, 2.0, and 2.1.
117
118 ---
119
120 ## Deprecations
121
122 ### `DjangoObjectPermissionsFilter` moved to third-party package.
123
124 The `DjangoObjectPermissionsFilter` class is pending deprecation, will be deprecated in 3.10 and removed entirely in 3.11.
125
126 It has been moved to the third-party [`djangorestframework-guardian`](https://github.com/rpkilby/django-rest-framework-guardian)
127 package. Please use this instead.
128
129 ### Router argument/method renamed to use `basename` for consistency.
130
131 * The `Router.register` `base_name` argument has been renamed in favor of `basename`.
132 * The `Router.get_default_base_name` method has been renamed in favor of `Router.get_default_basename`. [#5990][gh5990]
133
134 See [#5990][gh5990].
135
136 [gh5990]: https://github.com/encode/django-rest-framework/pull/5990
137
138 `base_name` and `get_default_base_name()` are pending deprecation. They will be deprecated in 3.10 and removed entirely in 3.11.
139
140 ### `action` decorator replaces `list_route` and `detail_route`
141
142 Both `list_route` and `detail_route` are now deprecated in favor of the single `action` decorator.
143 They will be removed entirely in 3.10.
144
145 The `action` decorator takes a boolean `detail` argument.
146
147 * Replace `detail_route` uses with `@action(detail=True)`.
148 * Replace `list_route` uses with `@action(detail=False)`.
149
150 ### `exclude_from_schema`
151
152 Both `APIView.exclude_from_schema` and the `exclude_from_schema` argument to the `@api_view` have now been removed.
153
154 For `APIView` you should instead set a `schema = None` attribute on the view class.
155
156 For function-based views the `@schema` decorator can be used to exclude the view from the schema, by using `@schema(None)`.
157
158 ---
159
160 ## Minor fixes and improvements
161
162 There are a large number of minor fixes and improvements in this release. See the [release notes](release-notes.md) page for a complete listing.
163
164
165 ## What's next
166
167 We're planning to iteratively work towards OpenAPI becoming the standard schema
168 representation. This will mean that the `coreapi` dependency will gradually become
169 removed, and we'll instead generate the schema directly, rather than building
170 a CoreAPI `Document` object.
171
172 OpenAPI has clearly become the standard for specifying Web APIs, so there's not
173 much value any more in our schema-agnostic document model. Making this change
174 will mean that we'll more easily be able to take advantage of the full set of
175 OpenAPI functionality.
176
177 This will also make a wider range of tooling available.
178
179 We'll focus on continuing to develop the [API Star](https://docs.apistar.com/)
180 library and client tool into a recommended option for generating API docs,
181 validating API schemas, and providing a dynamic client library.
182
183 There's also a huge amount of ongoing work on maturing the ASGI landscape,
184 with the possibility that some of this work will eventually [feed back into
185 Django](https://www.aeracode.org/2018/06/04/django-async-roadmap/).
186
187 There will be further work on the [Uvicorn](https://www.uvicorn.org/)
188 web server, as well as lots of functionality planned for the [Starlette](https://www.starlette.io/)
189 web framework, which is building a foundational set of tooling for working with
190 ASGI.
191
192
193 [funding]: https://opencollective.com/django-rest-framework
194 [gh5886]: https://github.com/encode/django-rest-framework/issues/5886
195 [gh5705]: https://github.com/encode/django-rest-framework/issues/5705
196 [openapi]: https://www.openapis.org/
197 [sponsors]: https://fund.django-rest-framework.org/topics/funding/#our-sponsors