Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions drf_spectacular/extensions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from abc import abstractmethod
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, Union
from typing import TYPE_CHECKING, Any, Dict, Iterable, Optional, Type, Union

from drf_spectacular.plumbing import OpenApiGeneratorExtension
from drf_spectacular.utils import Direction
Expand Down Expand Up @@ -32,21 +32,21 @@ class OpenApiAuthenticationExtension(OpenApiGeneratorExtension['OpenApiAuthentic
``get_security_definition()`` is expected to return a valid `OpenAPI security scheme object
<https://spec.openapis.org/oas/v3.0.3#security-scheme-object>`_
"""
_registry: List[Type['OpenApiAuthenticationExtension']] = []
_registry: Iterable[Type['OpenApiAuthenticationExtension']] = []

name: Union[str, List[str]]
name: Union[str, Iterable[str]]

def get_security_requirement(
self, auto_schema: 'AutoSchema'
) -> Union[Dict[str, List[Any]], List[Dict[str, List[Any]]]]:
) -> Union[Dict[str, Iterable[Any]], Iterable[Dict[str, Iterable[Any]]]]:
assert self.name, 'name(s) must be specified'
if isinstance(self.name, str):
return {self.name: []}
else:
return {name: [] for name in self.name}

@abstractmethod
def get_security_definition(self, auto_schema: 'AutoSchema') -> Union[_SchemaType, List[_SchemaType]]:
def get_security_definition(self, auto_schema: 'AutoSchema') -> Union[_SchemaType, Iterable[_SchemaType]]:
pass # pragma: no cover


Expand All @@ -62,7 +62,7 @@ class OpenApiSerializerExtension(OpenApiGeneratorExtension['OpenApiSerializerExt
``map_serializer()`` is expected to return a valid `OpenAPI schema object
<https://spec.openapis.org/oas/v3.0.3#schema-object>`_.
"""
_registry: List[Type['OpenApiSerializerExtension']] = []
_registry: Iterable[Type['OpenApiSerializerExtension']] = []

def get_name(self, auto_schema: 'AutoSchema', direction: Direction) -> Optional[str]:
""" return str for overriding default name extraction """
Expand All @@ -89,7 +89,7 @@ class OpenApiSerializerFieldExtension(OpenApiGeneratorExtension['OpenApiSerializ
``map_serializer_field()`` is expected to return a valid `OpenAPI schema object
<https://spec.openapis.org/oas/v3.0.3#schema-object>`_.
"""
_registry: List[Type['OpenApiSerializerFieldExtension']] = []
_registry: Iterable[Type['OpenApiSerializerFieldExtension']] = []

def get_name(self) -> Optional[str]:
""" return str for breaking out field schema into separate named component """
Expand All @@ -109,7 +109,7 @@ class OpenApiViewExtension(OpenApiGeneratorExtension['OpenApiViewExtension']):
``ViewSet`` et al.). The discovered original view instance can be accessed with
``self.target`` and be subclassed if desired.
"""
_registry: List[Type['OpenApiViewExtension']] = []
_registry: Iterable[Type['OpenApiViewExtension']] = []

@classmethod
def _load_class(cls):
Expand All @@ -136,8 +136,8 @@ class OpenApiFilterExtension(OpenApiGeneratorExtension['OpenApiFilterExtension']
Using ``drf_spectacular.plumbing.build_parameter_type`` is recommended to generate
the appropriate raw dict objects.
"""
_registry: List[Type['OpenApiFilterExtension']] = []
_registry: Iterable[Type['OpenApiFilterExtension']] = []

@abstractmethod
def get_schema_operation_parameters(self, auto_schema: 'AutoSchema', *args, **kwargs) -> List[_SchemaType]:
def get_schema_operation_parameters(self, auto_schema: 'AutoSchema', *args, **kwargs) -> Iterable[_SchemaType]:
pass # pragma: no cover
5 changes: 3 additions & 2 deletions drf_spectacular/plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from decimal import Decimal
from enum import Enum
from typing import (
Any, DefaultDict, Dict, Generic, List, Optional, Sequence, Tuple, Type, TypeVar, Union,
Any, DefaultDict, Dict, Generic, Iterable, List, Optional, Sequence, Tuple, Type, TypeVar,
Union,
)

if sys.version_info >= (3, 10):
Expand Down Expand Up @@ -818,7 +819,7 @@ def build(self, extra_components) -> _SchemaType:


class OpenApiGeneratorExtension(Generic[T], metaclass=ABCMeta):
_registry: List[Type[T]] = []
_registry: Iterable[Type[T]] = []
target_class: Union[None, str, Type[object]] = None
match_subclasses = False
priority = 0
Expand Down