|
4 | 4 | >
|
5 | 5 | > — Roy Fielding, [REST APIs must be hypertext driven][cite]
|
6 | 6 |
|
7 |
| -REST framework provides built-in support for generating OpenAPI schemas, which |
8 |
| -can be used with tools that allow you to build API documentation. |
| 7 | +REST framework provides a range of different choices for documenting your API. The following |
| 8 | +is a non-exhaustive list of the most popular ones. |
9 | 9 |
|
10 |
| -There are also a number of great third-party documentation packages available. |
| 10 | +## Third party packages for OpenAPI support |
11 | 11 |
|
12 |
| -## Generating documentation from OpenAPI schemas |
| 12 | +### drf-spectacular |
| 13 | + |
| 14 | +[drf-spectacular][drf-spectacular] is an [OpenAPI 3][open-api] schema generation library with explicit |
| 15 | +focus on extensibility, customizability and client generation. It is the recommended way for |
| 16 | +generating and presenting OpenAPI schemas. |
| 17 | + |
| 18 | +The library aims to extract as much schema information as possible, while providing decorators and extensions for easy |
| 19 | +customization. There is explicit support for [swagger-codegen][swagger], [SwaggerUI][swagger-ui] and [Redoc][redoc], |
| 20 | +i18n, versioning, authentication, polymorphism (dynamic requests and responses), query/path/header parameters, |
| 21 | +documentation and more. Several popular plugins for DRF are supported out-of-the-box as well. |
| 22 | + |
| 23 | +### drf-yasg |
| 24 | + |
| 25 | +[drf-yasg][drf-yasg] is a [Swagger / OpenAPI 2][swagger] generation tool implemented without using the schema generation provided |
| 26 | +by Django Rest Framework. |
| 27 | + |
| 28 | +It aims to implement as much of the [OpenAPI 2][open-api] specification as possible - nested schemas, named models, |
| 29 | +response bodies, enum/pattern/min/max validators, form parameters, etc. - and to generate documents usable with code |
| 30 | +generation tools like `swagger-codegen`. |
| 31 | + |
| 32 | +This also translates into a very useful interactive documentation viewer in the form of `swagger-ui`: |
| 33 | + |
| 34 | +![Screenshot - drf-yasg][image-drf-yasg] |
| 35 | + |
| 36 | +--- |
| 37 | + |
| 38 | +## Built-in OpenAPI schema generation (deprecated) |
| 39 | + |
| 40 | +**Deprecation notice: REST framework's built-in support for generating OpenAPI schemas is |
| 41 | +deprecated in favor of 3rd party packages that can provide this functionality instead. |
| 42 | +As replacement, we recommend using the [drf-spectacular](#drf-spectacular) package.** |
13 | 43 |
|
14 | 44 | There are a number of packages available that allow you to generate HTML
|
15 | 45 | documentation pages from OpenAPI schemas.
|
@@ -124,35 +154,6 @@ urlpatterns = [
|
124 | 154 |
|
125 | 155 | See the [ReDoc documentation][redoc] for advanced usage.
|
126 | 156 |
|
127 |
| -## Third party packages |
128 |
| - |
129 |
| -There are a number of mature third-party packages for providing API documentation. |
130 |
| - |
131 |
| -#### drf-yasg - Yet Another Swagger Generator |
132 |
| - |
133 |
| -[drf-yasg][drf-yasg] is a [Swagger][swagger] generation tool implemented without using the schema generation provided |
134 |
| -by Django Rest Framework. |
135 |
| - |
136 |
| -It aims to implement as much of the [OpenAPI][open-api] specification as possible - nested schemas, named models, |
137 |
| -response bodies, enum/pattern/min/max validators, form parameters, etc. - and to generate documents usable with code |
138 |
| -generation tools like `swagger-codegen`. |
139 |
| - |
140 |
| -This also translates into a very useful interactive documentation viewer in the form of `swagger-ui`: |
141 |
| - |
142 |
| - |
143 |
| -![Screenshot - drf-yasg][image-drf-yasg] |
144 |
| - |
145 |
| -#### drf-spectacular - Sane and flexible OpenAPI 3.0 schema generation for Django REST framework |
146 |
| - |
147 |
| -[drf-spectacular][drf-spectacular] is a [OpenAPI 3][open-api] schema generation tool with explicit focus on extensibility, |
148 |
| -customizability and client generation. Usage patterns are very similar to [drf-yasg][drf-yasg]. |
149 |
| - |
150 |
| -It aims to extract as much schema information as possible, while providing decorators and extensions for easy |
151 |
| -customization. There is explicit support for [swagger-codegen][swagger], [SwaggerUI][swagger-ui] and [Redoc][redoc], |
152 |
| -i18n, versioning, authentication, polymorphism (dynamic requests and responses), query/path/header parameters, |
153 |
| -documentation and more. Several popular plugins for DRF are supported out-of-the-box as well. |
154 |
| - |
155 |
| ---- |
156 | 157 |
|
157 | 158 | ## Self describing APIs
|
158 | 159 |
|
|
0 commit comments