Skip to content

Commit e9a7f5f

Browse files
authored
Removed built-in OpenAPI support (#1288)
* Removed built-in OpenAPI support * Removed django filter schema methods
1 parent 7bb4c08 commit e9a7f5f

File tree

16 files changed

+2
-2880
lines changed

16 files changed

+2
-2880
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ any parts of the framework not mentioned in the documentation should generally b
2626
* Removed support for Python 3.8.
2727
* Removed support for Django REST framework 3.14.
2828
* Removed support for Django 5.0.
29-
29+
* Removed built-in support for generating OpenAPI schema. Use [drf-spectacular-json-api](https://github.com/jokiefer/drf-spectacular-json-api/) instead.
3030

3131
## [7.1.0] - 2024-10-25
3232

README.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ Install using ``pip``...
114114
$ # for optional package integrations
115115
$ pip install djangorestframework-jsonapi['django-filter']
116116
$ pip install djangorestframework-jsonapi['django-polymorphic']
117-
$ pip install djangorestframework-jsonapi['openapi']
118117
119118
120119
or from source...
@@ -156,8 +155,6 @@ installed and activated:
156155
Browse to
157156

158157
* http://localhost:8000 for the list of available collections (in a non-JSON:API format!),
159-
* http://localhost:8000/swagger-ui/ for a Swagger user interface to the dynamic schema view, or
160-
* http://localhost:8000/openapi for the schema view's OpenAPI specification document.
161158

162159

163160
-----

docs/getting-started.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ Install using `pip`...
6969
# for optional package integrations
7070
pip install djangorestframework-jsonapi['django-filter']
7171
pip install djangorestframework-jsonapi['django-polymorphic']
72-
pip install djangorestframework-jsonapi['openapi']
7372

7473
or from source...
7574

@@ -100,8 +99,6 @@ and add `rest_framework_json_api` to your `INSTALLED_APPS` setting below `rest_f
10099

101100
Browse to
102101
* [http://localhost:8000](http://localhost:8000) for the list of available collections (in a non-JSON:API format!),
103-
* [http://localhost:8000/swagger-ui/](http://localhost:8000/swagger-ui/) for a Swagger user interface to the dynamic schema view, or
104-
* [http://localhost:8000/openapi](http://localhost:8000/openapi) for the schema view's OpenAPI specification document.
105102

106103
## Running Tests
107104

docs/usage.md

Lines changed: 0 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,139 +1054,6 @@ The `prefetch_related` case will issue 4 queries, but they will be small and fas
10541054
### Errors
10551055
-->
10561056

1057-
## Generating an OpenAPI Specification (OAS) 3.0 schema document
1058-
1059-
DRF has a [OAS schema functionality](https://www.django-rest-framework.org/api-guide/schemas/) to generate an
1060-
[OAS 3.0 schema](https://www.openapis.org/) as a YAML or JSON file.
1061-
1062-
DJA extends DRF's schema support to generate an OAS schema in the JSON:API format.
1063-
1064-
---
1065-
1066-
**Deprecation notice:**
1067-
1068-
REST framework's built-in support for generating OpenAPI schemas is
1069-
**deprecated** in favor of 3rd party packages that can provide this
1070-
functionality instead. Therefore we have also deprecated the schema support in
1071-
Django REST framework JSON:API. The built-in support will be retired over the
1072-
next releases.
1073-
1074-
As a full-fledged replacement, we recommend the [drf-spectacular-json-api] package.
1075-
1076-
---
1077-
1078-
### AutoSchema Settings
1079-
1080-
In order to produce an OAS schema that properly represents the JSON:API structure
1081-
you have to either add a `schema` attribute to each view class or set the `REST_FRAMEWORK['DEFAULT_SCHEMA_CLASS']`
1082-
to DJA's version of AutoSchema.
1083-
1084-
#### View-based
1085-
1086-
```python
1087-
from rest_framework_json_api.schemas.openapi import AutoSchema
1088-
1089-
class MyViewset(ModelViewSet):
1090-
schema = AutoSchema
1091-
...
1092-
```
1093-
1094-
#### Default schema class
1095-
1096-
```python
1097-
REST_FRAMEWORK = {
1098-
# ...
1099-
'DEFAULT_SCHEMA_CLASS': 'rest_framework_json_api.schemas.openapi.AutoSchema',
1100-
}
1101-
```
1102-
1103-
### Adding additional OAS schema content
1104-
1105-
You can extend the OAS schema document by subclassing
1106-
[`SchemaGenerator`](https://www.django-rest-framework.org/api-guide/schemas/#schemagenerator)
1107-
and extending `get_schema`.
1108-
1109-
1110-
Here's an example that adds OAS `info` and `servers` objects.
1111-
1112-
```python
1113-
from rest_framework_json_api.schemas.openapi import SchemaGenerator as JSONAPISchemaGenerator
1114-
1115-
1116-
class MySchemaGenerator(JSONAPISchemaGenerator):
1117-
"""
1118-
Describe my OAS schema info in detail (overriding what DRF put in) and list the servers where it can be found.
1119-
"""
1120-
def get_schema(self, request, public):
1121-
schema = super().get_schema(request, public)
1122-
schema['info'] = {
1123-
'version': '1.0',
1124-
'title': 'my demo API',
1125-
'description': 'A demonstration of [OAS 3.0](https://www.openapis.org)',
1126-
'contact': {
1127-
'name': 'my name'
1128-
},
1129-
'license': {
1130-
'name': 'BSD 2 clause',
1131-
'url': 'https://github.com/django-json-api/django-rest-framework-json-api/blob/main/LICENSE',
1132-
}
1133-
}
1134-
schema['servers'] = [
1135-
{'url': 'http://localhost/v1', 'description': 'local docker'},
1136-
{'url': 'http://localhost:8000/v1', 'description': 'local dev'},
1137-
{'url': 'https://api.example.com/v1', 'description': 'demo server'},
1138-
{'url': '{serverURL}', 'description': 'provide your server URL',
1139-
'variables': {'serverURL': {'default': 'http://localhost:8000/v1'}}}
1140-
]
1141-
return schema
1142-
```
1143-
1144-
### Generate a Static Schema on Command Line
1145-
1146-
See [DRF documentation for generateschema](https://www.django-rest-framework.org/api-guide/schemas/#generating-a-static-schema-with-the-generateschema-management-command)
1147-
To generate a static OAS schema document, using the `generateschema` management command, you **must override DRF's default** `generator_class` with the DJA-specific version:
1148-
1149-
```text
1150-
$ ./manage.py generateschema --generator_class rest_framework_json_api.schemas.openapi.SchemaGenerator
1151-
```
1152-
1153-
You can then use any number of OAS tools such as
1154-
[swagger-ui-watcher](https://www.npmjs.com/package/swagger-ui-watcher)
1155-
to render the schema:
1156-
```text
1157-
$ swagger-ui-watcher myschema.yaml
1158-
```
1159-
1160-
Note: Swagger-ui-watcher will complain that "DELETE operations cannot have a requestBody"
1161-
but it will still work. This [error](https://github.com/OAI/OpenAPI-Specification/pull/2117)
1162-
in the OAS specification will be fixed when [OAS 3.1.0](https://www.openapis.org/blog/2020/06/18/openapi-3-1-0-rc0-its-here)
1163-
is published.
1164-
1165-
([swagger-ui](https://www.npmjs.com/package/swagger-ui) will work silently.)
1166-
1167-
### Generate a Dynamic Schema in a View
1168-
1169-
See [DRF documentation for a Dynamic Schema](https://www.django-rest-framework.org/api-guide/schemas/#generating-a-dynamic-schema-with-schemaview).
1170-
1171-
```python
1172-
from rest_framework.schemas import get_schema_view
1173-
1174-
urlpatterns = [
1175-
...
1176-
path('openapi', get_schema_view(
1177-
title="Example API",
1178-
description="API for all things …",
1179-
version="1.0.0",
1180-
generator_class=MySchemaGenerator,
1181-
), name='openapi-schema'),
1182-
path('swagger-ui/', TemplateView.as_view(
1183-
template_name='swagger-ui.html',
1184-
extra_context={'schema_url': 'openapi-schema'}
1185-
), name='swagger-ui'),
1186-
...
1187-
]
1188-
```
1189-
11901057
## Third Party Packages
11911058

11921059
### About Third Party Packages

example/settings/dev.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"rest_framework_json_api.renderers.BrowsableAPIRenderer",
8484
),
8585
"DEFAULT_METADATA_CLASS": "rest_framework_json_api.metadata.JSONAPIMetadata",
86-
"DEFAULT_SCHEMA_CLASS": "rest_framework_json_api.schemas.openapi.AutoSchema",
8786
"DEFAULT_FILTER_BACKENDS": (
8887
"rest_framework_json_api.filters.OrderingFilter",
8988
"rest_framework_json_api.django_filters.DjangoFilterBackend",

example/templates/swagger-ui.html

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)