mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
fixup! Corrected OpenAPI schema type for DecimalField
This commit is contained in:
parent
f80d7be282
commit
9f9913573b
|
@ -445,7 +445,7 @@ class AutoSchema(ViewInspector):
|
|||
|
||||
if isinstance(field, serializers.DecimalField):
|
||||
if getattr(field, 'coerce_to_string', api_settings.COERCE_DECIMAL_TO_STRING):
|
||||
return {
|
||||
content = {
|
||||
'type': 'string',
|
||||
'format': 'decimal',
|
||||
}
|
||||
|
@ -453,13 +453,14 @@ class AutoSchema(ViewInspector):
|
|||
content = {
|
||||
'type': 'number'
|
||||
}
|
||||
if field.decimal_places:
|
||||
content['multipleOf'] = float('.' + (field.decimal_places - 1) * '0' + '1')
|
||||
if field.max_whole_digits:
|
||||
content['maximum'] = int(field.max_whole_digits * '9') + 1
|
||||
content['minimum'] = -content['maximum']
|
||||
self._map_min_max(field, content)
|
||||
return content
|
||||
|
||||
if field.decimal_places:
|
||||
content['multipleOf'] = float('.' + (field.decimal_places - 1) * '0' + '1')
|
||||
if field.max_whole_digits:
|
||||
content['maximum'] = int(field.max_whole_digits * '9') + 1
|
||||
content['minimum'] = -content['maximum']
|
||||
self._map_min_max(field, content)
|
||||
return content
|
||||
|
||||
if isinstance(field, serializers.FloatField):
|
||||
content = {
|
||||
|
|
|
@ -838,8 +838,15 @@ class TestOperationIntrospection(TestCase):
|
|||
assert properties['decimal2']['type'] == 'number'
|
||||
assert properties['decimal2']['multipleOf'] == .0001
|
||||
|
||||
assert properties['decimal3'] == {'type': 'string', 'format': 'decimal'}
|
||||
assert properties['decimal4'] == {'type': 'string', 'format': 'decimal'}
|
||||
assert properties['decimal3'] == {
|
||||
'type': 'string', 'format': 'decimal', 'maximum': 1000000, 'minimum': -1000000, 'multipleOf': 0.01
|
||||
}
|
||||
assert properties['decimal4'] == {
|
||||
'type': 'string', 'format': 'decimal', 'maximum': 1000000, 'minimum': -1000000, 'multipleOf': 0.01
|
||||
}
|
||||
assert properties['decimal5'] == {
|
||||
'type': 'string', 'format': 'decimal', 'maximum': 10000, 'minimum': -10000, 'multipleOf': 0.01
|
||||
}
|
||||
|
||||
assert properties['email']['type'] == 'string'
|
||||
assert properties['email']['format'] == 'email'
|
||||
|
|
|
@ -125,6 +125,7 @@ class ExampleValidatedSerializer(serializers.Serializer):
|
|||
decimal3 = serializers.DecimalField(max_digits=8, decimal_places=2, coerce_to_string=True)
|
||||
decimal4 = serializers.DecimalField(max_digits=8, decimal_places=2, coerce_to_string=True,
|
||||
validators=(DecimalValidator(max_digits=17, decimal_places=4),))
|
||||
decimal5 = serializers.DecimalField(max_digits=6, decimal_places=2)
|
||||
email = serializers.EmailField(default='foo@bar.com')
|
||||
url = serializers.URLField(default='http://www.example.com', allow_null=True)
|
||||
uuid = serializers.UUIDField()
|
||||
|
|
Loading…
Reference in New Issue
Block a user