From cc119d6d3d07e69826bb6ced909fe4e45d78f13b Mon Sep 17 00:00:00 2001 From: Lucas Paim Date: Thu, 11 May 2017 11:11:56 -0300 Subject: [PATCH 1/4] add QueryParamField support to auto-generated documentation --- rest_framework/fields.py | 4 ++++ rest_framework/schemas.py | 4 +++- rest_framework/serializers.py | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 41d6105ca..8649881b5 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -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.') diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index afab8f71f..ce90b437e 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -590,10 +590,12 @@ class SchemaGenerator(object): if field.read_only or isinstance(field, serializers.HiddenField): continue + location = 'query' if isinstance(field, serializers.QueryParamField) else 'form' + required = field.required and method != 'PATCH' field = coreapi.Field( name=field.field_name, - location='form', + location=location, required=required, schema=field_to_schema(field) ) diff --git a/rest_framework/serializers.py b/rest_framework/serializers.py index 5bd9b6473..c4f49f0a2 100644 --- a/rest_framework/serializers.py +++ b/rest_framework/serializers.py @@ -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, From afabebcaab38b643507a40a2b4c05c37e7773ee2 Mon Sep 17 00:00:00 2001 From: Lucas Paim Date: Thu, 11 May 2017 11:33:22 -0300 Subject: [PATCH 2/4] enable doc fields in GET requisitions --- rest_framework/schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index ce90b437e..ffaaa0f30 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -564,7 +564,7 @@ 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'): + if method not in ('PUT', 'GET', 'PATCH', 'POST'): return [] if not hasattr(view, 'get_serializer'): From fb1b6dc4728432e93126abb236f1ba6b68dd61ff Mon Sep 17 00:00:00 2001 From: Lucas Paim Date: Thu, 11 May 2017 11:46:03 -0300 Subject: [PATCH 3/4] fix doc's for GET requisition --- rest_framework/schemas.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rest_framework/schemas.py b/rest_framework/schemas.py index ffaaa0f30..b9dce5400 100644 --- a/rest_framework/schemas.py +++ b/rest_framework/schemas.py @@ -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', 'GET', '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 [] @@ -592,6 +596,9 @@ class SchemaGenerator(object): 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, From fe856472c97824f205769665d94adeb6f5a3d9fa Mon Sep 17 00:00:00 2001 From: Lucas Paim Date: Thu, 11 May 2017 11:55:33 -0300 Subject: [PATCH 4/4] change version --- rest_framework/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/__init__.py b/rest_framework/__init__.py index edcf9b52d..c0b5c4c04 100644 --- a/rest_framework/__init__.py +++ b/rest_framework/__init__.py @@ -8,7 +8,7 @@ ______ _____ _____ _____ __ """ __title__ = 'Django REST framework' -__version__ = '3.6.2' +__version__ = '3.6.3' __author__ = 'Tom Christie' __license__ = 'BSD 2-Clause' __copyright__ = 'Copyright 2011-2017 Tom Christie'