rest_framework.schemas.inspectors

inspectors.py # Per-endpoint view introspection

See schemas.__init__.py for package overview.

Module Contents

header_regex
field_to_schema(field)
get_pk_description(model, model_field)
class ViewInspector

Bases:object

Descriptor class on APIView.

Provide subclass for per-view schema generation

view

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: https://docs.python.org/3/howto/descriptor.html for info on descriptor usage.

__set__(self, instance, other)
view(self)

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

This is the main _public_ access point.

Parameters:

  • 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)

Bases:rest_framework.schemas.inspectors.ViewInspector

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 Field.name.

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

Parameters:

  • 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)

Bases:rest_framework.schemas.inspectors.ViewInspector

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

class DefaultSchema

Bases:rest_framework.schemas.inspectors.ViewInspector

Allows overriding AutoSchema using DEFAULT_SCHEMA_CLASS setting

__get__(self, instance, owner)