]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
:bug: Fix Python 3.7 specific list query handling
authorSebastián Ramírez <tiangolo@gmail.com>
Sun, 30 Dec 2018 17:43:34 +0000 (21:43 +0400)
committerSebastián Ramírez <tiangolo@gmail.com>
Sun, 30 Dec 2018 17:43:34 +0000 (21:43 +0400)
fastapi/dependencies/utils.py
fastapi/openapi/models.py

index a9da99c3e8cdec49789672f0a8b86f5929d61ee8..7dddae3c293e4bd2739229fae5f4fc9f5760e1e3 100644 (file)
@@ -3,7 +3,7 @@ import inspect
 from copy import deepcopy
 from datetime import date, datetime, time, timedelta
 from decimal import Decimal
-from typing import Any, Callable, Dict, List, Mapping, Sequence, Set, Tuple, Type, Union
+from typing import Any, Callable, Dict, List, Mapping, Sequence, Tuple, Type, Union
 from uuid import UUID
 
 from fastapi import params
@@ -107,10 +107,18 @@ def get_dependant(*, path: str, call: Callable, name: str = None) -> Dependant:
             )
         elif isinstance(param.default, params.Param):
             if param.annotation != param.empty:
-                assert lenient_issubclass(
-                    param.annotation,
-                    param_supported_types + (List, Tuple, Set, list, tuple, set),
-                ), f"Parameters for Path, Query, Header and Cookies must be of type str, int, float, bool, list, tuple or set: {param}"
+                origin = getattr(param.annotation, "__origin__", None)
+                param_all_types = param_supported_types + (list, tuple, set)
+                if isinstance(param.default, (params.Query, params.Header)):
+                    assert lenient_issubclass(
+                        param.annotation, param_all_types
+                    ) or lenient_issubclass(
+                        origin, param_all_types
+                    ), f"Parameters for Query and Header must be of type str, int, float, bool, list, tuple or set: {param}"
+                else:
+                    assert lenient_issubclass(
+                        param.annotation, param_supported_types
+                    ), f"Parameters for Path and Cookies must be of type str, int, float, bool: {param}"
             add_param_to_fields(
                 param=param, dependant=dependant, default_schema=params.Query
             )
index 72331eebcbe1a185d667aa314239c42949ebb49a..6572c7c07239939e414561ff6e1859410d3f123f 100644 (file)
@@ -322,7 +322,7 @@ class OpenIdConnect(SecurityBase):
     openIdConnectUrl: str
 
 
-SecurityScheme = Union[APIKey, HTTPBase, HTTPBearer, OAuth2, OpenIdConnect]
+SecurityScheme = Union[APIKey, HTTPBase, OAuth2, OpenIdConnect, HTTPBearer]
 
 
 class Components(BaseModel):