diff --git a/docs/api-guide/schemas.md b/docs/api-guide/schemas.md index 234be128e5..b1b1a5e354 100644 --- a/docs/api-guide/schemas.md +++ b/docs/api-guide/schemas.md @@ -240,6 +240,29 @@ Not all `AutoSchema` methods expose related `__init__()` kwargs, but those for ### `AutoSchema` methods + + +#### `map_field()` + +Maps individual serializer fields to their schema representation. The base implementation +will handle the default fields that Django REST Framework provides. + +For `SerializerMethodField` instances, for which the schema is unknown, or custom field subclasses you should override `map_field()` to generate the correct schema: + +```python +class CustomSchema(AutoSchema): + """Extension of ``AutoSchema`` to add support for custom field schemas.""" + + def map_field(self, field): + # Handle SerializerMethodFields or custom fields here... + # ... + return super()map_field(field) +``` + +Authors of third-party packages should aim to provide an `AutoSchema` subclass, +and a mixin overriding `map_field()` so that users can easily generate schemas +for their custom fields. + ### `AutoSchema.__init__()` kwargs