|
| 1 | +from http import HTTPStatus |
| 2 | +from typing import Any, Dict, Optional, Union |
| 3 | + |
| 4 | +import httpx |
| 5 | + |
| 6 | +from ... import errors |
| 7 | +from ...client import AuthenticatedClient, Client |
| 8 | +from ...models.get_models_oneof_with_required_const_response_200_type_0 import ( |
| 9 | + GetModelsOneofWithRequiredConstResponse200Type0, |
| 10 | +) |
| 11 | +from ...models.get_models_oneof_with_required_const_response_200_type_1 import ( |
| 12 | + GetModelsOneofWithRequiredConstResponse200Type1, |
| 13 | +) |
| 14 | +from ...types import Response |
| 15 | + |
| 16 | + |
| 17 | +def _get_kwargs() -> Dict[str, Any]: |
| 18 | + _kwargs: Dict[str, Any] = { |
| 19 | + "method": "get", |
| 20 | + "url": "/models/oneof-with-required-const", |
| 21 | + } |
| 22 | + |
| 23 | + return _kwargs |
| 24 | + |
| 25 | + |
| 26 | +def _parse_response( |
| 27 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 28 | +) -> Optional[ |
| 29 | + Union["GetModelsOneofWithRequiredConstResponse200Type0", "GetModelsOneofWithRequiredConstResponse200Type1"] |
| 30 | +]: |
| 31 | + if response.status_code == 200: |
| 32 | + |
| 33 | + def _parse_response_200( |
| 34 | + data: object, |
| 35 | + ) -> Union[ |
| 36 | + "GetModelsOneofWithRequiredConstResponse200Type0", "GetModelsOneofWithRequiredConstResponse200Type1" |
| 37 | + ]: |
| 38 | + try: |
| 39 | + if not isinstance(data, dict): |
| 40 | + raise TypeError() |
| 41 | + response_200_type_0 = GetModelsOneofWithRequiredConstResponse200Type0.from_dict(data) |
| 42 | + |
| 43 | + return response_200_type_0 |
| 44 | + except: # noqa: E722 |
| 45 | + pass |
| 46 | + if not isinstance(data, dict): |
| 47 | + raise TypeError() |
| 48 | + response_200_type_1 = GetModelsOneofWithRequiredConstResponse200Type1.from_dict(data) |
| 49 | + |
| 50 | + return response_200_type_1 |
| 51 | + |
| 52 | + response_200 = _parse_response_200(response.json()) |
| 53 | + |
| 54 | + return response_200 |
| 55 | + if client.raise_on_unexpected_status: |
| 56 | + raise errors.UnexpectedStatus(response.status_code, response.content) |
| 57 | + else: |
| 58 | + return None |
| 59 | + |
| 60 | + |
| 61 | +def _build_response( |
| 62 | + *, client: Union[AuthenticatedClient, Client], response: httpx.Response |
| 63 | +) -> Response[ |
| 64 | + Union["GetModelsOneofWithRequiredConstResponse200Type0", "GetModelsOneofWithRequiredConstResponse200Type1"] |
| 65 | +]: |
| 66 | + return Response( |
| 67 | + status_code=HTTPStatus(response.status_code), |
| 68 | + content=response.content, |
| 69 | + headers=response.headers, |
| 70 | + parsed=_parse_response(client=client, response=response), |
| 71 | + ) |
| 72 | + |
| 73 | + |
| 74 | +def sync_detailed( |
| 75 | + *, |
| 76 | + client: Union[AuthenticatedClient, Client], |
| 77 | +) -> Response[ |
| 78 | + Union["GetModelsOneofWithRequiredConstResponse200Type0", "GetModelsOneofWithRequiredConstResponse200Type1"] |
| 79 | +]: |
| 80 | + """ |
| 81 | + Raises: |
| 82 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 83 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 84 | +
|
| 85 | + Returns: |
| 86 | + Response[Union['GetModelsOneofWithRequiredConstResponse200Type0', 'GetModelsOneofWithRequiredConstResponse200Type1']] |
| 87 | + """ |
| 88 | + |
| 89 | + kwargs = _get_kwargs() |
| 90 | + |
| 91 | + response = client.get_httpx_client().request( |
| 92 | + **kwargs, |
| 93 | + ) |
| 94 | + |
| 95 | + return _build_response(client=client, response=response) |
| 96 | + |
| 97 | + |
| 98 | +def sync( |
| 99 | + *, |
| 100 | + client: Union[AuthenticatedClient, Client], |
| 101 | +) -> Optional[ |
| 102 | + Union["GetModelsOneofWithRequiredConstResponse200Type0", "GetModelsOneofWithRequiredConstResponse200Type1"] |
| 103 | +]: |
| 104 | + """ |
| 105 | + Raises: |
| 106 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 107 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 108 | +
|
| 109 | + Returns: |
| 110 | + Union['GetModelsOneofWithRequiredConstResponse200Type0', 'GetModelsOneofWithRequiredConstResponse200Type1'] |
| 111 | + """ |
| 112 | + |
| 113 | + return sync_detailed( |
| 114 | + client=client, |
| 115 | + ).parsed |
| 116 | + |
| 117 | + |
| 118 | +async def asyncio_detailed( |
| 119 | + *, |
| 120 | + client: Union[AuthenticatedClient, Client], |
| 121 | +) -> Response[ |
| 122 | + Union["GetModelsOneofWithRequiredConstResponse200Type0", "GetModelsOneofWithRequiredConstResponse200Type1"] |
| 123 | +]: |
| 124 | + """ |
| 125 | + Raises: |
| 126 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 127 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 128 | +
|
| 129 | + Returns: |
| 130 | + Response[Union['GetModelsOneofWithRequiredConstResponse200Type0', 'GetModelsOneofWithRequiredConstResponse200Type1']] |
| 131 | + """ |
| 132 | + |
| 133 | + kwargs = _get_kwargs() |
| 134 | + |
| 135 | + response = await client.get_async_httpx_client().request(**kwargs) |
| 136 | + |
| 137 | + return _build_response(client=client, response=response) |
| 138 | + |
| 139 | + |
| 140 | +async def asyncio( |
| 141 | + *, |
| 142 | + client: Union[AuthenticatedClient, Client], |
| 143 | +) -> Optional[ |
| 144 | + Union["GetModelsOneofWithRequiredConstResponse200Type0", "GetModelsOneofWithRequiredConstResponse200Type1"] |
| 145 | +]: |
| 146 | + """ |
| 147 | + Raises: |
| 148 | + errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. |
| 149 | + httpx.TimeoutException: If the request takes longer than Client.timeout. |
| 150 | +
|
| 151 | + Returns: |
| 152 | + Union['GetModelsOneofWithRequiredConstResponse200Type0', 'GetModelsOneofWithRequiredConstResponse200Type1'] |
| 153 | + """ |
| 154 | + |
| 155 | + return ( |
| 156 | + await asyncio_detailed( |
| 157 | + client=client, |
| 158 | + ) |
| 159 | + ).parsed |
0 commit comments