Skip to content

Commit

Permalink
Added docs for map_field()
Browse files Browse the repository at this point in the history
  • Loading branch information
carltongibson committed Apr 6, 2020
1 parent 3503b56 commit d42d456
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/api-guide/schemas.md
Expand Up @@ -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)

This comment has been minimized.

Copy link
@synic

synic Apr 6, 2020

Missing .

This comment has been minimized.

Copy link
@carltongibson

carltongibson Apr 10, 2020

Author Owner

Thanks @synic!

```

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


Expand Down

0 comments on commit d42d456

Please sign in to comment.