|
5 | 5 | import httpx |
6 | 6 |
|
7 | 7 | from ...client import AuthenticatedClient, Client |
8 | | -from ...errors import ApiResponseError |
9 | 8 | from ...models.a_model import AModel |
10 | 9 | from ...models.an_enum import AnEnum |
11 | 10 | from ...models.http_validation_error import HTTPValidationError |
| 11 | +from ...types import Response |
12 | 12 |
|
13 | 13 |
|
14 | 14 | def _get_kwargs( |
15 | | - *, client: Client, an_enum_value: List[AnEnum], some_date: Union[datetime.date, datetime.datetime], |
| 15 | + *, |
| 16 | + client: Client, |
| 17 | + an_enum_value: List[AnEnum], |
| 18 | + some_date: Union[datetime.date, datetime.datetime], |
16 | 19 | ) -> Dict[str, Any]: |
17 | 20 | url = "{}/tests/".format(client.base_url) |
18 | 21 |
|
@@ -44,40 +47,89 @@ def _get_kwargs( |
44 | 47 |
|
45 | 48 | def _parse_response( |
46 | 49 | *, response: httpx.Response |
47 | | -) -> Union[ |
48 | | - List[AModel], HTTPValidationError, |
49 | | -]: |
| 50 | +) -> Optional[Union[List[AModel], HTTPValidationError,]]: |
50 | 51 | if response.status_code == 200: |
51 | 52 | return [AModel.from_dict(item) for item in cast(List[Dict[str, Any]], response.json())] |
52 | 53 | if response.status_code == 422: |
53 | 54 | return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json())) |
54 | | - else: |
55 | | - raise ApiResponseError(response=response) |
| 55 | + return None |
| 56 | + |
| 57 | + |
| 58 | +def _build_response( |
| 59 | + *, response: httpx.Response |
| 60 | +) -> Response[Union[List[AModel], HTTPValidationError,]]: |
| 61 | + return Response( |
| 62 | + status_code=response.status_code, |
| 63 | + content=response.content, |
| 64 | + headers=response.headers, |
| 65 | + parsed=_parse_response(response=response), |
| 66 | + ) |
| 67 | + |
| 68 | + |
| 69 | +def sync_detailed( |
| 70 | + *, |
| 71 | + client: Client, |
| 72 | + an_enum_value: List[AnEnum], |
| 73 | + some_date: Union[datetime.date, datetime.datetime], |
| 74 | +) -> Response[Union[List[AModel], HTTPValidationError,]]: |
| 75 | + kwargs = _get_kwargs( |
| 76 | + client=client, |
| 77 | + an_enum_value=an_enum_value, |
| 78 | + some_date=some_date, |
| 79 | + ) |
| 80 | + |
| 81 | + response = httpx.get( |
| 82 | + **kwargs, |
| 83 | + ) |
| 84 | + |
| 85 | + return _build_response(response=response) |
56 | 86 |
|
57 | 87 |
|
58 | 88 | def sync( |
59 | | - *, client: Client, an_enum_value: List[AnEnum], some_date: Union[datetime.date, datetime.datetime], |
60 | | -) -> Union[ |
61 | | - List[AModel], HTTPValidationError, |
62 | | -]: |
| 89 | + *, |
| 90 | + client: Client, |
| 91 | + an_enum_value: List[AnEnum], |
| 92 | + some_date: Union[datetime.date, datetime.datetime], |
| 93 | +) -> Optional[Union[List[AModel], HTTPValidationError,]]: |
63 | 94 | """ Get a list of things """ |
64 | 95 |
|
65 | | - kwargs = _get_kwargs(client=client, an_enum_value=an_enum_value, some_date=some_date,) |
| 96 | + return sync_detailed( |
| 97 | + client=client, |
| 98 | + an_enum_value=an_enum_value, |
| 99 | + some_date=some_date, |
| 100 | + ).parsed |
| 101 | + |
| 102 | + |
| 103 | +async def asyncio_detailed( |
| 104 | + *, |
| 105 | + client: Client, |
| 106 | + an_enum_value: List[AnEnum], |
| 107 | + some_date: Union[datetime.date, datetime.datetime], |
| 108 | +) -> Response[Union[List[AModel], HTTPValidationError,]]: |
| 109 | + kwargs = _get_kwargs( |
| 110 | + client=client, |
| 111 | + an_enum_value=an_enum_value, |
| 112 | + some_date=some_date, |
| 113 | + ) |
66 | 114 |
|
67 | | - response = httpx.get(**kwargs,) |
| 115 | + async with httpx.AsyncClient() as _client: |
| 116 | + response = await _client.get(**kwargs) |
68 | 117 |
|
69 | | - return _parse_response(response=response) |
| 118 | + return _build_response(response=response) |
70 | 119 |
|
71 | 120 |
|
72 | 121 | 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 | | -]: |
| 122 | + *, |
| 123 | + client: Client, |
| 124 | + an_enum_value: List[AnEnum], |
| 125 | + some_date: Union[datetime.date, datetime.datetime], |
| 126 | +) -> Optional[Union[List[AModel], HTTPValidationError,]]: |
77 | 127 | """ 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 | 128 |
|
83 | | - return _parse_response(response=response) |
| 129 | + return ( |
| 130 | + await asyncio_detailed( |
| 131 | + client=client, |
| 132 | + an_enum_value=an_enum_value, |
| 133 | + some_date=some_date, |
| 134 | + ) |
| 135 | + ).parsed |
0 commit comments