Skip to content

Commit 94f6210

Browse files
committed
Convert generated clients to new API.
1 parent 11adc3a commit 94f6210

24 files changed

+690
-796
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
""" Contains synchronous methods for accessing the API """
1+
""" Contains methods for accessing the API """

end_to_end_tests/golden-master/my_test_api_client/api/default.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

end_to_end_tests/golden-master/my_test_api_client/api/default/__init__.py

Whitespace-only changes.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from dataclasses import asdict
2+
from typing import Any, Dict, List, Optional, Union, cast
3+
4+
import httpx
5+
6+
from ...client import AuthenticatedClient, Client
7+
from ...errors import ApiResponseError
8+
9+
10+
def _get_kwargs(*, client: Client,) -> Dict[str, Any]:
11+
url = "{}/ping".format(client.base_url)
12+
13+
headers: Dict[str, Any] = client.get_headers()
14+
15+
return {
16+
"url": url,
17+
"headers": headers,
18+
}
19+
20+
21+
def _parse_response(*, response: httpx.Response) -> bool:
22+
23+
if response.status_code == 200:
24+
return bool(response.text)
25+
else:
26+
raise ApiResponseError(response=response)
27+
28+
29+
def sync(*, client: Client,) -> bool:
30+
31+
""" A quick check to see if the system is running """
32+
33+
kwargs = _get_kwargs(client=client,)
34+
35+
response = httpx.get(**kwargs,)
36+
37+
return _parse_response(response=response)
38+
39+
40+
async def asyncio(*, client: Client,) -> bool:
41+
42+
""" A quick check to see if the system is running """
43+
kwargs = _get_kwargs(client=client,)
44+
45+
async with httpx.AsyncClient() as _client:
46+
response = await _client.get(**kwargs)
47+
48+
return _parse_response(response=response)

end_to_end_tests/golden-master/my_test_api_client/api/tests.py

Lines changed: 0 additions & 189 deletions
This file was deleted.

end_to_end_tests/golden-master/my_test_api_client/api/tests/__init__.py

Whitespace-only changes.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import datetime
2+
from dataclasses import asdict
3+
from typing import Any, Dict, List, Optional, Union, cast
4+
5+
import httpx
6+
7+
from ...client import AuthenticatedClient, Client
8+
from ...errors import ApiResponseError
9+
from ...models.a_model import AModel
10+
from ...models.an_enum import AnEnum
11+
from ...models.http_validation_error import HTTPValidationError
12+
13+
14+
def _get_kwargs(
15+
*, client: Client, an_enum_value: List[AnEnum], some_date: Union[datetime.date, datetime.datetime],
16+
) -> Dict[str, Any]:
17+
url = "{}/tests/".format(client.base_url)
18+
19+
headers: Dict[str, Any] = client.get_headers()
20+
21+
json_an_enum_value = []
22+
for an_enum_value_item_data in an_enum_value:
23+
an_enum_value_item = an_enum_value_item_data.value
24+
25+
json_an_enum_value.append(an_enum_value_item)
26+
27+
if isinstance(some_date, datetime.date):
28+
json_some_date = some_date.isoformat()
29+
30+
else:
31+
json_some_date = some_date.isoformat()
32+
33+
params: Dict[str, Any] = {
34+
"an_enum_value": json_an_enum_value,
35+
"some_date": json_some_date,
36+
}
37+
38+
return {
39+
"url": url,
40+
"headers": headers,
41+
"params": params,
42+
}
43+
44+
45+
def _parse_response(
46+
*, response: httpx.Response
47+
) -> Union[
48+
List[AModel], HTTPValidationError,
49+
]:
50+
if response.status_code == 200:
51+
return [AModel.from_dict(item) for item in cast(List[Dict[str, Any]], response.json())]
52+
if response.status_code == 422:
53+
return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json()))
54+
else:
55+
raise ApiResponseError(response=response)
56+
57+
58+
def sync(
59+
*, client: Client, an_enum_value: List[AnEnum], some_date: Union[datetime.date, datetime.datetime],
60+
) -> Union[
61+
List[AModel], HTTPValidationError,
62+
]:
63+
""" Get a list of things """
64+
65+
kwargs = _get_kwargs(client=client, an_enum_value=an_enum_value, some_date=some_date,)
66+
67+
response = httpx.get(**kwargs,)
68+
69+
return _parse_response(response=response)
70+
71+
72+
async def asyncio(
73+
*, client: Client, an_enum_value: List[AnEnum], some_date: Union[datetime.date, datetime.datetime],
74+
) -> Union[
75+
List[AModel], HTTPValidationError,
76+
]:
77+
""" Get a list of things """
78+
kwargs = _get_kwargs(client=client, an_enum_value=an_enum_value, some_date=some_date,)
79+
80+
async with httpx.AsyncClient() as _client:
81+
response = await _client.get(**kwargs)
82+
83+
return _parse_response(response=response)

0 commit comments

Comments
 (0)