mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Merge fe856472c9
into 836e49b535
This commit is contained in:
commit
7e26ba1aa8
|
@ -767,6 +767,10 @@ class CharField(Field):
|
|||
return six.text_type(value)
|
||||
|
||||
|
||||
class QueryParamField(CharField):
|
||||
pass
|
||||
|
||||
|
||||
class EmailField(CharField):
|
||||
default_error_messages = {
|
||||
'invalid': _('Enter a valid email address.')
|
||||
|
|
|
@ -564,8 +564,12 @@ class SchemaGenerator(object):
|
|||
Return a list of `coreapi.Field` instances corresponding to any
|
||||
request body input, as determined by the serializer class.
|
||||
"""
|
||||
if method not in ('PUT', 'PATCH', 'POST'):
|
||||
return []
|
||||
|
||||
if hasattr(view, 'action') and view.action == 'add_item':
|
||||
pass
|
||||
|
||||
body_allowed_methods = ('PUT', 'PATCH', 'POST')
|
||||
method_allow_body = method in body_allowed_methods
|
||||
|
||||
if not hasattr(view, 'get_serializer'):
|
||||
return []
|
||||
|
@ -590,10 +594,15 @@ class SchemaGenerator(object):
|
|||
if field.read_only or isinstance(field, serializers.HiddenField):
|
||||
continue
|
||||
|
||||
location = 'query' if isinstance(field, serializers.QueryParamField) else 'form'
|
||||
|
||||
if not method_allow_body and location != 'query':
|
||||
continue
|
||||
|
||||
required = field.required and method != 'PATCH'
|
||||
field = coreapi.Field(
|
||||
name=field.field_name,
|
||||
location='form',
|
||||
location=location,
|
||||
required=required,
|
||||
schema=field_to_schema(field)
|
||||
)
|
||||
|
|
|
@ -57,7 +57,7 @@ from rest_framework.fields import ( # NOQA # isort:skip
|
|||
DictField, DurationField, EmailField, Field, FileField, FilePathField, FloatField,
|
||||
HiddenField, IPAddressField, ImageField, IntegerField, JSONField, ListField,
|
||||
ModelField, MultipleChoiceField, NullBooleanField, ReadOnlyField, RegexField,
|
||||
SerializerMethodField, SlugField, TimeField, URLField, UUIDField,
|
||||
SerializerMethodField, SlugField, TimeField, URLField, UUIDField, QueryParamField,
|
||||
)
|
||||
from rest_framework.relations import ( # NOQA # isort:skip
|
||||
HyperlinkedIdentityField, HyperlinkedRelatedField, ManyRelatedField,
|
||||
|
|
Loading…
Reference in New Issue
Block a user