Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Stable/0.3.x: form parameter minimum/maximum values are strings per 1.2 spec #692

Open
wants to merge 1 commit into
base: stable/0.3.x
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions rest_framework_swagger/introspectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,10 @@ def build_form_parameters(self):
max_value = getattr(field, 'max_value', None)
min_value = getattr(field, 'min_value', None)
if max_value is not None and data_type == 'integer':
f['minimum'] = min_value
f['minimum'] = str(min_value)

if max_value is not None and data_type == 'integer':
f['maximum'] = max_value
f['maximum'] = str(max_value)

# ENUM options
if choices:
Expand Down
21 changes: 21 additions & 0 deletions rest_framework_swagger/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1799,6 +1799,27 @@ def post(self, request, *args, **kwargs):
self.assertIn('maximum', params[0])
self.assertEqual(params[0]['maximum'], '100')

def test_parameters_minimum_is_string_with_introspection(self):
'''
minimum and maximum of Parameter Object required by
Swagger 1.2 spec to be string.
'''
class CommentSerializer(serializers.Serializer):
some_bigint = serializers.IntegerField(min_value=1, max_value=100)

class SerializedAPI(ListCreateAPIView):
serializer_class = CommentSerializer

class_introspector = self.make_introspector(SerializedAPI)
introspector = APIViewMethodIntrospector(class_introspector, 'POST')
parser = introspector.get_yaml_parser()
params = parser.discover_parameters(introspector)
self.assertEqual(len(params), 1)
self.assertIn('minimum', params[0])
self.assertEqual(params[0]['minimum'], '1')
self.assertIn('maximum', params[0])
self.assertEqual(params[0]['maximum'], '100')

def test_response_messages(self):
class SerializedAPI(ListCreateAPIView):
serializer_class = CommentSerializer
Expand Down