diff --git a/api-guide/schemas/index.html b/api-guide/schemas/index.html index 6e47178c6..05eefaa36 100644 --- a/api-guide/schemas/index.html +++ b/api-guide/schemas/index.html @@ -572,14 +572,14 @@ permission, throttling or authentication policies to the schema endpoint.

return the schema.

views.py:

from rest_framework.decorators import api_view, renderer_classes
-from rest_framework import renderers, schemas
+from rest_framework import renderers, response, schemas
 
-generator = schemas.SchemaGenerator(title='Bookings API')
 
 @api_view()
 @renderer_classes([renderers.CoreJSONRenderer])
 def schema_view(request):
-    return generator.get_schema()
+    generator = schemas.SchemaGenerator(title='Bookings API')
+    return response.Response(generator.get_schema())
 

urls.py:

urlpatterns = [
@@ -597,7 +597,8 @@ you need to pass the request argument to the get_schema()@api_view()
 @renderer_classes([renderers.CoreJSONRenderer])
 def schema_view(request):
-    return generator.get_schema(request=request)
+    generator = schemas.SchemaGenerator(title='Bookings API')
+    return response.Response(generator.get_schema(request=request))
 

Explicit schema definition

An alternative to the auto-generated approach is to specify the API schema @@ -606,7 +607,7 @@ little more work, but ensures that you have full control over the schema representation.

import coreapi
 from rest_framework.decorators import api_view, renderer_classes
-from rest_framework import renderers
+from rest_framework import renderers, response
 
 schema = coreapi.Document(
     title='Bookings API',
@@ -618,7 +619,7 @@ schema = coreapi.Document(
 @api_view()
 @renderer_classes([renderers.CoreJSONRenderer])
 def schema_view(request):
-    return schema
+    return response.Response(schema)
 

Static schema file

A final option is to write your API schema as a static file, using one @@ -668,7 +669,8 @@ generate a schema.

@api_view
 @renderer_classes([renderers.CoreJSONRenderer])
 def schema_view(request):
-    return generator.get_schema()
+    generator = schemas.SchemaGenerator(title='Bookings API')
+    return Response(generator.get_schema())
 

Arguments: