Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema generation overriding #5335

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion rest_framework/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class Field(object):

def __init__(self, read_only=False, write_only=False,
required=None, default=empty, initial=empty, source=None,
label=None, help_text=None, style=None,
label=None, help_text=None, schema=None, style=None,
error_messages=None, validators=None, allow_null=False):
self._creation_counter = Field._creation_counter
Field._creation_counter += 1
Expand Down Expand Up @@ -342,6 +342,9 @@ def __init__(self, read_only=False, write_only=False,
if validators is not None:
self.validators = validators[:]

if schema is not None:
self.schema = schema

# These are set up by `.bind()` when the field is added to a serializer.
self.field_name = None
self.parent = None
Expand Down
2 changes: 1 addition & 1 deletion rest_framework/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def __str__(self):
# rather than the parent serializer.
MANY_RELATION_KWARGS = (
'read_only', 'write_only', 'required', 'default', 'initial', 'source',
'label', 'help_text', 'style', 'error_messages', 'allow_empty',
'label', 'help_text', 'schema', 'style', 'error_messages', 'allow_empty',
'html_cutoff', 'html_cutoff_text'
)

Expand Down
3 changes: 3 additions & 0 deletions rest_framework/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@


def field_to_schema(field):
if hasattr(field, 'schema'):
return field.schema

title = force_text(field.label) if field.label else ''
description = force_text(field.help_text) if field.help_text else ''

Expand Down
4 changes: 2 additions & 2 deletions rest_framework/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
# rather than the parent serializer.
LIST_SERIALIZER_KWARGS = (
'read_only', 'write_only', 'required', 'default', 'initial', 'source',
'label', 'help_text', 'style', 'error_messages', 'allow_empty',
'label', 'help_text', 'schema', 'style', 'error_messages', 'allow_empty',
'instance', 'data', 'partial', 'context', 'allow_null'
)

Expand Down Expand Up @@ -1174,7 +1174,7 @@ def build_standard_field(self, field_name, model_field):
valid_kwargs = set((
'read_only', 'write_only',
'required', 'default', 'initial', 'source',
'label', 'help_text', 'style',
'label', 'help_text', 'schema', 'style',
'error_messages', 'validators', 'allow_null', 'allow_blank',
'choices'
))
Expand Down