mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
[OAS3] integer and number formats
This commit is contained in:
parent
559088463b
commit
f00191a6db
|
@ -151,7 +151,9 @@ class BaseSchemaGenerator:
|
||||||
# Set by 'SCHEMA_COERCE_PATH_PK'.
|
# Set by 'SCHEMA_COERCE_PATH_PK'.
|
||||||
coerce_path_pk = None
|
coerce_path_pk = None
|
||||||
|
|
||||||
def __init__(self, title=None, url=None, description=None, patterns=None, urlconf=None, version=None):
|
def __init__(self, title=None, url=None, description=None,
|
||||||
|
patterns=None, urlconf=None, version=None):
|
||||||
|
|
||||||
if url and not url.endswith('/'):
|
if url and not url.endswith('/'):
|
||||||
url += '/'
|
url += '/'
|
||||||
|
|
||||||
|
|
|
@ -113,9 +113,8 @@ class SchemaGenerator(BaseSchemaGenerator):
|
||||||
|
|
||||||
return schema
|
return schema
|
||||||
|
|
||||||
|
|
||||||
# View Inspectors
|
# View Inspectors
|
||||||
|
|
||||||
|
|
||||||
class AutoSchema(ViewInspector):
|
class AutoSchema(ViewInspector):
|
||||||
|
|
||||||
def __init__(self, tags=None, operation_id_base=None, component_name=None):
|
def __init__(self, tags=None, operation_id_base=None, component_name=None):
|
||||||
|
@ -471,13 +470,15 @@ class AutoSchema(ViewInspector):
|
||||||
if isinstance(field, serializers.FloatField):
|
if isinstance(field, serializers.FloatField):
|
||||||
content = {
|
content = {
|
||||||
'type': 'number',
|
'type': 'number',
|
||||||
|
'format': 'float'
|
||||||
}
|
}
|
||||||
self._map_min_max(field, content)
|
self._map_min_max(field, content)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
if isinstance(field, serializers.IntegerField):
|
if isinstance(field, serializers.IntegerField):
|
||||||
content = {
|
content = {
|
||||||
'type': 'integer'
|
'type': 'integer',
|
||||||
|
'format': 'int64'
|
||||||
}
|
}
|
||||||
self._map_min_max(field, content)
|
self._map_min_max(field, content)
|
||||||
# 2147483647 is max for int32_size, so we use int64 for format
|
# 2147483647 is max for int32_size, so we use int64 for format
|
||||||
|
|
|
@ -54,7 +54,7 @@ class TestFieldMapping(TestCase):
|
||||||
cases = [
|
cases = [
|
||||||
(serializers.ListField(), {'items': {}, 'type': 'array'}),
|
(serializers.ListField(), {'items': {}, 'type': 'array'}),
|
||||||
(serializers.ListField(child=serializers.BooleanField()), {'items': {'type': 'boolean'}, 'type': 'array'}),
|
(serializers.ListField(child=serializers.BooleanField()), {'items': {'type': 'boolean'}, 'type': 'array'}),
|
||||||
(serializers.ListField(child=serializers.FloatField()), {'items': {'type': 'number'}, 'type': 'array'}),
|
(serializers.ListField(child=serializers.FloatField()), {'items': {'type': 'number', 'format': 'float'}, 'type': 'array'}),
|
||||||
(serializers.ListField(child=serializers.CharField()), {'items': {'type': 'string'}, 'type': 'array'}),
|
(serializers.ListField(child=serializers.CharField()), {'items': {'type': 'string'}, 'type': 'array'}),
|
||||||
(serializers.ListField(child=serializers.IntegerField(max_value=4294967295)),
|
(serializers.ListField(child=serializers.IntegerField(max_value=4294967295)),
|
||||||
{'items': {'type': 'integer', 'maximum': 4294967295, 'format': 'int64'}, 'type': 'array'}),
|
{'items': {'type': 'integer', 'maximum': 4294967295, 'format': 'int64'}, 'type': 'array'}),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user