From d9602b9be64447d4ec42f466c9d58fa08b6794c9 Mon Sep 17 00:00:00 2001 From: Julian Bez Date: Mon, 3 Sep 2018 12:10:58 +0200 Subject: [PATCH] Use first arg if return annotation is not class directly Happens for typing classes like Optional, Union, and so on --- src/drf_yasg/inspectors/field.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/drf_yasg/inspectors/field.py b/src/drf_yasg/inspectors/field.py index a7798a2c..750a1a4c 100644 --- a/src/drf_yasg/inspectors/field.py +++ b/src/drf_yasg/inspectors/field.py @@ -5,6 +5,7 @@ import uuid from collections import OrderedDict from decimal import Decimal +from inspect import isclass from django.core import validators from django.db import models @@ -511,6 +512,8 @@ def field_to_swagger_object(self, field, swagger_object_type, use_references, ** # look for Python 3.5+ style type hinting of the return value hint_class = inspect.signature(method).return_annotation + if not isclass(hint_class) and hasattr(hint_class, '__args__'): + hint_class = hint_class.__args__[0] if not issubclass(hint_class, inspect._empty): type_info = get_basic_type_info_from_hint(hint_class)