Skip to content

Commit

Permalink
fix(spm): correct api client header handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrasser committed Dec 18, 2024
1 parent def7039 commit a6b9f8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 4 additions & 2 deletions cryosparc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def _construct_request(self, _path: str, _schema, *args, **kwargs) -> Tuple[str,
elif param_in == "query" and param_name in kwargs:
# query param must be in kwargs
query_params[param_name] = kwargs.pop(param_name)
elif param_in == "header" and param_name in kwargs:
elif param_in == "header" and (header_name := param_name.replace("-", "_")) in kwargs:
# header must be in kwargs
headers[param_name] = kwargs.pop(param_name)
headers[param_name] = kwargs.pop(header_name)
elif param_in == "header" and param_name in client_headers:
pass # in default headers, no action required
elif param_schema["required"]:
Expand Down Expand Up @@ -231,6 +231,7 @@ def __init__(
base_url: Optional[str] = None,
*,
auth: Optional[Auth] = None, # token or email/password
headers: Dict[str, str] | None = None,
timeout: float = 300,
http_client: Optional[httpx.Client] = None,
):
Expand All @@ -240,6 +241,7 @@ def __init__(
if not base_url:
raise TypeError(f"Must specify either base_url ({base_url}) or http_client ({http_client})")
http_client = httpx.Client(base_url=base_url, timeout=timeout)
http_client.headers.update(headers)
super().__init__(http_client)
self._attrs = set()
self(auth=auth) # query the OpenAPI server and populate endpoint functions
Expand Down
7 changes: 6 additions & 1 deletion cryosparc/api.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,12 @@ class APIClient:
developer: DeveloperNamespace

def __init__(
self, base_url: Optional[str] = None, *, timeout: float = ..., auth: Union[str, tuple[str, str], None] = None
self,
base_url: Optional[str] = None,
*,
auth: Union[str, tuple[str, str], None] = None,
headers: Optional[Dict[str, str]] = None,
timeout: float = ...,
) -> None: ...
def __call__(self, *, auth: Union[str, tuple[str, str], None] = None) -> Any: ...
def read_root(self) -> Hello: ...
Expand Down

0 comments on commit a6b9f8d

Please sign in to comment.