mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
[OpenAPI] Schemas Generator minor improvements, better generalization for third-party integrations
This commit is contained in:
parent
559088463b
commit
eb1e2703de
|
@ -32,7 +32,7 @@ def get_schema_view(
|
||||||
public=False, patterns=None, generator_class=None,
|
public=False, patterns=None, generator_class=None,
|
||||||
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
|
authentication_classes=api_settings.DEFAULT_AUTHENTICATION_CLASSES,
|
||||||
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES,
|
permission_classes=api_settings.DEFAULT_PERMISSION_CLASSES,
|
||||||
version=None):
|
version=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Return a schema view.
|
Return a schema view.
|
||||||
"""
|
"""
|
||||||
|
@ -44,7 +44,7 @@ def get_schema_view(
|
||||||
|
|
||||||
generator = generator_class(
|
generator = generator_class(
|
||||||
title=title, url=url, description=description,
|
title=title, url=url, description=description,
|
||||||
urlconf=urlconf, patterns=patterns, version=version
|
urlconf=urlconf, patterns=patterns, version=version, **kwargs
|
||||||
)
|
)
|
||||||
|
|
||||||
# Avoid import cycle on APIView
|
# Avoid import cycle on APIView
|
||||||
|
|
|
@ -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, **kwargs):
|
||||||
|
|
||||||
if url and not url.endswith('/'):
|
if url and not url.endswith('/'):
|
||||||
url += '/'
|
url += '/'
|
||||||
|
|
||||||
|
@ -165,6 +167,9 @@ class BaseSchemaGenerator:
|
||||||
self.url = url
|
self.url = url
|
||||||
self.endpoints = None
|
self.endpoints = None
|
||||||
|
|
||||||
|
for k, v in kwargs.items():
|
||||||
|
setattr(self, k, v)
|
||||||
|
|
||||||
def _initialise_endpoints(self):
|
def _initialise_endpoints(self):
|
||||||
if self.endpoints is None:
|
if self.endpoints is None:
|
||||||
inspector = self.endpoint_inspector_cls(self.patterns, self.urlconf)
|
inspector = self.endpoint_inspector_cls(self.patterns, self.urlconf)
|
||||||
|
|
|
@ -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