|
|
|
@ -55,10 +55,9 @@ from fastapi.concurrency import ( |
|
|
|
asynccontextmanager, |
|
|
|
contextmanager_in_threadpool, |
|
|
|
) |
|
|
|
from fastapi.dependencies.models import Dependant, SecurityRequirement |
|
|
|
from fastapi.dependencies.models import Dependant |
|
|
|
from fastapi.exceptions import DependencyScopeError |
|
|
|
from fastapi.logger import logger |
|
|
|
from fastapi.security.base import SecurityBase |
|
|
|
from fastapi.security.oauth2 import SecurityScopes |
|
|
|
from fastapi.types import DependencyCacheKey |
|
|
|
from fastapi.utils import create_model_field, get_path_param_names |
|
|
|
@ -142,10 +141,14 @@ def get_flat_dependant( |
|
|
|
*, |
|
|
|
skip_repeats: bool = False, |
|
|
|
visited: Optional[List[DependencyCacheKey]] = None, |
|
|
|
parent_oauth_scopes: Optional[List[str]] = None, |
|
|
|
) -> Dependant: |
|
|
|
if visited is None: |
|
|
|
visited = [] |
|
|
|
visited.append(dependant.cache_key) |
|
|
|
use_parent_oauth_scopes = (parent_oauth_scopes or []) + ( |
|
|
|
dependant.oauth_scopes or [] |
|
|
|
) |
|
|
|
|
|
|
|
flat_dependant = Dependant( |
|
|
|
path_params=dependant.path_params.copy(), |
|
|
|
@ -153,22 +156,37 @@ def get_flat_dependant( |
|
|
|
header_params=dependant.header_params.copy(), |
|
|
|
cookie_params=dependant.cookie_params.copy(), |
|
|
|
body_params=dependant.body_params.copy(), |
|
|
|
security_requirements=dependant.security_requirements.copy(), |
|
|
|
name=dependant.name, |
|
|
|
call=dependant.call, |
|
|
|
request_param_name=dependant.request_param_name, |
|
|
|
websocket_param_name=dependant.websocket_param_name, |
|
|
|
http_connection_param_name=dependant.http_connection_param_name, |
|
|
|
response_param_name=dependant.response_param_name, |
|
|
|
background_tasks_param_name=dependant.background_tasks_param_name, |
|
|
|
security_scopes_param_name=dependant.security_scopes_param_name, |
|
|
|
own_oauth_scopes=dependant.own_oauth_scopes, |
|
|
|
parent_oauth_scopes=use_parent_oauth_scopes, |
|
|
|
use_cache=dependant.use_cache, |
|
|
|
path=dependant.path, |
|
|
|
scope=dependant.scope, |
|
|
|
) |
|
|
|
for sub_dependant in dependant.dependencies: |
|
|
|
if skip_repeats and sub_dependant.cache_key in visited: |
|
|
|
continue |
|
|
|
flat_sub = get_flat_dependant( |
|
|
|
sub_dependant, skip_repeats=skip_repeats, visited=visited |
|
|
|
sub_dependant, |
|
|
|
skip_repeats=skip_repeats, |
|
|
|
visited=visited, |
|
|
|
parent_oauth_scopes=flat_dependant.oauth_scopes, |
|
|
|
) |
|
|
|
flat_dependant.dependencies.append(flat_sub) |
|
|
|
flat_dependant.path_params.extend(flat_sub.path_params) |
|
|
|
flat_dependant.query_params.extend(flat_sub.query_params) |
|
|
|
flat_dependant.header_params.extend(flat_sub.header_params) |
|
|
|
flat_dependant.cookie_params.extend(flat_sub.cookie_params) |
|
|
|
flat_dependant.body_params.extend(flat_sub.body_params) |
|
|
|
flat_dependant.security_requirements.extend(flat_sub.security_requirements) |
|
|
|
flat_dependant.dependencies.extend(flat_sub.dependencies) |
|
|
|
|
|
|
|
return flat_dependant |
|
|
|
|
|
|
|
|
|
|
|
@ -258,11 +276,6 @@ def get_dependant( |
|
|
|
path_param_names = get_path_param_names(path) |
|
|
|
endpoint_signature = get_typed_signature(call) |
|
|
|
signature_params = endpoint_signature.parameters |
|
|
|
if isinstance(call, SecurityBase): |
|
|
|
security_requirement = SecurityRequirement( |
|
|
|
security_scheme=call, scopes=current_scopes |
|
|
|
) |
|
|
|
dependant.security_requirements.append(security_requirement) |
|
|
|
for param_name, param in signature_params.items(): |
|
|
|
is_path_param = param_name in path_param_names |
|
|
|
param_details = analyze_param( |
|
|
|
|