Skip to content

fix: Non-string header values [#552 & #553]. Thanks @John98Zakaria! #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 18, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import types

from . import get_location_query_optionality
from . import get_location_header_types, get_location_query_optionality


class LocationEndpoints:
@classmethod
def get_location_query_optionality(cls) -> types.ModuleType:
return get_location_query_optionality

@classmethod
def get_location_header_types(cls) -> types.ModuleType:
return get_location_header_types
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/common_parameters".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {
"common": common,
}
params: Dict[str, Any] = {}
params["common"] = common

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/common_parameters".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {
"common": common,
}
params: Dict[str, Any] = {}
params["common"] = common

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
from typing import Any, Dict, Union

import httpx

from ...client import Client
from ...types import UNSET, Response, Unset


def _get_kwargs(
*,
client: Client,
boolean_header: Union[Unset, bool] = UNSET,
string_header: Union[Unset, str] = UNSET,
number_header: Union[Unset, float] = UNSET,
integer_header: Union[Unset, int] = UNSET,
) -> Dict[str, Any]:
url = "{}/location/header/types".format(client.base_url)

headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

if not isinstance(boolean_header, Unset):
headers["Boolean-Header"] = "true" if boolean_header else "false"

if not isinstance(string_header, Unset):
headers["String-Header"] = string_header

if not isinstance(number_header, Unset):
headers["Number-Header"] = str(number_header)

if not isinstance(integer_header, Unset):
headers["Integer-Header"] = str(integer_header)

return {
"method": "get",
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
}


def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=None,
)


def sync_detailed(
*,
client: Client,
boolean_header: Union[Unset, bool] = UNSET,
string_header: Union[Unset, str] = UNSET,
number_header: Union[Unset, float] = UNSET,
integer_header: Union[Unset, int] = UNSET,
) -> Response[Any]:
"""
Args:
boolean_header (Union[Unset, bool]):
string_header (Union[Unset, str]):
number_header (Union[Unset, float]):
integer_header (Union[Unset, int]):

Returns:
Response[Any]
"""

kwargs = _get_kwargs(
client=client,
boolean_header=boolean_header,
string_header=string_header,
number_header=number_header,
integer_header=integer_header,
)

response = httpx.request(
verify=client.verify_ssl,
**kwargs,
)

return _build_response(response=response)


async def asyncio_detailed(
*,
client: Client,
boolean_header: Union[Unset, bool] = UNSET,
string_header: Union[Unset, str] = UNSET,
number_header: Union[Unset, float] = UNSET,
integer_header: Union[Unset, int] = UNSET,
) -> Response[Any]:
"""
Args:
boolean_header (Union[Unset, bool]):
string_header (Union[Unset, str]):
number_header (Union[Unset, float]):
integer_header (Union[Unset, int]):

Returns:
Response[Any]
"""

kwargs = _get_kwargs(
client=client,
boolean_header=boolean_header,
string_header=string_header,
number_header=number_header,
integer_header=integer_header,
)

async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.request(**kwargs)

return _build_response(response=response)
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,32 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/location/query/optionality".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {}
json_not_null_required = not_null_required.isoformat()

params["not_null_required"] = json_not_null_required

json_null_required: Union[Unset, None, str] = UNSET
if not isinstance(null_required, Unset):
json_null_required = null_required.isoformat() if null_required else None

params["null_required"] = json_null_required

json_null_not_required: Union[Unset, None, str] = UNSET
if not isinstance(null_not_required, Unset):
json_null_not_required = null_not_required.isoformat() if null_not_required else None

params["null_not_required"] = json_null_not_required

json_not_null_not_required: Union[Unset, None, str] = UNSET
if not isinstance(not_null_not_required, Unset):
json_not_null_not_required = not_null_not_required.isoformat() if not_null_not_required else None

params: Dict[str, Any] = {
"not_null_required": json_not_null_required,
"null_required": json_null_required,
"null_not_required": json_null_not_required,
"not_null_not_required": json_not_null_not_required,
}
params["not_null_not_required"] = json_not_null_not_required

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/common_parameters_overriding/{param}".format(client.base_url, param=param_path)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {
"param": param_query,
}
params: Dict[str, Any] = {}
params["param"] = param_query

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/common_parameters_overriding/{param}".format(client.base_url, param=param_path)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {
"param": param_query,
}
params: Dict[str, Any] = {}
params["param"] = param_query

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/same-name-multiple-locations/{param}".format(client.base_url, param=param_path)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

if param_header is not UNSET:
if not isinstance(param_header, Unset):
headers["param"] = param_header

if param_cookie is not UNSET:
cookies["param"] = param_cookie

params: Dict[str, Any] = {
"param": param_query,
}
params: Dict[str, Any] = {}
params["param"] = param_query

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def _get_kwargs(
client.base_url, param4=param4, param2=param2, param1=param1, param3=param3
)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/tag_with_number".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional, Union, cast

import httpx
from dateutil.parser import isoparse
Expand Down Expand Up @@ -28,23 +28,39 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/tests/defaults".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

params: Dict[str, Any] = {}
params["string_prop"] = string_prop

json_date_prop = date_prop.isoformat()
params["date_prop"] = json_date_prop

params["float_prop"] = float_prop

params["int_prop"] = int_prop

params["boolean_prop"] = boolean_prop

json_list_prop = []
for list_prop_item_data in list_prop:
list_prop_item = list_prop_item_data.value

json_list_prop.append(list_prop_item)

params["list_prop"] = json_list_prop

json_union_prop = union_prop

params["union_prop"] = json_union_prop

json_union_prop_with_ref: Union[None, Unset, float, str]
if isinstance(union_prop_with_ref, Unset):
json_union_prop_with_ref = UNSET
elif union_prop_with_ref is None:
json_union_prop_with_ref = None

elif isinstance(union_prop_with_ref, AnEnum):
json_union_prop_with_ref = UNSET
if not isinstance(union_prop_with_ref, Unset):
Expand All @@ -53,25 +69,20 @@ def _get_kwargs(
else:
json_union_prop_with_ref = union_prop_with_ref

params["union_prop_with_ref"] = json_union_prop_with_ref

json_enum_prop = enum_prop.value

params["enum_prop"] = json_enum_prop

json_model_prop = model_prop.to_dict()

params.update(json_model_prop)

json_required_model_prop = required_model_prop.to_dict()

params: Dict[str, Any] = {
"string_prop": string_prop,
"date_prop": json_date_prop,
"float_prop": float_prop,
"int_prop": int_prop,
"boolean_prop": boolean_prop,
"list_prop": json_list_prop,
"union_prop": json_union_prop,
"union_prop_with_ref": json_union_prop_with_ref,
"enum_prop": json_enum_prop,
}
params.update(json_model_prop)
params.update(json_required_model_prop)

params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

return {
Expand All @@ -86,8 +97,7 @@ def _get_kwargs(

def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]:
if response.status_code == 200:
response_200 = response.json()

response_200 = cast(Any, response.json())
return response_200
if response.status_code == 422:
response_422 = HTTPValidationError.from_dict(response.json())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/tests/basic_lists/booleans".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _get_kwargs(
) -> Dict[str, Any]:
url = "{}/tests/basic_lists/floats".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
headers: Dict[str, str] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

return {
Expand Down
Loading