parent
207a7e2b2d
commit
c510de13d7
|
|
@ -5,7 +5,6 @@ import operator
|
||||||
import uuid
|
import uuid
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from inspect import isclass
|
|
||||||
|
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
@ -18,11 +17,15 @@ from ..utils import decimal_as_float, filter_none, get_serializer_class, get_ser
|
||||||
from .base import FieldInspector, NotHandled, SerializerInspector
|
from .base import FieldInspector, NotHandled, SerializerInspector
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Python>=3.5
|
|
||||||
import typing
|
import typing
|
||||||
except ImportError:
|
except ImportError:
|
||||||
typing = None
|
typing = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
from inspect import signature as inspect_signature
|
||||||
|
except ImportError:
|
||||||
|
inspect_signature = None
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -83,10 +86,10 @@ class InlineSerializerInspector(SerializerInspector):
|
||||||
|
|
||||||
ref_name = self.get_serializer_ref_name(field)
|
ref_name = self.get_serializer_ref_name(field)
|
||||||
|
|
||||||
def make_schema_definition():
|
def make_schema_definition(serializer=field):
|
||||||
properties = OrderedDict()
|
properties = OrderedDict()
|
||||||
required = []
|
required = []
|
||||||
for property_name, child in field.fields.items():
|
for property_name, child in serializer.fields.items():
|
||||||
property_name = self.get_property_name(property_name)
|
property_name = self.get_property_name(property_name)
|
||||||
prop_kwargs = {
|
prop_kwargs = {
|
||||||
'read_only': bool(child.read_only) or None
|
'read_only': bool(child.read_only) or None
|
||||||
|
|
@ -544,13 +547,13 @@ class SerializerMethodFieldInspector(FieldInspector):
|
||||||
serializer.read_only = True
|
serializer.read_only = True
|
||||||
|
|
||||||
return self.probe_field_inspectors(serializer, swagger_object_type, use_references, read_only=True)
|
return self.probe_field_inspectors(serializer, swagger_object_type, use_references, read_only=True)
|
||||||
elif typing:
|
elif typing and inspect_signature:
|
||||||
# look for Python 3.5+ style type hinting of the return value
|
# look for Python 3.5+ style type hinting of the return value
|
||||||
hint_class = inspect.signature(method).return_annotation
|
hint_class = inspect_signature(method).return_annotation
|
||||||
|
|
||||||
if not isclass(hint_class) and hasattr(hint_class, '__args__'):
|
if not inspect.isclass(hint_class) and hasattr(hint_class, '__args__'):
|
||||||
hint_class = hint_class.__args__[0]
|
hint_class = hint_class.__args__[0]
|
||||||
if isclass(hint_class) and not issubclass(hint_class, inspect._empty):
|
if inspect.isclass(hint_class) and not issubclass(hint_class, inspect._empty):
|
||||||
type_info = get_basic_type_info_from_hint(hint_class)
|
type_info = get_basic_type_info_from_hint(hint_class)
|
||||||
|
|
||||||
if type_info is not None:
|
if type_info is not None:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue