@@ -958,8 +958,6 @@ In order to produce an OAS schema that properly represents the JSON:API structur
958
958
you have to either add a ` schema ` attribute to each view class or set the ` REST_FRAMEWORK['DEFAULT_SCHEMA_CLASS'] `
959
959
to DJA's version of AutoSchema.
960
960
961
- You can also extend the OAS schema with additional static content (a feature not available in DRF at this time).
962
-
963
961
#### View-based
964
962
965
963
``` python
@@ -979,16 +977,16 @@ REST_FRAMEWORK = {
979
977
}
980
978
```
981
979
982
- ### Adding static OAS schema content
980
+ ### Adding additional OAS schema content
983
981
984
- You can optionally include an OAS schema document initialization by subclassing ` SchemaGenerator `
985
- and setting ` schema_init ` .
982
+ You can extend the OAS schema document by subclassing
983
+ [ ` SchemaGenerator ` ] ( https://www.django-rest-framework.org/api-guide/schemas/#schemagenerator )
984
+ and extending ` get_schema ` .
986
985
987
- Here's an example that fills out OAS ` info ` and ` servers ` objects.
988
986
989
- ``` python
990
- # views.py
987
+ Here's an example that adds OAS ` info ` and ` servers ` objects.
991
988
989
+ ``` python
992
990
from rest_framework_json_api.schemas.openapi import SchemaGenerator as JSONAPISchemaGenerator
993
991
994
992
@@ -1047,14 +1045,22 @@ is published.
1047
1045
### Generate a Dynamic Schema in a View
1048
1046
1049
1047
See [ DRF documentation for a Dynamic Schema] ( https://www.django-rest-framework.org/api-guide/schemas/#generating-a-dynamic-schema-with-schemaview ) .
1050
- You will need to pass in your custom SchemaGenerator if you've created one.
1051
1048
1052
1049
``` python
1053
1050
from rest_framework.schemas import get_schema_view
1054
- from views import MySchemaGenerator
1055
1051
1056
1052
urlpatterns = [
1057
- path(' openapi' , get_schema_view(generator_class = MySchemaGenerator), name = ' openapi-schema' ),
1053
+ ...
1054
+ path(' openapi' , get_schema_view(
1055
+ title = " Example API" ,
1056
+ description = " API for all things …" ,
1057
+ version = " 1.0.0" ,
1058
+ generator_class = MySchemaGenerator,
1059
+ ), name = ' openapi-schema' ),
1060
+ path(' swagger-ui/' , TemplateView.as_view(
1061
+ template_name = ' swagger-ui.html' ,
1062
+ extra_context = {' schema_url' : ' openapi-schema' }
1063
+ ), name = ' swagger-ui' ),
1058
1064
...
1059
1065
]
1060
1066
```
0 commit comments