You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/topics/documenting-your-api.md
+26-4Lines changed: 26 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,7 @@ The `rest_framework.documentation` module provides three helper functions to hel
107
107
*`generator_class`: Default `rest_framework.schemas.SchemaGenerator`. May be used to specify a `SchemaGenerator` subclass to be passed to the `SchemaView`.
108
108
*`authentication_classes`: Default `api_settings.DEFAULT_AUTHENTICATION_CLASSES`. May be used to pass custom authentication classes to the `SchemaView`.
109
109
*`permission_classes`: Default `api_settings.DEFAULT_PERMISSION_CLASSES` May be used to pass custom permission classes to the `SchemaView`.
110
+
*`renderer_classes`: Default `None`. May be used to pass custom renderer classes to the `SchemaView`.
110
111
111
112
#### `get_docs_view`
112
113
@@ -117,7 +118,8 @@ The `rest_framework.documentation` module provides three helper functions to hel
117
118
*`patterns`: Default `None`. A list of URLs to inspect when generating the schema. If `None` project's URL conf will be used.
118
119
*`generator_class`: Default `rest_framework.schemas.SchemaGenerator`. May be used to specify a `SchemaGenerator` subclass to be passed to the `SchemaView`.
119
120
*`authentication_classes`: Default `api_settings.DEFAULT_AUTHENTICATION_CLASSES`. May be used to pass custom authentication classes to the `SchemaView`.
120
-
*`permission_classes`: Default `api_settings.DEFAULT_PERMISSION_CLASSES` May be used to pass custom permission classes to the `SchemaView`.
121
+
*`permission_classes`: Default `api_settings.DEFAULT_PERMISSION_CLASSES`. May be used to pass custom permission classes to the `SchemaView`.
122
+
*`renderer_classes`: Default `None`. May be used to pass custom renderer classes to the `SchemaView`. If `None` the `SchemaView` will be configured with `DocumentationRenderer` and `CoreJSONRenderer` renderers, corresponding to the (default) `html` and `corejson` formats.
121
123
122
124
#### `get_schemajs_view`
123
125
@@ -130,6 +132,25 @@ The `rest_framework.documentation` module provides three helper functions to hel
130
132
*`authentication_classes`: Default `api_settings.DEFAULT_AUTHENTICATION_CLASSES`. May be used to pass custom authentication classes to the `SchemaView`.
131
133
*`permission_classes`: Default `api_settings.DEFAULT_PERMISSION_CLASSES` May be used to pass custom permission classes to the `SchemaView`.
132
134
135
+
136
+
### Customising code samples
137
+
138
+
The built-in API documentation includes automatically generated code samples for
139
+
each of the available API client libraries.
140
+
141
+
You may customise these samples by subclassing `DocumentationRenderer`, setting
142
+
`languages` to the list of languages you wish to support:
143
+
144
+
from rest_framework.renderers import DocumentationRenderer
145
+
146
+
147
+
class CustomRenderer(DocumentationRenderer):
148
+
languages = ['ruby', 'go']
149
+
150
+
For each language you need to provide an `intro` template, detailing installation instructions and such,
151
+
plus a generic template for making API requests, that can be filled with individual request details.
152
+
See the [templates for the bundled languages][client-library-templates] for examples.
153
+
133
154
---
134
155
135
156
## Third party packages
@@ -138,11 +159,11 @@ There are a number of mature third-party packages for providing API documentatio
138
159
139
160
#### drf-yasg - Yet Another Swagger Generator
140
161
141
-
[drf-yasg][drf-yasg] is a [Swagger][swagger] generation tool implemented without using the schema generation provided
162
+
[drf-yasg][drf-yasg] is a [Swagger][swagger] generation tool implemented without using the schema generation provided
142
163
by Django Rest Framework.
143
164
144
-
It aims to implement as much of the [OpenAPI][open-api] specification as possible - nested schemas, named models,
145
-
response bodies, enum/pattern/min/max validators, form parameters, etc. - and to generate documents usable with code
165
+
It aims to implement as much of the [OpenAPI][open-api] specification as possible - nested schemas, named models,
166
+
response bodies, enum/pattern/min/max validators, form parameters, etc. - and to generate documents usable with code
146
167
generation tools like `swagger-codegen`.
147
168
148
169
This also translates into a very useful interactive documentation viewer in the form of `swagger-ui`:
@@ -314,3 +335,4 @@ To implement a hypermedia API you'll need to decide on an appropriate media type
0 commit comments