|
| 1 | +import datetime |
| 2 | +from typing import Any, Dict, List, Optional, Union |
| 3 | + |
| 4 | +import httpx |
| 5 | +from dateutil.parser import isoparse |
| 6 | + |
| 7 | +from ...client import Client |
| 8 | +from ...models.an_enum import AnEnum |
| 9 | +from ...models.http_validation_error import HTTPValidationError |
| 10 | +from ...types import UNSET, Response, Unset |
| 11 | + |
| 12 | + |
| 13 | +def _get_kwargs( |
| 14 | + *, |
| 15 | + client: Client, |
| 16 | + string_prop: Union[Unset, None, str] = "the default string", |
| 17 | + datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), |
| 18 | + date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(), |
| 19 | + float_prop: Union[Unset, None, float] = 3.14, |
| 20 | + int_prop: Union[Unset, None, int] = 7, |
| 21 | + boolean_prop: Union[Unset, None, bool] = False, |
| 22 | + list_prop: Union[Unset, None, List[AnEnum]] = UNSET, |
| 23 | + union_prop: Union[Unset, None, float, str] = "not a float", |
| 24 | + union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6, |
| 25 | + enum_prop: Union[Unset, None, AnEnum] = UNSET, |
| 26 | +) -> Dict[str, Any]: |
| 27 | + url = "{}/tests/defaults".format(client.base_url) |
| 28 | + |
| 29 | + headers: Dict[str, Any] = client.get_headers() |
| 30 | + |
| 31 | + json_datetime_prop: Union[Unset, str] = UNSET |
| 32 | + if not isinstance(datetime_prop, Unset) and datetime_prop is not None: |
| 33 | + json_datetime_prop = datetime_prop.isoformat() |
| 34 | + |
| 35 | + json_date_prop: Union[Unset, str] = UNSET |
| 36 | + if not isinstance(date_prop, Unset) and date_prop is not None: |
| 37 | + json_date_prop = date_prop.isoformat() |
| 38 | + |
| 39 | + json_list_prop: Union[Unset, List[Any]] = UNSET |
| 40 | + if not isinstance(list_prop, Unset) and list_prop is not None: |
| 41 | + json_list_prop = [] |
| 42 | + for list_prop_item_data in list_prop: |
| 43 | + list_prop_item = list_prop_item_data.value |
| 44 | + |
| 45 | + json_list_prop.append(list_prop_item) |
| 46 | + |
| 47 | + json_union_prop: Union[Unset, float, str] |
| 48 | + if isinstance(union_prop, Unset) or union_prop is None: |
| 49 | + json_union_prop = UNSET |
| 50 | + else: |
| 51 | + json_union_prop = union_prop |
| 52 | + |
| 53 | + json_union_prop_with_ref: Union[Unset, float, AnEnum] |
| 54 | + if isinstance(union_prop_with_ref, Unset) or union_prop_with_ref is None: |
| 55 | + json_union_prop_with_ref = UNSET |
| 56 | + elif isinstance(union_prop_with_ref, AnEnum): |
| 57 | + json_union_prop_with_ref = UNSET |
| 58 | + if not isinstance(union_prop_with_ref, Unset): |
| 59 | + json_union_prop_with_ref = union_prop_with_ref |
| 60 | + |
| 61 | + else: |
| 62 | + json_union_prop_with_ref = union_prop_with_ref |
| 63 | + |
| 64 | + json_enum_prop: Union[Unset, AnEnum] = UNSET |
| 65 | + if not isinstance(enum_prop, Unset) and enum_prop is not None: |
| 66 | + json_enum_prop = enum_prop |
| 67 | + |
| 68 | + params: Dict[str, Any] = {} |
| 69 | + if string_prop is not UNSET and string_prop is not None: |
| 70 | + params["string_prop"] = string_prop |
| 71 | + if datetime_prop is not UNSET and datetime_prop is not None: |
| 72 | + params["datetime_prop"] = json_datetime_prop |
| 73 | + if date_prop is not UNSET and date_prop is not None: |
| 74 | + params["date_prop"] = json_date_prop |
| 75 | + if float_prop is not UNSET and float_prop is not None: |
| 76 | + params["float_prop"] = float_prop |
| 77 | + if int_prop is not UNSET and int_prop is not None: |
| 78 | + params["int_prop"] = int_prop |
| 79 | + if boolean_prop is not UNSET and boolean_prop is not None: |
| 80 | + params["boolean_prop"] = boolean_prop |
| 81 | + if list_prop is not UNSET and list_prop is not None: |
| 82 | + params["list_prop"] = json_list_prop |
| 83 | + if union_prop is not UNSET and union_prop is not None: |
| 84 | + params["union_prop"] = json_union_prop |
| 85 | + if union_prop_with_ref is not UNSET and union_prop_with_ref is not None: |
| 86 | + params["union_prop_with_ref"] = json_union_prop_with_ref |
| 87 | + if enum_prop is not UNSET and enum_prop is not None: |
| 88 | + params["enum_prop"] = json_enum_prop |
| 89 | + |
| 90 | + return { |
| 91 | + "url": url, |
| 92 | + "headers": headers, |
| 93 | + "cookies": client.get_cookies(), |
| 94 | + "timeout": client.get_timeout(), |
| 95 | + "params": params, |
| 96 | + } |
| 97 | + |
| 98 | + |
| 99 | +def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]: |
| 100 | + if response.status_code == 200: |
| 101 | + response_200 = None |
| 102 | + |
| 103 | + return response_200 |
| 104 | + if response.status_code == 422: |
| 105 | + response_422 = HTTPValidationError.from_dict(response.json()) |
| 106 | + |
| 107 | + return response_422 |
| 108 | + return None |
| 109 | + |
| 110 | + |
| 111 | +def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]: |
| 112 | + return Response( |
| 113 | + status_code=response.status_code, |
| 114 | + content=response.content, |
| 115 | + headers=response.headers, |
| 116 | + parsed=_parse_response(response=response), |
| 117 | + ) |
| 118 | + |
| 119 | + |
| 120 | +def sync_detailed( |
| 121 | + *, |
| 122 | + client: Client, |
| 123 | + string_prop: Union[Unset, None, str] = "the default string", |
| 124 | + datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), |
| 125 | + date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(), |
| 126 | + float_prop: Union[Unset, None, float] = 3.14, |
| 127 | + int_prop: Union[Unset, None, int] = 7, |
| 128 | + boolean_prop: Union[Unset, None, bool] = False, |
| 129 | + list_prop: Union[Unset, None, List[AnEnum]] = UNSET, |
| 130 | + union_prop: Union[Unset, None, float, str] = "not a float", |
| 131 | + union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6, |
| 132 | + enum_prop: Union[Unset, None, AnEnum] = UNSET, |
| 133 | +) -> Response[Union[None, HTTPValidationError]]: |
| 134 | + kwargs = _get_kwargs( |
| 135 | + client=client, |
| 136 | + string_prop=string_prop, |
| 137 | + datetime_prop=datetime_prop, |
| 138 | + date_prop=date_prop, |
| 139 | + float_prop=float_prop, |
| 140 | + int_prop=int_prop, |
| 141 | + boolean_prop=boolean_prop, |
| 142 | + list_prop=list_prop, |
| 143 | + union_prop=union_prop, |
| 144 | + union_prop_with_ref=union_prop_with_ref, |
| 145 | + enum_prop=enum_prop, |
| 146 | + ) |
| 147 | + |
| 148 | + response = httpx.post( |
| 149 | + **kwargs, |
| 150 | + ) |
| 151 | + |
| 152 | + return _build_response(response=response) |
| 153 | + |
| 154 | + |
| 155 | +def sync( |
| 156 | + *, |
| 157 | + client: Client, |
| 158 | + string_prop: Union[Unset, None, str] = "the default string", |
| 159 | + datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), |
| 160 | + date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(), |
| 161 | + float_prop: Union[Unset, None, float] = 3.14, |
| 162 | + int_prop: Union[Unset, None, int] = 7, |
| 163 | + boolean_prop: Union[Unset, None, bool] = False, |
| 164 | + list_prop: Union[Unset, None, List[AnEnum]] = UNSET, |
| 165 | + union_prop: Union[Unset, None, float, str] = "not a float", |
| 166 | + union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6, |
| 167 | + enum_prop: Union[Unset, None, AnEnum] = UNSET, |
| 168 | +) -> Optional[Union[None, HTTPValidationError]]: |
| 169 | + """ """ |
| 170 | + |
| 171 | + return sync_detailed( |
| 172 | + client=client, |
| 173 | + string_prop=string_prop, |
| 174 | + datetime_prop=datetime_prop, |
| 175 | + date_prop=date_prop, |
| 176 | + float_prop=float_prop, |
| 177 | + int_prop=int_prop, |
| 178 | + boolean_prop=boolean_prop, |
| 179 | + list_prop=list_prop, |
| 180 | + union_prop=union_prop, |
| 181 | + union_prop_with_ref=union_prop_with_ref, |
| 182 | + enum_prop=enum_prop, |
| 183 | + ).parsed |
| 184 | + |
| 185 | + |
| 186 | +async def asyncio_detailed( |
| 187 | + *, |
| 188 | + client: Client, |
| 189 | + string_prop: Union[Unset, None, str] = "the default string", |
| 190 | + datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), |
| 191 | + date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(), |
| 192 | + float_prop: Union[Unset, None, float] = 3.14, |
| 193 | + int_prop: Union[Unset, None, int] = 7, |
| 194 | + boolean_prop: Union[Unset, None, bool] = False, |
| 195 | + list_prop: Union[Unset, None, List[AnEnum]] = UNSET, |
| 196 | + union_prop: Union[Unset, None, float, str] = "not a float", |
| 197 | + union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6, |
| 198 | + enum_prop: Union[Unset, None, AnEnum] = UNSET, |
| 199 | +) -> Response[Union[None, HTTPValidationError]]: |
| 200 | + kwargs = _get_kwargs( |
| 201 | + client=client, |
| 202 | + string_prop=string_prop, |
| 203 | + datetime_prop=datetime_prop, |
| 204 | + date_prop=date_prop, |
| 205 | + float_prop=float_prop, |
| 206 | + int_prop=int_prop, |
| 207 | + boolean_prop=boolean_prop, |
| 208 | + list_prop=list_prop, |
| 209 | + union_prop=union_prop, |
| 210 | + union_prop_with_ref=union_prop_with_ref, |
| 211 | + enum_prop=enum_prop, |
| 212 | + ) |
| 213 | + |
| 214 | + async with httpx.AsyncClient() as _client: |
| 215 | + response = await _client.post(**kwargs) |
| 216 | + |
| 217 | + return _build_response(response=response) |
| 218 | + |
| 219 | + |
| 220 | +async def asyncio( |
| 221 | + *, |
| 222 | + client: Client, |
| 223 | + string_prop: Union[Unset, None, str] = "the default string", |
| 224 | + datetime_prop: Union[Unset, None, datetime.datetime] = isoparse("1010-10-10T00:00:00"), |
| 225 | + date_prop: Union[Unset, None, datetime.date] = isoparse("1010-10-10").date(), |
| 226 | + float_prop: Union[Unset, None, float] = 3.14, |
| 227 | + int_prop: Union[Unset, None, int] = 7, |
| 228 | + boolean_prop: Union[Unset, None, bool] = False, |
| 229 | + list_prop: Union[Unset, None, List[AnEnum]] = UNSET, |
| 230 | + union_prop: Union[Unset, None, float, str] = "not a float", |
| 231 | + union_prop_with_ref: Union[Unset, None, float, AnEnum] = 0.6, |
| 232 | + enum_prop: Union[Unset, None, AnEnum] = UNSET, |
| 233 | +) -> Optional[Union[None, HTTPValidationError]]: |
| 234 | + """ """ |
| 235 | + |
| 236 | + return ( |
| 237 | + await asyncio_detailed( |
| 238 | + client=client, |
| 239 | + string_prop=string_prop, |
| 240 | + datetime_prop=datetime_prop, |
| 241 | + date_prop=date_prop, |
| 242 | + float_prop=float_prop, |
| 243 | + int_prop=int_prop, |
| 244 | + boolean_prop=boolean_prop, |
| 245 | + list_prop=list_prop, |
| 246 | + union_prop=union_prop, |
| 247 | + union_prop_with_ref=union_prop_with_ref, |
| 248 | + enum_prop=enum_prop, |
| 249 | + ) |
| 250 | + ).parsed |
0 commit comments