Skip to content

Commit b87699c

Browse files
tfranzelauvipytomchristie
authored
Update schema generation doc & add deprecation notice #8453 (#8773)
* Update schema generation doc & add deprecation notice #8453 * Update docs/topics/documenting-your-api.md Co-authored-by: Tom Christie <[email protected]> * Update docs/topics/documenting-your-api.md Co-authored-by: Tom Christie <[email protected]> * Update docs/topics/documenting-your-api.md Co-authored-by: Tom Christie <[email protected]> Co-authored-by: T. Franzel <[email protected]> Co-authored-by: Asif Saif Uddin <[email protected]> Co-authored-by: Tom Christie <[email protected]>
1 parent fd7d3a7 commit b87699c

File tree

2 files changed

+52
-33
lines changed

2 files changed

+52
-33
lines changed

docs/api-guide/schemas.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,23 @@ source:
99
>
1010
> &mdash; Heroku, [JSON Schema for the Heroku Platform API][cite]
1111
12+
---
13+
14+
**Deprecation notice:**
15+
16+
REST framework's built-in support for generating OpenAPI schemas is
17+
**deprecated** in favor of 3rd party packages that can provide this
18+
functionality instead. The built-in support will be moved into a separate
19+
package and then subsequently retired over the next releases.
20+
21+
As a full-fledged replacement, we recommend the [drf-spectacular] package.
22+
It has extensive support for generating OpenAPI 3 schemas from
23+
REST framework APIs, with both automatic and customisable options available.
24+
For further information please refer to
25+
[Documenting your API](../topics/documenting-your-api.md#drf-spectacular).
26+
27+
---
28+
1229
API schemas are a useful tool that allow for a range of use cases, including
1330
generating reference documentation, or driving dynamic client libraries that
1431
can interact with your API.
@@ -438,3 +455,4 @@ create a base `AutoSchema` subclass for your project that takes additional
438455
[openapi-generator]: https://github.com/OpenAPITools/openapi-generator
439456
[swagger-codegen]: https://github.com/swagger-api/swagger-codegen
440457
[info-object]: https://swagger.io/specification/#infoObject
458+
[drf-spectacular]: https://drf-spectacular.readthedocs.io/en/latest/readme.html

docs/topics/documenting-your-api.md

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,42 @@
44
>
55
> &mdash; Roy Fielding, [REST APIs must be hypertext driven][cite]
66
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.
99

10-
There are also a number of great third-party documentation packages available.
10+
## Third party packages for OpenAPI support
1111

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.**
1343

1444
There are a number of packages available that allow you to generate HTML
1545
documentation pages from OpenAPI schemas.
@@ -124,35 +154,6 @@ urlpatterns = [
124154

125155
See the [ReDoc documentation][redoc] for advanced usage.
126156

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-
---
156157

157158
## Self describing APIs
158159

0 commit comments

Comments
 (0)