rest_framework.schemas.inspectors # Per-endpoint view introspection

See for package overview.

Module Contents

get_pk_description(model, model_field)
class ViewInspector


Descriptor class on APIView.

Provide subclass for per-view schema generation


View property.

__get__(self, instance, owner)

Enables ViewInspector as a Python _Descriptor_.

This is how view.schema knows about view.

__get__ is called when the descriptor is accessed on the owner. (That will be when view.schema is called in our case.)

owner is always the owner class. (An APIView, or subclass for us.) instance is the view instance or None if accessed from the class, rather than an instance.

See: for info on descriptor usage.

__set__(self, instance, other)

Generate coreapi.Link for self.view, path and method.

This is the main _public_ access point.


  • path: Route path for view from URLConf.
  • method: The HTTP request method.
  • base_url: The project “mount point” as given to SchemaGenerator
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 ManualSchema(fields, description='', encoding=None)


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

class DefaultSchema


Allows overriding AutoSchema using DEFAULT_SCHEMA_CLASS setting

__get__(self, instance, owner)