Skip to content

Commit

Permalink
allow already supported lazy string in types #982
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Jun 21, 2023
1 parent dd645b6 commit ad217b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
('py:class', r'(?:APIView|AutoSchema|OpenApiFilterExtension)'),
# Unresolvable type hinting references to packages without intersphinx support.
('py:class', r'rest_framework\..+'),
('py:class', r'django\.utils\.functional\.Promise'),
# Internal undocumented objects.
('py:class', r'drf_spectacular\.generators\..+'),
('py:class', r'drf_spectacular\.plumbing\..+'),
Expand Down
17 changes: 10 additions & 7 deletions drf_spectacular/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import sys
from typing import Any, Callable, Dict, Optional, Sequence, Tuple, Type, TypeVar, Union

from django.utils.functional import Promise

# direct import due to https://github.com/microsoft/pyright/issues/3025
if sys.version_info >= (3, 8):
from typing import Final, Literal
Expand All @@ -20,6 +22,7 @@
_SerializerType = Union[Serializer, Type[Serializer]]
_FieldType = Union[Field, Type[Field]]
_ParameterLocationType = Literal['query', 'path', 'header', 'cookie']
_StrOrPromise = Union[str, Promise]
Direction = Literal['request', 'response']


Expand Down Expand Up @@ -160,8 +163,8 @@ def __init__(
name: str,
value: Any = None,
external_value: str = '',
summary: str = '',
description: str = '',
summary: _StrOrPromise = '',
description: _StrOrPromise = '',
request_only: bool = False,
response_only: bool = False,
parameter_only: Optional[Tuple[str, _ParameterLocationType]] = None,
Expand Down Expand Up @@ -202,7 +205,7 @@ def __init__(
type: Union[_SerializerType, _KnownPythonTypes, OpenApiTypes, dict] = str,
location: _ParameterLocationType = QUERY,
required: bool = False,
description: str = '',
description: _StrOrPromise = '',
enum: Optional[Sequence[Any]] = None,
pattern: Optional[str] = None,
deprecated: bool = False,
Expand Down Expand Up @@ -247,7 +250,7 @@ class OpenApiResponse(OpenApiSchemaBase):
def __init__(
self,
response: Any = None,
description: str = '',
description: _StrOrPromise = '',
examples: Optional[Sequence[OpenApiExample]] = None
):
self.response = response
Expand Down Expand Up @@ -302,7 +305,7 @@ class OpenApiCallback(OpenApiSchemaBase):
"""
def __init__(
self,
name: str,
name: _StrOrPromise,
path: str,
decorator: Union[Callable[[F], F], Dict[str, Callable[[F], F]], Dict[str, Any]],
):
Expand All @@ -317,8 +320,8 @@ def extend_schema(
request: Any = empty,
responses: Any = empty,
auth: Optional[Sequence[str]] = None,
description: Optional[str] = None,
summary: Optional[str] = None,
description: Optional[_StrOrPromise] = None,
summary: Optional[_StrOrPromise] = None,
deprecated: Optional[bool] = None,
tags: Optional[Sequence[str]] = None,
filters: Optional[bool] = None,
Expand Down

0 comments on commit ad217b5

Please sign in to comment.