schemas: # Top-down schema generation # Per-endpoint view introspection # Shared helper functions # Houses SchemaView, APIView subclass.

We expose a minimal “public” API directly from schemas. This covers the basic use-cases:

from rest_framework.schemas import (
AutoSchema, ManualSchema, get_schema_view, SchemaGenerator,


Other access should target the submodules directly

Package Contents

class SchemaGenerator(title=None, url=None, description=None, patterns=None, urlconf=None)


get_schema(self, request=None, public=False)

Generate a coreapi.Document representing the API schema.

Return a dictionary containing all the links that should be included in the API schema.

determine_path_prefix(self, paths)

Given a list of all paths, return the common prefix which should be discounted when generating a schema structure.

This will be the longest common string that does not include that last component of the URL, or the last component before a path parameter.

For example:

/api/v1/users/ /api/v1/users/{pk}/

The path prefix is ‘/api/v1/’

create_view(self, callback, method, request=None)

Given a callback, return an actual view instance.

has_view_permissions(self, path, method, view)

Return True if the incoming request has the correct view permissions.

coerce_path(self, path, method, view)

Coerce {pk} path arguments into the name of the model field, where possible. This is cleaner for an external representation. (Ie. “this is an identifier”, not “this is a database primary key”)

get_keys(self, subpath, method, view)

Return a list of keys that should be used to layout a link within the schema document.

/users/ (“users”, “list”), (“users”, “create”) /users/{pk}/ (“users”, “read”), (“users”, “update”), (“users”, “delete”) /users/enabled/ (“users”, “enabled”) # custom viewset list action /users/{pk}/star/ (“users”, “star”) # custom viewset detail action /users/{pk}/groups/ (“users”, “groups”, “list”), (“users”, “groups”, “create”) /users/{pk}/groups/{pk}/ (“users”, “groups”, “read”), (“users”, “groups”, “update”), (“users”, “groups”, “delete”)

class AutoSchema(manual_fields=None)


Default inspector for APIView

Responsible for per-view introspection and schema generation.

get_description(self, path, method)

Determine a link description.

This will be based on the method docstring if one exists, or else the class docstring.

_get_description_section(self, view, header, description)
get_path_fields(self, path, method)

Return a list of coreapi.Field instances corresponding to any templated path variables.

get_serializer_fields(self, path, method)

Return a list of coreapi.Field instances corresponding to any request body input, as determined by the serializer class.

get_pagination_fields(self, path, method)
_allows_filters(self, path, method)

Determine whether to include filter Fields in schema.

Default implementation looks for ModelViewSet or GenericAPIView actions/methods that cause filtering on the default implementation.

Override to adjust behaviour for your view.

Note: Introduced in v3.7: Initially “private” (i.e. with leading underscore)
to allow changes based on user experience.
get_filter_fields(self, path, method)
get_manual_fields(self, path, method)
static update_fields(fields, update_with)

Update list of coreapi.Field instances, overwriting on

Utility function to handle replacing coreapi.Field fields from a list by name. Used to handle manual_fields.


  • fields: list of coreapi.Field instances to update
  • update_with: list of `coreapi.Field instances to add or replace.
get_encoding(self, path, method)

Return the ‘encoding’ parameter to use for a given endpoint.

class DefaultSchema


Allows overriding AutoSchema using DEFAULT_SCHEMA_CLASS setting

__get__(self, instance, owner)
class ManualSchema(fields, description='', encoding=None)


Allows providing a list of coreapi.Fields, plus an optional description.

get_schema_view(title=None, url=None, description=None, urlconf=None, renderer_classes=None, public=False, patterns=None, generator_class=SchemaGenerator, authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES, permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES)

Return a schema view.