diff --git a/README.md b/README.md index cea385093..dcbdedc63 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,21 @@ class_overrides: module_name: short_name ``` +### tag_overrides + +Used to change the name of tags. This param should be a mapping of existing tag name to class_name and identifier_name. +As an example, if the tag in OpenAPI was something like "Very Long Name" and you want the generated client's class names and +identifier names to be called "LongName" with identifier called "long_name" you could do this: + +Example: + +```yaml +tag_overrides: + "Very Long Name": + class_name: LongName + identifier_name: long_name +``` + The easiest way to find what needs to be overridden is probably to generate your client and go look at everything in the models folder. ### project_name_override and package_name_override diff --git a/end_to_end_tests/custom-templates-golden-record/my_test_api_client/client.py b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/client.py new file mode 100644 index 000000000..3944891dd --- /dev/null +++ b/end_to_end_tests/custom-templates-golden-record/my_test_api_client/client.py @@ -0,0 +1,59 @@ +import ssl +from typing import Dict, Union + + +class MyTestApiClient: + """A class for keeping track of data related to the API + + Attributes: + base_url: The base URL for the API, all requests are made to a relative path to this URL + cookies: A dictionary of cookies to be sent with every request + headers: A dictionary of headers to be sent with every request + timeout: The maximum amount of a time in seconds a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + verify_ssl: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. + follow_redirects: Whether or not to follow redirects. Default value is False. + """ + + def __init__( + self, + base_url: str, + cookies: Union[Dict[str, str], None] = None, + headers: Union[Dict[str, str], None] = None, + timeout: float = 5.0, + verify_ssl: Union[str, bool, ssl.SSLContext] = True, + raise_on_unexpected_status: bool = False, + follow_redirects: bool = False, + token: Union[str, None] = None, + prefix: str = "Bearer", + auth_header_name: str = "Authorization", + ): + cookies = cookies if cookies is not None else {} + headers = headers if headers is not None else {} + + self.base_url = base_url + self.cookies = cookies + self.headers = headers + self.timeout = timeout + self.verify_ssl = verify_ssl + self.raise_on_unexpected_status = raise_on_unexpected_status + self.follow_redirects = follow_redirects + self.token = token + self.prefix = prefix + self.auth_header_name = auth_header_name + + def get_headers(self) -> Dict[str, str]: + """Get headers to be used in all endpoints""" + if not self.token: + return {**self.headers} + auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token + return {self.auth_header_name: auth_header_value, **self.headers} + + def get_cookies(self) -> Dict[str, str]: + return {**self.cookies} + + def get_timeout(self) -> float: + return self.timeout diff --git a/end_to_end_tests/golden-record/README.md b/end_to_end_tests/golden-record/README.md index 3def2172e..cb80d1412 100644 --- a/end_to_end_tests/golden-record/README.md +++ b/end_to_end_tests/golden-record/README.md @@ -2,49 +2,34 @@ A client library for accessing My Test API ## Usage -First, create a client: +First, configure a client: ```python -from my_test_api_client import Client +from my_test_api_client import MyTestApiClient -client = Client(base_url="https://api.example.com") -``` - -If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead: - -```python -from my_test_api_client import AuthenticatedClient - -client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken") +client = MyTestApiClient(base_url="https://api.example.com", token="SuperSecretToken") ``` Now call your endpoint and use your models: ```python from my_test_api_client.models import MyDataModel -from my_test_api_client.api.my_tag import get_my_data_model -from my_test_api_client.types import Response -my_data: MyDataModel = get_my_data_model.sync(client=client) -# or if you need more info (e.g. status_code) -response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) +my_data: MyDataModel = client.my_tag.get_my_data_model() ``` Or do the same thing with an async version: ```python from my_test_api_client.models import MyDataModel -from my_test_api_client.api.my_tag import get_my_data_model -from my_test_api_client.types import Response -my_data: MyDataModel = await get_my_data_model.asyncio(client=client) -response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) +my_data: MyDataModel = await client.get_my_data_model_async() ``` By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle. ```python -client = AuthenticatedClient( +client = MyTestApiClient( base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl="/path/to/certificate_bundle.pem", @@ -54,25 +39,23 @@ client = AuthenticatedClient( You can also disable certificate validation altogether, but beware that **this is a security risk**. ```python -client = AuthenticatedClient( +client = MyTestApiClient( base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False ) ``` -There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. +There are more settings on the generated `MyTestApiClient` class which let you control more runtime behavior, check out the docstring on that class for more info. Things to know: -1. Every path/method combo becomes a Python module with four functions: - 1. `sync`: Blocking request that returns parsed data (if successful) or `None` - 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful. - 1. `asyncio`: Like `sync` but async instead of blocking - 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking +1. Every path/method combo becomes provides you with two functions. For example: get_my_data_model has these methods: + 1. `get_my_data_model`: Blocking request that returns parsed data (if successful) or `None` + 1. `get_my_data_model_async`: Like `sync` but async instead of blocking 1. All path/query params, and bodies become method arguments. 1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) -1. Any endpoint which did not have a tag will be in `my_test_api_client.api.default` +1. Any endpoint which did not have a tag will be in `my_test_api_client.default` ## Building / publishing this Client This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: diff --git a/end_to_end_tests/golden-record/my_test_api_client/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/__init__.py index 530928e7a..aff096cbb 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/__init__.py @@ -1,7 +1,4 @@ """ A client library for accessing My Test API """ -from .client import AuthenticatedClient, Client +from .client import MyTestApiClient -__all__ = ( - "AuthenticatedClient", - "Client", -) +__all__ = ("MyTestApiClient",) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/__init__.py index e69de29bb..26bf962e0 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/__init__.py @@ -0,0 +1,102 @@ +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Optional, Union + +from ...types import UNSET, Unset +from . import get_common_parameters, post_common_parameters + + +class Default: + def __init__(self, client: "MyTestApiClient"): + self.__client = client + + def get_common_parameters( + self, + *, + common: Union[Unset, None, str] = UNSET, + ) -> Any: + """ + Args: + common (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return get_common_parameters.sync( + client=self.__client, + common=common, + ) + + async def get_common_parameters_async( + self, + *, + common: Union[Unset, None, str] = UNSET, + ) -> Any: + """ + Args: + common (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await get_common_parameters.asyncio( + client=self.__client, + common=common, + ) + + def post_common_parameters( + self, + *, + common: Union[Unset, None, str] = UNSET, + ) -> Any: + """ + Args: + common (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return post_common_parameters.sync( + client=self.__client, + common=common, + ) + + async def post_common_parameters_async( + self, + *, + common: Union[Unset, None, str] = UNSET, + ) -> Any: + """ + Args: + common (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await post_common_parameters.asyncio( + client=self.__client, + common=common, + ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py index a2478b80d..d2e7a5981 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/get_common_parameters.py @@ -1,18 +1,18 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, Union import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Union + from ... import errors -from ...client import Client from ...types import UNSET, Response, Unset -def _get_kwargs( - *, - client: Client, - common: Union[Unset, None, str] = UNSET, -) -> Dict[str, Any]: +def _get_kwargs(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/common_parameters".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -34,16 +34,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -52,17 +50,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, - common: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +def sync_detailed(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Response[Any]: """ Args: common (Union[Unset, None, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -82,17 +76,32 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, - common: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +def sync(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Any: + """ + Args: + common (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + common=common, + ).parsed + + +async def asyncio_detailed(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Response[Any]: """ Args: common (Union[Unset, None, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -108,3 +117,24 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Any: + """ + Args: + common (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + common=common, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py index 99e7f21d7..f4a23e562 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/default/post_common_parameters.py @@ -1,18 +1,18 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, Union import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Union + from ... import errors -from ...client import Client from ...types import UNSET, Response, Unset -def _get_kwargs( - *, - client: Client, - common: Union[Unset, None, str] = UNSET, -) -> Dict[str, Any]: +def _get_kwargs(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/common_parameters".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -34,16 +34,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -52,17 +50,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, - common: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +def sync_detailed(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Response[Any]: """ Args: common (Union[Unset, None, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -82,17 +76,32 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, - common: Union[Unset, None, str] = UNSET, -) -> Response[Any]: +def sync(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Any: + """ + Args: + common (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + common=common, + ).parsed + + +async def asyncio_detailed(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Response[Any]: """ Args: common (Union[Unset, None, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -108,3 +117,24 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(*, common: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Any: + """ + Args: + common (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + common=common, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/__init__.py index e69de29bb..0ae83f7d5 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/__init__.py @@ -0,0 +1,155 @@ +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from ...client import MyTestApiClient + +import datetime +from typing import Optional, Union, cast + +from dateutil.parser import isoparse + +from ...models.get_location_header_types_int_enum_header import GetLocationHeaderTypesIntEnumHeader +from ...models.get_location_header_types_string_enum_header import GetLocationHeaderTypesStringEnumHeader +from ...types import UNSET, Unset +from . import get_location_header_types, get_location_query_optionality + + +class Location: + def __init__(self, client: "MyTestApiClient"): + self.__client = client + + def get_location_query_optionality( + self, + *, + not_null_required: datetime.datetime, + null_required: Union[Unset, None, datetime.datetime] = UNSET, + null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + ) -> Any: + """ + Args: + not_null_required (datetime.datetime): + null_required (Union[Unset, None, datetime.datetime]): + null_not_required (Union[Unset, None, datetime.datetime]): + not_null_not_required (Union[Unset, None, datetime.datetime]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return get_location_query_optionality.sync( + client=self.__client, + not_null_required=not_null_required, + null_required=null_required, + null_not_required=null_not_required, + not_null_not_required=not_null_not_required, + ) + + async def get_location_query_optionality_async( + self, + *, + not_null_required: datetime.datetime, + null_required: Union[Unset, None, datetime.datetime] = UNSET, + null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + ) -> Any: + """ + Args: + not_null_required (datetime.datetime): + null_required (Union[Unset, None, datetime.datetime]): + null_not_required (Union[Unset, None, datetime.datetime]): + not_null_not_required (Union[Unset, None, datetime.datetime]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await get_location_query_optionality.asyncio( + client=self.__client, + not_null_required=not_null_required, + null_required=null_required, + null_not_required=null_not_required, + not_null_not_required=not_null_not_required, + ) + + def get_location_header_types( + self, + *, + boolean_header: Union[Unset, bool] = UNSET, + string_header: Union[Unset, str] = UNSET, + number_header: Union[Unset, float] = UNSET, + integer_header: Union[Unset, int] = UNSET, + int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, + string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, + ) -> Any: + """ + Args: + boolean_header (Union[Unset, bool]): + string_header (Union[Unset, str]): + number_header (Union[Unset, float]): + integer_header (Union[Unset, int]): + int_enum_header (Union[Unset, GetLocationHeaderTypesIntEnumHeader]): + string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return get_location_header_types.sync( + client=self.__client, + boolean_header=boolean_header, + string_header=string_header, + number_header=number_header, + integer_header=integer_header, + int_enum_header=int_enum_header, + string_enum_header=string_enum_header, + ) + + async def get_location_header_types_async( + self, + *, + boolean_header: Union[Unset, bool] = UNSET, + string_header: Union[Unset, str] = UNSET, + number_header: Union[Unset, float] = UNSET, + integer_header: Union[Unset, int] = UNSET, + int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, + string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, + ) -> Any: + """ + Args: + boolean_header (Union[Unset, bool]): + string_header (Union[Unset, str]): + number_header (Union[Unset, float]): + integer_header (Union[Unset, int]): + int_enum_header (Union[Unset, GetLocationHeaderTypesIntEnumHeader]): + string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await get_location_header_types.asyncio( + client=self.__client, + boolean_header=boolean_header, + string_header=string_header, + number_header=number_header, + integer_header=integer_header, + int_enum_header=int_enum_header, + string_enum_header=string_enum_header, + ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py index 9249eab31..b83c71db1 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_header_types.py @@ -1,10 +1,14 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, Union import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Union + from ... import errors -from ...client import Client from ...models.get_location_header_types_int_enum_header import GetLocationHeaderTypesIntEnumHeader from ...models.get_location_header_types_string_enum_header import GetLocationHeaderTypesStringEnumHeader from ...types import UNSET, Response, Unset @@ -12,13 +16,13 @@ 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, int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, + client: "MyTestApiClient", ) -> Dict[str, Any]: url = "{}/location/header/types".format(client.base_url) @@ -53,16 +57,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -73,13 +75,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any 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, int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, + client: "MyTestApiClient", ) -> Response[Any]: """ Args: @@ -91,7 +93,7 @@ def sync_detailed( string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -116,15 +118,53 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync( + *, + boolean_header: Union[Unset, bool] = UNSET, + string_header: Union[Unset, str] = UNSET, + number_header: Union[Unset, float] = UNSET, + integer_header: Union[Unset, int] = UNSET, + int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, + string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, + client: "MyTestApiClient", +) -> Any: + """ + Args: + boolean_header (Union[Unset, bool]): + string_header (Union[Unset, str]): + number_header (Union[Unset, float]): + integer_header (Union[Unset, int]): + int_enum_header (Union[Unset, GetLocationHeaderTypesIntEnumHeader]): + string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + boolean_header=boolean_header, + string_header=string_header, + number_header=number_header, + integer_header=integer_header, + int_enum_header=int_enum_header, + string_enum_header=string_enum_header, + ).parsed + + 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, int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, + client: "MyTestApiClient", ) -> Response[Any]: """ Args: @@ -136,7 +176,7 @@ async def asyncio_detailed( string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -157,3 +197,43 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio( + *, + boolean_header: Union[Unset, bool] = UNSET, + string_header: Union[Unset, str] = UNSET, + number_header: Union[Unset, float] = UNSET, + integer_header: Union[Unset, int] = UNSET, + int_enum_header: Union[Unset, GetLocationHeaderTypesIntEnumHeader] = UNSET, + string_enum_header: Union[Unset, GetLocationHeaderTypesStringEnumHeader] = UNSET, + client: "MyTestApiClient", +) -> Any: + """ + Args: + boolean_header (Union[Unset, bool]): + string_header (Union[Unset, str]): + number_header (Union[Unset, float]): + integer_header (Union[Unset, int]): + int_enum_header (Union[Unset, GetLocationHeaderTypesIntEnumHeader]): + string_enum_header (Union[Unset, GetLocationHeaderTypesStringEnumHeader]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + boolean_header=boolean_header, + string_header=string_header, + number_header=number_header, + integer_header=integer_header, + int_enum_header=int_enum_header, + string_enum_header=string_enum_header, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py index 0209c7319..d9447ac9f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/location/get_location_query_optionality.py @@ -1,21 +1,25 @@ -import datetime from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, Union import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +import datetime +from typing import Union + from ... import errors -from ...client import Client from ...types import UNSET, Response, Unset def _get_kwargs( *, - client: Client, not_null_required: datetime.datetime, null_required: Union[Unset, None, datetime.datetime] = UNSET, null_not_required: Union[Unset, None, datetime.datetime] = UNSET, not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + client: "MyTestApiClient", ) -> Dict[str, Any]: url = "{}/location/query/optionality".format(client.base_url) @@ -58,16 +62,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -78,11 +80,11 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any def sync_detailed( *, - client: Client, not_null_required: datetime.datetime, null_required: Union[Unset, None, datetime.datetime] = UNSET, null_not_required: Union[Unset, None, datetime.datetime] = UNSET, not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + client: "MyTestApiClient", ) -> Response[Any]: """ Args: @@ -92,7 +94,7 @@ def sync_detailed( not_null_not_required (Union[Unset, None, datetime.datetime]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -115,13 +117,45 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync( + *, + not_null_required: datetime.datetime, + null_required: Union[Unset, None, datetime.datetime] = UNSET, + null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + client: "MyTestApiClient", +) -> Any: + """ + Args: + not_null_required (datetime.datetime): + null_required (Union[Unset, None, datetime.datetime]): + null_not_required (Union[Unset, None, datetime.datetime]): + not_null_not_required (Union[Unset, None, datetime.datetime]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + not_null_required=not_null_required, + null_required=null_required, + null_not_required=null_not_required, + not_null_not_required=not_null_not_required, + ).parsed + + async def asyncio_detailed( *, - client: Client, not_null_required: datetime.datetime, null_required: Union[Unset, None, datetime.datetime] = UNSET, null_not_required: Union[Unset, None, datetime.datetime] = UNSET, not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + client: "MyTestApiClient", ) -> Response[Any]: """ Args: @@ -131,7 +165,7 @@ async def asyncio_detailed( not_null_not_required (Union[Unset, None, datetime.datetime]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -150,3 +184,37 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio( + *, + not_null_required: datetime.datetime, + null_required: Union[Unset, None, datetime.datetime] = UNSET, + null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET, + client: "MyTestApiClient", +) -> Any: + """ + Args: + not_null_required (datetime.datetime): + null_required (Union[Unset, None, datetime.datetime]): + null_not_required (Union[Unset, None, datetime.datetime]): + not_null_not_required (Union[Unset, None, datetime.datetime]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + not_null_required=not_null_required, + null_required=null_required, + null_not_required=null_not_required, + not_null_not_required=not_null_not_required, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/__init__.py index e69de29bb..138cf3f1b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/__init__.py @@ -0,0 +1,84 @@ +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Optional, Union + +from ...types import UNSET, Unset +from . import get_parameter_references_path_param + + +class ParameterReferences: + def __init__(self, client: "MyTestApiClient"): + self.__client = client + + def get_parameter_references_path_param( + self, + path_param: str, + *, + string_param: Union[Unset, None, str] = UNSET, + integer_param: Union[Unset, None, int] = 0, + header_param: Union[Unset, str] = UNSET, + cookie_param: Union[Unset, str] = UNSET, + ) -> Any: + """Test different types of parameter references + + Args: + path_param (str): + string_param (Union[Unset, None, str]): + integer_param (Union[Unset, None, int]): + header_param (Union[Unset, str]): + cookie_param (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return get_parameter_references_path_param.sync( + client=self.__client, + path_param=path_param, + string_param=string_param, + integer_param=integer_param, + header_param=header_param, + cookie_param=cookie_param, + ) + + async def get_parameter_references_path_param_async( + self, + path_param: str, + *, + string_param: Union[Unset, None, str] = UNSET, + integer_param: Union[Unset, None, int] = 0, + header_param: Union[Unset, str] = UNSET, + cookie_param: Union[Unset, str] = UNSET, + ) -> Any: + """Test different types of parameter references + + Args: + path_param (str): + string_param (Union[Unset, None, str]): + integer_param (Union[Unset, None, int]): + header_param (Union[Unset, str]): + cookie_param (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await get_parameter_references_path_param.asyncio( + client=self.__client, + path_param=path_param, + string_param=string_param, + integer_param=integer_param, + header_param=header_param, + cookie_param=cookie_param, + ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py index b8c33ec94..b19f9a3c5 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameter_references/get_parameter_references_path_param.py @@ -1,21 +1,25 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, Union import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Union + from ... import errors -from ...client import Client from ...types import UNSET, Response, Unset def _get_kwargs( path_param: str, *, - client: Client, string_param: Union[Unset, None, str] = UNSET, integer_param: Union[Unset, None, int] = 0, header_param: Union[Unset, str] = UNSET, cookie_param: Union[Unset, str] = UNSET, + client: "MyTestApiClient", ) -> Dict[str, Any]: url = "{}/parameter-references/{path_param}".format(client.base_url, path_param=path_param) @@ -46,16 +50,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -67,11 +69,11 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any def sync_detailed( path_param: str, *, - client: Client, string_param: Union[Unset, None, str] = UNSET, integer_param: Union[Unset, None, int] = 0, header_param: Union[Unset, str] = UNSET, cookie_param: Union[Unset, str] = UNSET, + client: "MyTestApiClient", ) -> Response[Any]: """Test different types of parameter references @@ -83,7 +85,7 @@ def sync_detailed( cookie_param (Union[Unset, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -107,14 +109,50 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync( + path_param: str, + *, + string_param: Union[Unset, None, str] = UNSET, + integer_param: Union[Unset, None, int] = 0, + header_param: Union[Unset, str] = UNSET, + cookie_param: Union[Unset, str] = UNSET, + client: "MyTestApiClient", +) -> Any: + """Test different types of parameter references + + Args: + path_param (str): + string_param (Union[Unset, None, str]): + integer_param (Union[Unset, None, int]): + header_param (Union[Unset, str]): + cookie_param (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + path_param=path_param, + client=client, + string_param=string_param, + integer_param=integer_param, + header_param=header_param, + cookie_param=cookie_param, + ).parsed + + async def asyncio_detailed( path_param: str, *, - client: Client, string_param: Union[Unset, None, str] = UNSET, integer_param: Union[Unset, None, int] = 0, header_param: Union[Unset, str] = UNSET, cookie_param: Union[Unset, str] = UNSET, + client: "MyTestApiClient", ) -> Response[Any]: """Test different types of parameter references @@ -126,7 +164,7 @@ async def asyncio_detailed( cookie_param (Union[Unset, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -146,3 +184,41 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio( + path_param: str, + *, + string_param: Union[Unset, None, str] = UNSET, + integer_param: Union[Unset, None, int] = 0, + header_param: Union[Unset, str] = UNSET, + cookie_param: Union[Unset, str] = UNSET, + client: "MyTestApiClient", +) -> Any: + """Test different types of parameter references + + Args: + path_param (str): + string_param (Union[Unset, None, str]): + integer_param (Union[Unset, None, int]): + header_param (Union[Unset, str]): + cookie_param (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + path_param=path_param, + client=client, + string_param=string_param, + integer_param=integer_param, + header_param=header_param, + cookie_param=cookie_param, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/__init__.py index e69de29bb..d87482e1a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/__init__.py @@ -0,0 +1,245 @@ +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Optional, Union + +from ...types import UNSET, Unset +from . import ( + delete_common_parameters_overriding_param, + get_common_parameters_overriding_param, + get_same_name_multiple_locations_param, + multiple_path_parameters, +) + + +class Parameters: + def __init__(self, client: "MyTestApiClient"): + self.__client = client + + def get_common_parameters_overriding_param( + self, + param_path: str, + *, + param_query: str = "overridden_in_GET", + ) -> Any: + """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code + + Args: + param_path (str): + param_query (str): A parameter with the same name as another. Default: + 'overridden_in_GET'. Example: an example string. + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return get_common_parameters_overriding_param.sync( + client=self.__client, + param_path=param_path, + param_query=param_query, + ) + + async def get_common_parameters_overriding_param_async( + self, + param_path: str, + *, + param_query: str = "overridden_in_GET", + ) -> Any: + """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code + + Args: + param_path (str): + param_query (str): A parameter with the same name as another. Default: + 'overridden_in_GET'. Example: an example string. + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await get_common_parameters_overriding_param.asyncio( + client=self.__client, + param_path=param_path, + param_query=param_query, + ) + + def delete_common_parameters_overriding_param( + self, + param_path: str, + *, + param_query: Union[Unset, None, str] = UNSET, + ) -> Any: + """ + Args: + param_path (str): + param_query (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return delete_common_parameters_overriding_param.sync( + client=self.__client, + param_path=param_path, + param_query=param_query, + ) + + async def delete_common_parameters_overriding_param_async( + self, + param_path: str, + *, + param_query: Union[Unset, None, str] = UNSET, + ) -> Any: + """ + Args: + param_path (str): + param_query (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await delete_common_parameters_overriding_param.asyncio( + client=self.__client, + param_path=param_path, + param_query=param_query, + ) + + def get_same_name_multiple_locations_param( + self, + param_path: str, + *, + param_query: Union[Unset, None, str] = UNSET, + param_header: Union[Unset, str] = UNSET, + param_cookie: Union[Unset, str] = UNSET, + ) -> Any: + """ + Args: + param_path (str): + param_query (Union[Unset, None, str]): + param_header (Union[Unset, str]): + param_cookie (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return get_same_name_multiple_locations_param.sync( + client=self.__client, + param_path=param_path, + param_query=param_query, + param_header=param_header, + param_cookie=param_cookie, + ) + + async def get_same_name_multiple_locations_param_async( + self, + param_path: str, + *, + param_query: Union[Unset, None, str] = UNSET, + param_header: Union[Unset, str] = UNSET, + param_cookie: Union[Unset, str] = UNSET, + ) -> Any: + """ + Args: + param_path (str): + param_query (Union[Unset, None, str]): + param_header (Union[Unset, str]): + param_cookie (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await get_same_name_multiple_locations_param.asyncio( + client=self.__client, + param_path=param_path, + param_query=param_query, + param_header=param_header, + param_cookie=param_cookie, + ) + + def multiple_path_parameters( + self, + param4: str, + param2: int, + param1: str, + param3: int, + ) -> Any: + """ + Args: + param4 (str): + param2 (int): + param1 (str): + param3 (int): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return multiple_path_parameters.sync( + client=self.__client, + param4=param4, + param2=param2, + param1=param1, + param3=param3, + ) + + async def multiple_path_parameters_async( + self, + param4: str, + param2: int, + param1: str, + param3: int, + ) -> Any: + """ + Args: + param4 (str): + param2 (int): + param1 (str): + param3 (int): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await multiple_path_parameters.asyncio( + client=self.__client, + param4=param4, + param2=param2, + param1=param1, + param3=param3, + ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py index 2816ec304..d93d45561 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/delete_common_parameters_overriding_param.py @@ -1,18 +1,19 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, Union import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Union + from ... import errors -from ...client import Client from ...types import UNSET, Response, Unset def _get_kwargs( - param_path: str, - *, - client: Client, - param_query: Union[Unset, None, str] = UNSET, + param_path: str, *, param_query: Union[Unset, None, str] = UNSET, client: "MyTestApiClient" ) -> Dict[str, Any]: url = "{}/common_parameters_overriding/{param}".format(client.base_url, param=param_path) @@ -35,16 +36,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -54,10 +53,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any def sync_detailed( - param_path: str, - *, - client: Client, - param_query: Union[Unset, None, str] = UNSET, + param_path: str, *, param_query: Union[Unset, None, str] = UNSET, client: "MyTestApiClient" ) -> Response[Any]: """ Args: @@ -65,7 +61,7 @@ def sync_detailed( param_query (Union[Unset, None, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -86,11 +82,29 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync(param_path: str, *, param_query: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Any: + """ + Args: + param_path (str): + param_query (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + param_path=param_path, + client=client, + param_query=param_query, + ).parsed + + async def asyncio_detailed( - param_path: str, - *, - client: Client, - param_query: Union[Unset, None, str] = UNSET, + param_path: str, *, param_query: Union[Unset, None, str] = UNSET, client: "MyTestApiClient" ) -> Response[Any]: """ Args: @@ -98,7 +112,7 @@ async def asyncio_detailed( param_query (Union[Unset, None, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -115,3 +129,26 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(param_path: str, *, param_query: Union[Unset, None, str] = UNSET, client: "MyTestApiClient") -> Any: + """ + Args: + param_path (str): + param_query (Union[Unset, None, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + param_path=param_path, + client=client, + param_query=param_query, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py index f1d97abc5..087114634 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_common_parameters_overriding_param.py @@ -1,18 +1,17 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + from ... import errors -from ...client import Client from ...types import UNSET, Response def _get_kwargs( - param_path: str, - *, - client: Client, - param_query: str = "overridden_in_GET", + param_path: str, *, param_query: str = "overridden_in_GET", client: "MyTestApiClient" ) -> Dict[str, Any]: url = "{}/common_parameters_overriding/{param}".format(client.base_url, param=param_path) @@ -35,16 +34,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -54,10 +51,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any def sync_detailed( - param_path: str, - *, - client: Client, - param_query: str = "overridden_in_GET", + param_path: str, *, param_query: str = "overridden_in_GET", client: "MyTestApiClient" ) -> Response[Any]: """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code @@ -67,7 +61,7 @@ def sync_detailed( 'overridden_in_GET'. Example: an example string. Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -88,11 +82,31 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync(param_path: str, *, param_query: str = "overridden_in_GET", client: "MyTestApiClient") -> Any: + """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code + + Args: + param_path (str): + param_query (str): A parameter with the same name as another. Default: + 'overridden_in_GET'. Example: an example string. + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + param_path=param_path, + client=client, + param_query=param_query, + ).parsed + + async def asyncio_detailed( - param_path: str, - *, - client: Client, - param_query: str = "overridden_in_GET", + param_path: str, *, param_query: str = "overridden_in_GET", client: "MyTestApiClient" ) -> Response[Any]: """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code @@ -102,7 +116,7 @@ async def asyncio_detailed( 'overridden_in_GET'. Example: an example string. Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -119,3 +133,28 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(param_path: str, *, param_query: str = "overridden_in_GET", client: "MyTestApiClient") -> Any: + """Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code + + Args: + param_path (str): + param_query (str): A parameter with the same name as another. Default: + 'overridden_in_GET'. Example: an example string. + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + param_path=param_path, + client=client, + param_query=param_query, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py index ee9c35016..220819afe 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/get_same_name_multiple_locations_param.py @@ -1,20 +1,24 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, Union import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Union + from ... import errors -from ...client import Client from ...types import UNSET, Response, Unset def _get_kwargs( param_path: str, *, - client: Client, param_query: Union[Unset, None, str] = UNSET, param_header: Union[Unset, str] = UNSET, param_cookie: Union[Unset, str] = UNSET, + client: "MyTestApiClient", ) -> Dict[str, Any]: url = "{}/same-name-multiple-locations/{param}".format(client.base_url, param=param_path) @@ -43,16 +47,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -64,10 +66,10 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any def sync_detailed( param_path: str, *, - client: Client, param_query: Union[Unset, None, str] = UNSET, param_header: Union[Unset, str] = UNSET, param_cookie: Union[Unset, str] = UNSET, + client: "MyTestApiClient", ) -> Response[Any]: """ Args: @@ -77,7 +79,7 @@ def sync_detailed( param_cookie (Union[Unset, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -100,13 +102,45 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync( + param_path: str, + *, + param_query: Union[Unset, None, str] = UNSET, + param_header: Union[Unset, str] = UNSET, + param_cookie: Union[Unset, str] = UNSET, + client: "MyTestApiClient", +) -> Any: + """ + Args: + param_path (str): + param_query (Union[Unset, None, str]): + param_header (Union[Unset, str]): + param_cookie (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + param_path=param_path, + client=client, + param_query=param_query, + param_header=param_header, + param_cookie=param_cookie, + ).parsed + + async def asyncio_detailed( param_path: str, *, - client: Client, param_query: Union[Unset, None, str] = UNSET, param_header: Union[Unset, str] = UNSET, param_cookie: Union[Unset, str] = UNSET, + client: "MyTestApiClient", ) -> Response[Any]: """ Args: @@ -116,7 +150,7 @@ async def asyncio_detailed( param_cookie (Union[Unset, str]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -135,3 +169,37 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio( + param_path: str, + *, + param_query: Union[Unset, None, str] = UNSET, + param_header: Union[Unset, str] = UNSET, + param_cookie: Union[Unset, str] = UNSET, + client: "MyTestApiClient", +) -> Any: + """ + Args: + param_path (str): + param_query (Union[Unset, None, str]): + param_header (Union[Unset, str]): + param_cookie (Union[Unset, str]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + param_path=param_path, + client=client, + param_query=param_query, + param_header=param_header, + param_cookie=param_cookie, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py index 347aa36b4..bb1f59421 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/parameters/multiple_path_parameters.py @@ -1,21 +1,16 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - param4: str, - param2: int, - param1: str, - param3: int, - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(param4: str, param2: int, param1: str, param3: int, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/multiple-path-parameters/{param4}/something/{param2}/{param1}/{param3}".format( client.base_url, param4=param4, param2=param2, param1=param1, param3=param3 ) @@ -33,16 +28,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -51,14 +44,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - param4: str, - param2: int, - param1: str, - param3: int, - *, - client: Client, -) -> Response[Any]: +def sync_detailed(param4: str, param2: int, param1: str, param3: int, client: "MyTestApiClient") -> Response[Any]: """ Args: param4 (str): @@ -67,7 +53,7 @@ def sync_detailed( param3 (int): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -90,13 +76,33 @@ def sync_detailed( return _build_response(client=client, response=response) +def sync(param4: str, param2: int, param1: str, param3: int, client: "MyTestApiClient") -> Any: + """ + Args: + param4 (str): + param2 (int): + param1 (str): + param3 (int): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + param4=param4, + param2=param2, + param1=param1, + param3=param3, + client=client, + ).parsed + + async def asyncio_detailed( - param4: str, - param2: int, - param1: str, - param3: int, - *, - client: Client, + param4: str, param2: int, param1: str, param3: int, client: "MyTestApiClient" ) -> Response[Any]: """ Args: @@ -106,7 +112,7 @@ async def asyncio_detailed( param3 (int): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -125,3 +131,30 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(param4: str, param2: int, param1: str, param3: int, client: "MyTestApiClient") -> Any: + """ + Args: + param4 (str): + param2 (int): + param1 (str): + param3 (int): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + param4=param4, + param2=param2, + param1=param1, + param3=param3, + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/responses/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/responses/__init__.py index e69de29bb..f128081a4 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/responses/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/responses/__init__.py @@ -0,0 +1,50 @@ +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict, cast + +from ...models.post_responses_unions_simple_before_complex_response_200 import ( + PostResponsesUnionsSimpleBeforeComplexResponse200, +) +from . import post_responses_unions_simple_before_complex + + +class Responses: + def __init__(self, client: "MyTestApiClient"): + self.__client = client + + def post_responses_unions_simple_before_complex( + self, + ) -> PostResponsesUnionsSimpleBeforeComplexResponse200: + """Regression test for #603 + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[PostResponsesUnionsSimpleBeforeComplexResponse200] + """ + + return post_responses_unions_simple_before_complex.sync( + client=self.__client, + ) + + async def post_responses_unions_simple_before_complex_async( + self, + ) -> PostResponsesUnionsSimpleBeforeComplexResponse200: + """Regression test for #603 + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[PostResponsesUnionsSimpleBeforeComplexResponse200] + """ + + return await post_responses_unions_simple_before_complex.asyncio( + client=self.__client, + ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py b/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py index 9e43e738a..52a41d1f6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/responses/post_responses_unions_simple_before_complex.py @@ -1,20 +1,21 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict + from ... import errors -from ...client import Client from ...models.post_responses_unions_simple_before_complex_response_200 import ( PostResponsesUnionsSimpleBeforeComplexResponse200, ) from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/responses/unions/simple_before_complex".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -31,20 +32,17 @@ def _get_kwargs( def _parse_response( - *, client: Client, response: httpx.Response -) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: + *, client: "MyTestApiClient", response: httpx.Response +) -> PostResponsesUnionsSimpleBeforeComplexResponse200: if response.status_code == HTTPStatus.OK: response_200 = PostResponsesUnionsSimpleBeforeComplexResponse200.from_dict(response.json()) return response_200 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content) def _build_response( - *, client: Client, response: httpx.Response + *, client: "MyTestApiClient", response: httpx.Response ) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: return Response( status_code=HTTPStatus(response.status_code), @@ -54,14 +52,11 @@ def _build_response( ) -def sync_detailed( - *, - client: Client, -) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: +def sync_detailed(client: "MyTestApiClient") -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: """Regression test for #603 Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -80,14 +75,11 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, -) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: +def sync(client: "MyTestApiClient") -> PostResponsesUnionsSimpleBeforeComplexResponse200: """Regression test for #603 Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -99,14 +91,11 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, -) -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: +async def asyncio_detailed(client: "MyTestApiClient") -> Response[PostResponsesUnionsSimpleBeforeComplexResponse200]: """Regression test for #603 Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -123,14 +112,11 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, -) -> Optional[PostResponsesUnionsSimpleBeforeComplexResponse200]: +async def asyncio(client: "MyTestApiClient") -> PostResponsesUnionsSimpleBeforeComplexResponse200: """Regression test for #603 Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/__init__.py index e69de29bb..ae4d649d2 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/__init__.py @@ -0,0 +1,43 @@ +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from . import get_tag_with_number + + +class Tag1: + def __init__(self, client: "MyTestApiClient"): + self.__client = client + + def get_tag_with_number( + self, + ) -> Any: + """ + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return get_tag_with_number.sync( + client=self.__client, + ) + + async def get_tag_with_number_async( + self, + ) -> Any: + """ + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await get_tag_with_number.asyncio( + client=self.__client, + ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py index 05f976082..a1106d25c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tag1/get_tag_with_number.py @@ -1,17 +1,16 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tag_with_number".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -27,16 +26,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -45,13 +42,10 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, -) -> Response[Any]: +def sync_detailed(client: "MyTestApiClient") -> Response[Any]: """ Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -70,13 +64,25 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, -) -> Response[Any]: +def sync(client: "MyTestApiClient") -> Any: + """ + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed(client: "MyTestApiClient") -> Response[Any]: """ Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -91,3 +97,20 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(client: "MyTestApiClient") -> Any: + """ + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/__init__.py index e69de29bb..6645eb06a 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/__init__.py @@ -0,0 +1,992 @@ +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from ...client import MyTestApiClient + +import datetime +from io import BytesIO +from typing import Dict, List, Optional, Union, cast + +from dateutil.parser import isoparse + +from ...models.a_form_data import AFormData +from ...models.a_model import AModel +from ...models.an_enum import AnEnum +from ...models.an_enum_with_null import AnEnumWithNull +from ...models.an_int_enum import AnIntEnum +from ...models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost +from ...models.http_validation_error import HTTPValidationError +from ...models.model_with_union_property import ModelWithUnionProperty +from ...models.post_form_data_inline_data import PostFormDataInlineData +from ...models.test_inline_objects_json_body import TestInlineObjectsJsonBody +from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse200 +from ...types import UNSET, File, FileJsonType, Unset +from . import ( + callback_test, + defaults_tests_defaults_post, + description_with_backslash, + get_basic_list_of_booleans, + get_basic_list_of_floats, + get_basic_list_of_integers, + get_basic_list_of_strings, + get_user_list, + int_enum_tests_int_enum_post, + json_body_tests_json_body_post, + no_response_tests_no_response_get, + octet_stream_tests_octet_stream_get, + post_form_data, + post_form_data_inline, + post_tests_json_body_string, + test_inline_objects, + token_with_cookie_auth_token_with_cookie_get, + unsupported_content_tests_unsupported_content_get, + upload_file_tests_upload_post, + upload_multiple_files_tests_upload_post, +) + + +class Tests: + def __init__(self, client: "MyTestApiClient"): + self.__client = client + + def get_user_list( + self, + *, + an_enum_value: List[AnEnum], + an_enum_value_with_null: List[Optional[AnEnumWithNull]], + an_enum_value_with_only_null: List[None], + some_date: Union[datetime.date, datetime.datetime], + ) -> List["AModel"]: + """Get List + + Get a list of things + + Args: + an_enum_value (List[AnEnum]): + an_enum_value_with_null (List[Optional[AnEnumWithNull]]): + an_enum_value_with_only_null (List[None]): + some_date (Union[datetime.date, datetime.datetime]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List['AModel']] + """ + + return get_user_list.sync( + client=self.__client, + an_enum_value=an_enum_value, + an_enum_value_with_null=an_enum_value_with_null, + an_enum_value_with_only_null=an_enum_value_with_only_null, + some_date=some_date, + ) + + async def get_user_list_async( + self, + *, + an_enum_value: List[AnEnum], + an_enum_value_with_null: List[Optional[AnEnumWithNull]], + an_enum_value_with_only_null: List[None], + some_date: Union[datetime.date, datetime.datetime], + ) -> List["AModel"]: + """Get List + + Get a list of things + + Args: + an_enum_value (List[AnEnum]): + an_enum_value_with_null (List[Optional[AnEnumWithNull]]): + an_enum_value_with_only_null (List[None]): + some_date (Union[datetime.date, datetime.datetime]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List['AModel']] + """ + + return await get_user_list.asyncio( + client=self.__client, + an_enum_value=an_enum_value, + an_enum_value_with_null=an_enum_value_with_null, + an_enum_value_with_only_null=an_enum_value_with_only_null, + some_date=some_date, + ) + + def get_basic_list_of_strings( + self, + ) -> List[str]: + """Get Basic List Of Strings + + Get a list of strings + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List[str]] + """ + + return get_basic_list_of_strings.sync( + client=self.__client, + ) + + async def get_basic_list_of_strings_async( + self, + ) -> List[str]: + """Get Basic List Of Strings + + Get a list of strings + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List[str]] + """ + + return await get_basic_list_of_strings.asyncio( + client=self.__client, + ) + + def get_basic_list_of_integers( + self, + ) -> List[int]: + """Get Basic List Of Integers + + Get a list of integers + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List[int]] + """ + + return get_basic_list_of_integers.sync( + client=self.__client, + ) + + async def get_basic_list_of_integers_async( + self, + ) -> List[int]: + """Get Basic List Of Integers + + Get a list of integers + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List[int]] + """ + + return await get_basic_list_of_integers.asyncio( + client=self.__client, + ) + + def get_basic_list_of_floats( + self, + ) -> List[float]: + """Get Basic List Of Floats + + Get a list of floats + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List[float]] + """ + + return get_basic_list_of_floats.sync( + client=self.__client, + ) + + async def get_basic_list_of_floats_async( + self, + ) -> List[float]: + """Get Basic List Of Floats + + Get a list of floats + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List[float]] + """ + + return await get_basic_list_of_floats.asyncio( + client=self.__client, + ) + + def get_basic_list_of_booleans( + self, + ) -> List[bool]: + """Get Basic List Of Booleans + + Get a list of booleans + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List[bool]] + """ + + return get_basic_list_of_booleans.sync( + client=self.__client, + ) + + async def get_basic_list_of_booleans_async( + self, + ) -> List[bool]: + """Get Basic List Of Booleans + + Get a list of booleans + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[List[bool]] + """ + + return await get_basic_list_of_booleans.asyncio( + client=self.__client, + ) + + def post_form_data( + self, + *, + form_data: AFormData, + ) -> Any: + """Post form data + + Post form data + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return post_form_data.sync( + client=self.__client, + form_data=form_data, + ) + + async def post_form_data_async( + self, + *, + form_data: AFormData, + ) -> Any: + """Post form data + + Post form data + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await post_form_data.asyncio( + client=self.__client, + form_data=form_data, + ) + + def post_form_data_inline( + self, + *, + form_data: PostFormDataInlineData, + ) -> Any: + """Post form data (inline schema) + + Post form data (inline schema) + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return post_form_data_inline.sync( + client=self.__client, + form_data=form_data, + ) + + async def post_form_data_inline_async( + self, + *, + form_data: PostFormDataInlineData, + ) -> Any: + """Post form data (inline schema) + + Post form data (inline schema) + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await post_form_data_inline.asyncio( + client=self.__client, + form_data=form_data, + ) + + def upload_file_tests_upload_post( + self, + *, + multipart_data: BodyUploadFileTestsUploadPost, + ) -> Any: + """Upload File + + Upload a file + + Args: + multipart_data (BodyUploadFileTestsUploadPost): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return upload_file_tests_upload_post.sync( + client=self.__client, + multipart_data=multipart_data, + ) + + async def upload_file_tests_upload_post_async( + self, + *, + multipart_data: BodyUploadFileTestsUploadPost, + ) -> Any: + """Upload File + + Upload a file + + Args: + multipart_data (BodyUploadFileTestsUploadPost): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await upload_file_tests_upload_post.asyncio( + client=self.__client, + multipart_data=multipart_data, + ) + + def upload_multiple_files_tests_upload_post( + self, + *, + multipart_data: List[File], + ) -> Any: + """Upload multiple files + + Upload several files in the same request + + Args: + multipart_data (List[File]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return upload_multiple_files_tests_upload_post.sync( + client=self.__client, + multipart_data=multipart_data, + ) + + async def upload_multiple_files_tests_upload_post_async( + self, + *, + multipart_data: List[File], + ) -> Any: + """Upload multiple files + + Upload several files in the same request + + Args: + multipart_data (List[File]): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await upload_multiple_files_tests_upload_post.asyncio( + client=self.__client, + multipart_data=multipart_data, + ) + + def json_body_tests_json_body_post( + self, + *, + json_body: AModel, + ) -> Any: + """Json Body + + Try sending a JSON body + + Args: + json_body (AModel): A Model for testing all the ways custom objects can be used + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return json_body_tests_json_body_post.sync( + client=self.__client, + json_body=json_body, + ) + + async def json_body_tests_json_body_post_async( + self, + *, + json_body: AModel, + ) -> Any: + """Json Body + + Try sending a JSON body + + Args: + json_body (AModel): A Model for testing all the ways custom objects can be used + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await json_body_tests_json_body_post.asyncio( + client=self.__client, + json_body=json_body, + ) + + def post_tests_json_body_string( + self, + *, + json_body: str, + ) -> str: + """Json Body Which is String + + Args: + json_body (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + return post_tests_json_body_string.sync( + client=self.__client, + json_body=json_body, + ) + + async def post_tests_json_body_string_async( + self, + *, + json_body: str, + ) -> str: + """Json Body Which is String + + Args: + json_body (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[str] + """ + + return await post_tests_json_body_string.asyncio( + client=self.__client, + json_body=json_body, + ) + + def defaults_tests_defaults_post( + self, + *, + string_prop: str = "the default string", + date_prop: datetime.date = isoparse("1010-10-10").date(), + float_prop: float = 3.14, + int_prop: int = 7, + boolean_prop: bool = False, + list_prop: List[AnEnum], + union_prop: Union[float, str] = "not a float", + union_prop_with_ref: Union[AnEnum, None, Unset, float] = 0.6, + enum_prop: AnEnum, + model_prop: "ModelWithUnionProperty", + required_model_prop: "ModelWithUnionProperty", + ) -> Any: + """Defaults + + Args: + string_prop (str): Default: 'the default string'. + date_prop (datetime.date): Default: isoparse('1010-10-10').date(). + float_prop (float): Default: 3.14. + int_prop (int): Default: 7. + boolean_prop (bool): + list_prop (List[AnEnum]): + union_prop (Union[float, str]): Default: 'not a float'. + union_prop_with_ref (Union[AnEnum, None, Unset, float]): Default: 0.6. + enum_prop (AnEnum): For testing Enums in all the ways they can be used + model_prop (ModelWithUnionProperty): + required_model_prop (ModelWithUnionProperty): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return defaults_tests_defaults_post.sync( + client=self.__client, + string_prop=string_prop, + date_prop=date_prop, + float_prop=float_prop, + int_prop=int_prop, + boolean_prop=boolean_prop, + list_prop=list_prop, + union_prop=union_prop, + union_prop_with_ref=union_prop_with_ref, + enum_prop=enum_prop, + model_prop=model_prop, + required_model_prop=required_model_prop, + ) + + async def defaults_tests_defaults_post_async( + self, + *, + string_prop: str = "the default string", + date_prop: datetime.date = isoparse("1010-10-10").date(), + float_prop: float = 3.14, + int_prop: int = 7, + boolean_prop: bool = False, + list_prop: List[AnEnum], + union_prop: Union[float, str] = "not a float", + union_prop_with_ref: Union[AnEnum, None, Unset, float] = 0.6, + enum_prop: AnEnum, + model_prop: "ModelWithUnionProperty", + required_model_prop: "ModelWithUnionProperty", + ) -> Any: + """Defaults + + Args: + string_prop (str): Default: 'the default string'. + date_prop (datetime.date): Default: isoparse('1010-10-10').date(). + float_prop (float): Default: 3.14. + int_prop (int): Default: 7. + boolean_prop (bool): + list_prop (List[AnEnum]): + union_prop (Union[float, str]): Default: 'not a float'. + union_prop_with_ref (Union[AnEnum, None, Unset, float]): Default: 0.6. + enum_prop (AnEnum): For testing Enums in all the ways they can be used + model_prop (ModelWithUnionProperty): + required_model_prop (ModelWithUnionProperty): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await defaults_tests_defaults_post.asyncio( + client=self.__client, + string_prop=string_prop, + date_prop=date_prop, + float_prop=float_prop, + int_prop=int_prop, + boolean_prop=boolean_prop, + list_prop=list_prop, + union_prop=union_prop, + union_prop_with_ref=union_prop_with_ref, + enum_prop=enum_prop, + model_prop=model_prop, + required_model_prop=required_model_prop, + ) + + def octet_stream_tests_octet_stream_get( + self, + ) -> File: + """Octet Stream + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[File] + """ + + return octet_stream_tests_octet_stream_get.sync( + client=self.__client, + ) + + async def octet_stream_tests_octet_stream_get_async( + self, + ) -> File: + """Octet Stream + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[File] + """ + + return await octet_stream_tests_octet_stream_get.asyncio( + client=self.__client, + ) + + def no_response_tests_no_response_get( + self, + ) -> Any: + """No Response + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return no_response_tests_no_response_get.sync( + client=self.__client, + ) + + async def no_response_tests_no_response_get_async( + self, + ) -> Any: + """No Response + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await no_response_tests_no_response_get.asyncio( + client=self.__client, + ) + + def unsupported_content_tests_unsupported_content_get( + self, + ) -> Any: + """Unsupported Content + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return unsupported_content_tests_unsupported_content_get.sync( + client=self.__client, + ) + + async def unsupported_content_tests_unsupported_content_get_async( + self, + ) -> Any: + """Unsupported Content + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await unsupported_content_tests_unsupported_content_get.asyncio( + client=self.__client, + ) + + def int_enum_tests_int_enum_post( + self, + *, + int_enum: AnIntEnum, + ) -> Any: + """Int Enum + + Args: + int_enum (AnIntEnum): An enumeration. + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return int_enum_tests_int_enum_post.sync( + client=self.__client, + int_enum=int_enum, + ) + + async def int_enum_tests_int_enum_post_async( + self, + *, + int_enum: AnIntEnum, + ) -> Any: + """Int Enum + + Args: + int_enum (AnIntEnum): An enumeration. + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await int_enum_tests_int_enum_post.asyncio( + client=self.__client, + int_enum=int_enum, + ) + + def test_inline_objects( + self, + *, + json_body: TestInlineObjectsJsonBody, + ) -> TestInlineObjectsResponse200: + """Test Inline Objects + + Args: + json_body (TestInlineObjectsJsonBody): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[TestInlineObjectsResponse200] + """ + + return test_inline_objects.sync( + client=self.__client, + json_body=json_body, + ) + + async def test_inline_objects_async( + self, + *, + json_body: TestInlineObjectsJsonBody, + ) -> TestInlineObjectsResponse200: + """Test Inline Objects + + Args: + json_body (TestInlineObjectsJsonBody): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[TestInlineObjectsResponse200] + """ + + return await test_inline_objects.asyncio( + client=self.__client, + json_body=json_body, + ) + + def token_with_cookie_auth_token_with_cookie_get( + self, + *, + my_token: str, + ) -> Any: + """TOKEN_WITH_COOKIE + + Test optional cookie parameters + + Args: + my_token (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return token_with_cookie_auth_token_with_cookie_get.sync( + client=self.__client, + my_token=my_token, + ) + + async def token_with_cookie_auth_token_with_cookie_get_async( + self, + *, + my_token: str, + ) -> Any: + """TOKEN_WITH_COOKIE + + Test optional cookie parameters + + Args: + my_token (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await token_with_cookie_auth_token_with_cookie_get.asyncio( + client=self.__client, + my_token=my_token, + ) + + def callback_test( + self, + *, + json_body: AModel, + ) -> Any: + """Path with callback + + Try sending a request related to a callback + + Args: + json_body (AModel): A Model for testing all the ways custom objects can be used + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return callback_test.sync( + client=self.__client, + json_body=json_body, + ) + + async def callback_test_async( + self, + *, + json_body: AModel, + ) -> Any: + """Path with callback + + Try sending a request related to a callback + + Args: + json_body (AModel): A Model for testing all the ways custom objects can be used + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await callback_test.asyncio( + client=self.__client, + json_body=json_body, + ) + + def description_with_backslash( + self, + ) -> Any: + r""" Test description with \ + + Test description with \ + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return description_with_backslash.sync( + client=self.__client, + ) + + async def description_with_backslash_async( + self, + ) -> Any: + r""" Test description with \ + + Test description with \ + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await description_with_backslash.asyncio( + client=self.__client, + ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py index c68e64be7..30c13dfa3 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/callback_test.py @@ -1,20 +1,20 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict, cast + from ... import errors -from ...client import Client from ...models.a_model import AModel from ...models.http_validation_error import HTTPValidationError from ...types import Response -def _get_kwargs( - *, - client: Client, - json_body: AModel, -) -> Dict[str, Any]: +def _get_kwargs(*, json_body: AModel, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/callback".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -33,21 +33,18 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) - return response_422 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content, response_422) + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -56,11 +53,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni ) -def sync_detailed( - *, - client: Client, - json_body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +def sync_detailed(*, json_body: AModel, client: "MyTestApiClient") -> Response[Any]: """Path with callback Try sending a request related to a callback @@ -69,11 +62,11 @@ def sync_detailed( json_body (AModel): A Model for testing all the ways custom objects can be used Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -89,11 +82,7 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, - json_body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +def sync(*, json_body: AModel, client: "MyTestApiClient") -> Any: """Path with callback Try sending a request related to a callback @@ -102,11 +91,11 @@ def sync( json_body (AModel): A Model for testing all the ways custom objects can be used Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return sync_detailed( @@ -115,11 +104,7 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, - json_body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +async def asyncio_detailed(*, json_body: AModel, client: "MyTestApiClient") -> Response[Any]: """Path with callback Try sending a request related to a callback @@ -128,11 +113,11 @@ async def asyncio_detailed( json_body (AModel): A Model for testing all the ways custom objects can be used Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -146,11 +131,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, - json_body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +async def asyncio(*, json_body: AModel, client: "MyTestApiClient") -> Any: """Path with callback Try sending a request related to a callback @@ -159,11 +140,11 @@ async def asyncio( json_body (AModel): A Model for testing all the ways custom objects can be used Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py index 1e1e4beb1..e8f8c37d2 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py @@ -1,12 +1,17 @@ -import datetime from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import TYPE_CHECKING, Any, Dict, List, Union, cast import httpx + +if TYPE_CHECKING: + from ...client import MyTestApiClient + +import datetime +from typing import Dict, List, Union, cast + from dateutil.parser import isoparse from ... import errors -from ...client import Client from ...models.an_enum import AnEnum from ...models.http_validation_error import HTTPValidationError from ...models.model_with_union_property import ModelWithUnionProperty @@ -15,7 +20,6 @@ def _get_kwargs( *, - client: Client, string_prop: str = "the default string", date_prop: datetime.date = isoparse("1010-10-10").date(), float_prop: float = 3.14, @@ -27,6 +31,7 @@ def _get_kwargs( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", + client: "MyTestApiClient", ) -> Dict[str, Any]: url = "{}/tests/defaults".format(client.base_url) @@ -100,21 +105,18 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) - return response_422 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content, response_422) + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -125,7 +127,6 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni def sync_detailed( *, - client: Client, string_prop: str = "the default string", date_prop: datetime.date = isoparse("1010-10-10").date(), float_prop: float = 3.14, @@ -137,7 +138,8 @@ def sync_detailed( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Response[Union[Any, HTTPValidationError]]: + client: "MyTestApiClient", +) -> Response[Any]: """Defaults Args: @@ -154,11 +156,11 @@ def sync_detailed( required_model_prop (ModelWithUnionProperty): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -186,7 +188,6 @@ def sync_detailed( def sync( *, - client: Client, string_prop: str = "the default string", date_prop: datetime.date = isoparse("1010-10-10").date(), float_prop: float = 3.14, @@ -198,7 +199,8 @@ def sync( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Optional[Union[Any, HTTPValidationError]]: + client: "MyTestApiClient", +) -> Any: """Defaults Args: @@ -215,11 +217,11 @@ def sync( required_model_prop (ModelWithUnionProperty): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return sync_detailed( @@ -240,7 +242,6 @@ def sync( async def asyncio_detailed( *, - client: Client, string_prop: str = "the default string", date_prop: datetime.date = isoparse("1010-10-10").date(), float_prop: float = 3.14, @@ -252,7 +253,8 @@ async def asyncio_detailed( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Response[Union[Any, HTTPValidationError]]: + client: "MyTestApiClient", +) -> Response[Any]: """Defaults Args: @@ -269,11 +271,11 @@ async def asyncio_detailed( required_model_prop (ModelWithUnionProperty): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -299,7 +301,6 @@ async def asyncio_detailed( async def asyncio( *, - client: Client, string_prop: str = "the default string", date_prop: datetime.date = isoparse("1010-10-10").date(), float_prop: float = 3.14, @@ -311,7 +312,8 @@ async def asyncio( enum_prop: AnEnum, model_prop: "ModelWithUnionProperty", required_model_prop: "ModelWithUnionProperty", -) -> Optional[Union[Any, HTTPValidationError]]: + client: "MyTestApiClient", +) -> Any: """Defaults Args: @@ -328,11 +330,11 @@ async def asyncio( required_model_prop (ModelWithUnionProperty): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py index 31923ad11..b11d9e940 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/description_with_backslash.py @@ -1,17 +1,16 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/description-with-backslash".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -27,16 +26,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -45,16 +42,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, -) -> Response[Any]: +def sync_detailed(client: "MyTestApiClient") -> Response[Any]: r""" Test description with \ Test description with \ Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -73,16 +67,31 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, -) -> Response[Any]: +def sync(client: "MyTestApiClient") -> Any: + r""" Test description with \ + + Test description with \ + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed(client: "MyTestApiClient") -> Response[Any]: r""" Test description with \ Test description with \ Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -97,3 +106,23 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(client: "MyTestApiClient") -> Any: + r""" Test description with \ + + Test description with \ + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py index f36aa9a9a..37e1f9bd2 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_booleans.py @@ -1,17 +1,18 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, cast +from typing import TYPE_CHECKING, Any, Dict, List, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import List, cast + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/basic_lists/booleans".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -27,18 +28,15 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[List[bool]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> List[bool]: if response.status_code == HTTPStatus.OK: response_200 = cast(List[bool], response.json()) return response_200 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[List[bool]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[List[bool]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -47,16 +45,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Lis ) -def sync_detailed( - *, - client: Client, -) -> Response[List[bool]]: +def sync_detailed(client: "MyTestApiClient") -> Response[List[bool]]: """Get Basic List Of Booleans Get a list of booleans Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -75,16 +70,13 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, -) -> Optional[List[bool]]: +def sync(client: "MyTestApiClient") -> List[bool]: """Get Basic List Of Booleans Get a list of booleans Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -96,16 +88,13 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, -) -> Response[List[bool]]: +async def asyncio_detailed(client: "MyTestApiClient") -> Response[List[bool]]: """Get Basic List Of Booleans Get a list of booleans Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -122,16 +111,13 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, -) -> Optional[List[bool]]: +async def asyncio(client: "MyTestApiClient") -> List[bool]: """Get Basic List Of Booleans Get a list of booleans Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py index cfc9fec4d..667c23285 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_floats.py @@ -1,17 +1,18 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, cast +from typing import TYPE_CHECKING, Any, Dict, List, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import List, cast + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/basic_lists/floats".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -27,18 +28,15 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[List[float]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> List[float]: if response.status_code == HTTPStatus.OK: response_200 = cast(List[float], response.json()) return response_200 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[List[float]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[List[float]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -47,16 +45,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Lis ) -def sync_detailed( - *, - client: Client, -) -> Response[List[float]]: +def sync_detailed(client: "MyTestApiClient") -> Response[List[float]]: """Get Basic List Of Floats Get a list of floats Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -75,16 +70,13 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, -) -> Optional[List[float]]: +def sync(client: "MyTestApiClient") -> List[float]: """Get Basic List Of Floats Get a list of floats Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -96,16 +88,13 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, -) -> Response[List[float]]: +async def asyncio_detailed(client: "MyTestApiClient") -> Response[List[float]]: """Get Basic List Of Floats Get a list of floats Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -122,16 +111,13 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, -) -> Optional[List[float]]: +async def asyncio(client: "MyTestApiClient") -> List[float]: """Get Basic List Of Floats Get a list of floats Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py index ab31821b5..40774c965 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_integers.py @@ -1,17 +1,18 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, cast +from typing import TYPE_CHECKING, Any, Dict, List, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import List, cast + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/basic_lists/integers".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -27,18 +28,15 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[List[int]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> List[int]: if response.status_code == HTTPStatus.OK: response_200 = cast(List[int], response.json()) return response_200 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[List[int]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[List[int]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -47,16 +45,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Lis ) -def sync_detailed( - *, - client: Client, -) -> Response[List[int]]: +def sync_detailed(client: "MyTestApiClient") -> Response[List[int]]: """Get Basic List Of Integers Get a list of integers Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -75,16 +70,13 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, -) -> Optional[List[int]]: +def sync(client: "MyTestApiClient") -> List[int]: """Get Basic List Of Integers Get a list of integers Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -96,16 +88,13 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, -) -> Response[List[int]]: +async def asyncio_detailed(client: "MyTestApiClient") -> Response[List[int]]: """Get Basic List Of Integers Get a list of integers Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -122,16 +111,13 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, -) -> Optional[List[int]]: +async def asyncio(client: "MyTestApiClient") -> List[int]: """Get Basic List Of Integers Get a list of integers Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py index 4c62d518b..2150b5271 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_basic_list_of_strings.py @@ -1,17 +1,18 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, cast +from typing import TYPE_CHECKING, Any, Dict, List, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import List, cast + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/basic_lists/strings".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -27,18 +28,15 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[List[str]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> List[str]: if response.status_code == HTTPStatus.OK: response_200 = cast(List[str], response.json()) return response_200 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[List[str]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[List[str]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -47,16 +45,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Lis ) -def sync_detailed( - *, - client: Client, -) -> Response[List[str]]: +def sync_detailed(client: "MyTestApiClient") -> Response[List[str]]: """Get Basic List Of Strings Get a list of strings Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -75,16 +70,13 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, -) -> Optional[List[str]]: +def sync(client: "MyTestApiClient") -> List[str]: """Get Basic List Of Strings Get a list of strings Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -96,16 +88,13 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, -) -> Response[List[str]]: +async def asyncio_detailed(client: "MyTestApiClient") -> Response[List[str]]: """Get Basic List Of Strings Get a list of strings Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -122,16 +111,13 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, -) -> Optional[List[str]]: +async def asyncio(client: "MyTestApiClient") -> List[str]: """Get Basic List Of Strings Get a list of strings Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py index cf0c1c375..57a3064d6 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/get_user_list.py @@ -1,11 +1,15 @@ -import datetime from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union +from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +import datetime +from typing import Dict, List, Optional, Union + from ... import errors -from ...client import Client from ...models.a_model import AModel from ...models.an_enum import AnEnum from ...models.an_enum_with_null import AnEnumWithNull @@ -15,11 +19,11 @@ def _get_kwargs( *, - client: Client, an_enum_value: List[AnEnum], an_enum_value_with_null: List[Optional[AnEnumWithNull]], an_enum_value_with_only_null: List[None], some_date: Union[datetime.date, datetime.datetime], + client: "MyTestApiClient", ) -> Dict[str, Any]: url = "{}/tests/".format(client.base_url) @@ -71,9 +75,7 @@ def _get_kwargs( } -def _parse_response( - *, client: Client, response: httpx.Response -) -> Optional[Union[HTTPValidationError, List["AModel"]]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> List["AModel"]: if response.status_code == HTTPStatus.OK: response_200 = [] _response_200 = response.json() @@ -86,20 +88,15 @@ def _parse_response( if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) - return response_422 + raise errors.UnexpectedStatus(response.status_code, response.content, response_422) if response.status_code == HTTPStatus.LOCKED: response_423 = HTTPValidationError.from_dict(response.json()) - return response_423 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content, response_423) + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response( - *, client: Client, response: httpx.Response -) -> Response[Union[HTTPValidationError, List["AModel"]]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[List["AModel"]]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -110,12 +107,12 @@ def _build_response( def sync_detailed( *, - client: Client, an_enum_value: List[AnEnum], an_enum_value_with_null: List[Optional[AnEnumWithNull]], an_enum_value_with_only_null: List[None], some_date: Union[datetime.date, datetime.datetime], -) -> Response[Union[HTTPValidationError, List["AModel"]]]: + client: "MyTestApiClient", +) -> Response[List["AModel"]]: """Get List Get a list of things @@ -127,11 +124,11 @@ def sync_detailed( some_date (Union[datetime.date, datetime.datetime]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, List['AModel']]] + Response[List['AModel']] """ kwargs = _get_kwargs( @@ -152,12 +149,12 @@ def sync_detailed( def sync( *, - client: Client, an_enum_value: List[AnEnum], an_enum_value_with_null: List[Optional[AnEnumWithNull]], an_enum_value_with_only_null: List[None], some_date: Union[datetime.date, datetime.datetime], -) -> Optional[Union[HTTPValidationError, List["AModel"]]]: + client: "MyTestApiClient", +) -> List["AModel"]: """Get List Get a list of things @@ -169,11 +166,11 @@ def sync( some_date (Union[datetime.date, datetime.datetime]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, List['AModel']]] + Response[List['AModel']] """ return sync_detailed( @@ -187,12 +184,12 @@ def sync( async def asyncio_detailed( *, - client: Client, an_enum_value: List[AnEnum], an_enum_value_with_null: List[Optional[AnEnumWithNull]], an_enum_value_with_only_null: List[None], some_date: Union[datetime.date, datetime.datetime], -) -> Response[Union[HTTPValidationError, List["AModel"]]]: + client: "MyTestApiClient", +) -> Response[List["AModel"]]: """Get List Get a list of things @@ -204,11 +201,11 @@ async def asyncio_detailed( some_date (Union[datetime.date, datetime.datetime]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, List['AModel']]] + Response[List['AModel']] """ kwargs = _get_kwargs( @@ -227,12 +224,12 @@ async def asyncio_detailed( async def asyncio( *, - client: Client, an_enum_value: List[AnEnum], an_enum_value_with_null: List[Optional[AnEnumWithNull]], an_enum_value_with_only_null: List[None], some_date: Union[datetime.date, datetime.datetime], -) -> Optional[Union[HTTPValidationError, List["AModel"]]]: + client: "MyTestApiClient", +) -> List["AModel"]: """Get List Get a list of things @@ -244,11 +241,11 @@ async def asyncio( some_date (Union[datetime.date, datetime.datetime]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, List['AModel']]] + Response[List['AModel']] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py index d6777f84c..368dcbcfd 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/int_enum_tests_int_enum_post.py @@ -1,20 +1,20 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict, cast + from ... import errors -from ...client import Client from ...models.an_int_enum import AnIntEnum from ...models.http_validation_error import HTTPValidationError from ...types import UNSET, Response -def _get_kwargs( - *, - client: Client, - int_enum: AnIntEnum, -) -> Dict[str, Any]: +def _get_kwargs(*, int_enum: AnIntEnum, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/int_enum".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -38,21 +38,18 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) - return response_422 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content, response_422) + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -61,22 +58,18 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni ) -def sync_detailed( - *, - client: Client, - int_enum: AnIntEnum, -) -> Response[Union[Any, HTTPValidationError]]: +def sync_detailed(*, int_enum: AnIntEnum, client: "MyTestApiClient") -> Response[Any]: """Int Enum Args: int_enum (AnIntEnum): An enumeration. Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -92,22 +85,18 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, - int_enum: AnIntEnum, -) -> Optional[Union[Any, HTTPValidationError]]: +def sync(*, int_enum: AnIntEnum, client: "MyTestApiClient") -> Any: """Int Enum Args: int_enum (AnIntEnum): An enumeration. Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return sync_detailed( @@ -116,22 +105,18 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, - int_enum: AnIntEnum, -) -> Response[Union[Any, HTTPValidationError]]: +async def asyncio_detailed(*, int_enum: AnIntEnum, client: "MyTestApiClient") -> Response[Any]: """Int Enum Args: int_enum (AnIntEnum): An enumeration. Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -145,22 +130,18 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, - int_enum: AnIntEnum, -) -> Optional[Union[Any, HTTPValidationError]]: +async def asyncio(*, int_enum: AnIntEnum, client: "MyTestApiClient") -> Any: """Int Enum Args: int_enum (AnIntEnum): An enumeration. Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py index d977511d4..1b0d6565b 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/json_body_tests_json_body_post.py @@ -1,20 +1,20 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict, cast + from ... import errors -from ...client import Client from ...models.a_model import AModel from ...models.http_validation_error import HTTPValidationError from ...types import Response -def _get_kwargs( - *, - client: Client, - json_body: AModel, -) -> Dict[str, Any]: +def _get_kwargs(*, json_body: AModel, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/json_body".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -33,21 +33,18 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) - return response_422 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content, response_422) + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -56,11 +53,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni ) -def sync_detailed( - *, - client: Client, - json_body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +def sync_detailed(*, json_body: AModel, client: "MyTestApiClient") -> Response[Any]: """Json Body Try sending a JSON body @@ -69,11 +62,11 @@ def sync_detailed( json_body (AModel): A Model for testing all the ways custom objects can be used Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -89,11 +82,7 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, - json_body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +def sync(*, json_body: AModel, client: "MyTestApiClient") -> Any: """Json Body Try sending a JSON body @@ -102,11 +91,11 @@ def sync( json_body (AModel): A Model for testing all the ways custom objects can be used Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return sync_detailed( @@ -115,11 +104,7 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, - json_body: AModel, -) -> Response[Union[Any, HTTPValidationError]]: +async def asyncio_detailed(*, json_body: AModel, client: "MyTestApiClient") -> Response[Any]: """Json Body Try sending a JSON body @@ -128,11 +113,11 @@ async def asyncio_detailed( json_body (AModel): A Model for testing all the ways custom objects can be used Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -146,11 +131,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, - json_body: AModel, -) -> Optional[Union[Any, HTTPValidationError]]: +async def asyncio(*, json_body: AModel, client: "MyTestApiClient") -> Any: """Json Body Try sending a JSON body @@ -159,11 +140,11 @@ async def asyncio( json_body (AModel): A Model for testing all the ways custom objects can be used Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py index 075452512..b69098c75 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/no_response_tests_no_response_get.py @@ -1,17 +1,16 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/no_response".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -27,16 +26,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = cast(Any, response.json()) + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -45,14 +42,11 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, -) -> Response[Any]: +def sync_detailed(client: "MyTestApiClient") -> Response[Any]: """No Response Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -71,14 +65,27 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, -) -> Response[Any]: +def sync(client: "MyTestApiClient") -> Any: + """No Response + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed(client: "MyTestApiClient") -> Response[Any]: """No Response Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -93,3 +100,21 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(client: "MyTestApiClient") -> Any: + """No Response + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py index a10ad95a7..1f12fbc71 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/octet_stream_tests_octet_stream_get.py @@ -1,18 +1,18 @@ from http import HTTPStatus -from io import BytesIO -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from io import BytesIO + from ... import errors -from ...client import Client from ...types import File, Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/octet_stream".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -28,18 +28,15 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[File]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> File: if response.status_code == HTTPStatus.OK: response_200 = File(payload=BytesIO(response.content)) return response_200 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[File]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[File]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -48,14 +45,11 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Fil ) -def sync_detailed( - *, - client: Client, -) -> Response[File]: +def sync_detailed(client: "MyTestApiClient") -> Response[File]: """Octet Stream Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -74,14 +68,11 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, -) -> Optional[File]: +def sync(client: "MyTestApiClient") -> File: """Octet Stream Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -93,14 +84,11 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, -) -> Response[File]: +async def asyncio_detailed(client: "MyTestApiClient") -> Response[File]: """Octet Stream Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -117,14 +105,11 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, -) -> Optional[File]: +async def asyncio(client: "MyTestApiClient") -> File: """Octet Stream Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py index 07c0b225e..dc4dbeb4f 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data.py @@ -1,19 +1,19 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict, cast + from ... import errors -from ...client import Client from ...models.a_form_data import AFormData from ...types import Response -def _get_kwargs( - *, - client: Client, - form_data: AFormData, -) -> Dict[str, Any]: +def _get_kwargs(*, form_data: AFormData, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/post_form_data".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -30,16 +30,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = cast(Any, response.json()) + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -48,17 +46,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, - form_data: AFormData, -) -> Response[Any]: +def sync_detailed(*, form_data: AFormData, client: "MyTestApiClient") -> Response[Any]: """Post form data Post form data Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -78,17 +72,32 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, - form_data: AFormData, -) -> Response[Any]: +def sync(*, form_data: AFormData, client: "MyTestApiClient") -> Any: + """Post form data + + Post form data + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + form_data=form_data, + ).parsed + + +async def asyncio_detailed(*, form_data: AFormData, client: "MyTestApiClient") -> Response[Any]: """Post form data Post form data Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -104,3 +113,24 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(*, form_data: AFormData, client: "MyTestApiClient") -> Any: + """Post form data + + Post form data + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + form_data=form_data, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py index e93a22986..6e35fece0 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_form_data_inline.py @@ -1,19 +1,19 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict, cast + from ... import errors -from ...client import Client from ...models.post_form_data_inline_data import PostFormDataInlineData from ...types import Response -def _get_kwargs( - *, - client: Client, - form_data: PostFormDataInlineData, -) -> Dict[str, Any]: +def _get_kwargs(*, form_data: PostFormDataInlineData, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/post_form_data_inline".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -30,16 +30,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = cast(Any, response.json()) + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -48,17 +46,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, - form_data: PostFormDataInlineData, -) -> Response[Any]: +def sync_detailed(*, form_data: PostFormDataInlineData, client: "MyTestApiClient") -> Response[Any]: """Post form data (inline schema) Post form data (inline schema) Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -78,17 +72,32 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, - form_data: PostFormDataInlineData, -) -> Response[Any]: +def sync(*, form_data: PostFormDataInlineData, client: "MyTestApiClient") -> Any: + """Post form data (inline schema) + + Post form data (inline schema) + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + form_data=form_data, + ).parsed + + +async def asyncio_detailed(*, form_data: PostFormDataInlineData, client: "MyTestApiClient") -> Response[Any]: """Post form data (inline schema) Post form data (inline schema) Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -104,3 +113,24 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(*, form_data: PostFormDataInlineData, client: "MyTestApiClient") -> Any: + """Post form data (inline schema) + + Post form data (inline schema) + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + form_data=form_data, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py index 7bd2c3b16..c823d9f5e 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/post_tests_json_body_string.py @@ -1,19 +1,19 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict, cast + from ... import errors -from ...client import Client from ...models.http_validation_error import HTTPValidationError from ...types import Response -def _get_kwargs( - *, - client: Client, - json_body: str, -) -> Dict[str, Any]: +def _get_kwargs(*, json_body: str, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/json_body/string".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -32,21 +32,18 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[HTTPValidationError, str]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> str: if response.status_code == HTTPStatus.OK: response_200 = cast(str, response.json()) return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) - return response_422 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content, response_422) + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[HTTPValidationError, str]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[str]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -55,22 +52,18 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni ) -def sync_detailed( - *, - client: Client, - json_body: str, -) -> Response[Union[HTTPValidationError, str]]: +def sync_detailed(*, json_body: str, client: "MyTestApiClient") -> Response[str]: """Json Body Which is String Args: json_body (str): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[str] """ kwargs = _get_kwargs( @@ -86,22 +79,18 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, - json_body: str, -) -> Optional[Union[HTTPValidationError, str]]: +def sync(*, json_body: str, client: "MyTestApiClient") -> str: """Json Body Which is String Args: json_body (str): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[str] """ return sync_detailed( @@ -110,22 +99,18 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, - json_body: str, -) -> Response[Union[HTTPValidationError, str]]: +async def asyncio_detailed(*, json_body: str, client: "MyTestApiClient") -> Response[str]: """Json Body Which is String Args: json_body (str): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[str] """ kwargs = _get_kwargs( @@ -139,22 +124,18 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, - json_body: str, -) -> Optional[Union[HTTPValidationError, str]]: +async def asyncio(*, json_body: str, client: "MyTestApiClient") -> str: """Json Body Which is String Args: json_body (str): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[HTTPValidationError, str]] + Response[str] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py index 7e3baf769..53f17f429 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/test_inline_objects.py @@ -1,20 +1,20 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict + from ... import errors -from ...client import Client from ...models.test_inline_objects_json_body import TestInlineObjectsJsonBody from ...models.test_inline_objects_response_200 import TestInlineObjectsResponse200 from ...types import Response -def _get_kwargs( - *, - client: Client, - json_body: TestInlineObjectsJsonBody, -) -> Dict[str, Any]: +def _get_kwargs(*, json_body: TestInlineObjectsJsonBody, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/inline_objects".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -33,18 +33,15 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[TestInlineObjectsResponse200]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> TestInlineObjectsResponse200: if response.status_code == HTTPStatus.OK: response_200 = TestInlineObjectsResponse200.from_dict(response.json()) return response_200 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[TestInlineObjectsResponse200]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[TestInlineObjectsResponse200]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -54,9 +51,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Tes def sync_detailed( - *, - client: Client, - json_body: TestInlineObjectsJsonBody, + *, json_body: TestInlineObjectsJsonBody, client: "MyTestApiClient" ) -> Response[TestInlineObjectsResponse200]: """Test Inline Objects @@ -64,7 +59,7 @@ def sync_detailed( json_body (TestInlineObjectsJsonBody): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -84,18 +79,14 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, - json_body: TestInlineObjectsJsonBody, -) -> Optional[TestInlineObjectsResponse200]: +def sync(*, json_body: TestInlineObjectsJsonBody, client: "MyTestApiClient") -> TestInlineObjectsResponse200: """Test Inline Objects Args: json_body (TestInlineObjectsJsonBody): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -109,9 +100,7 @@ def sync( async def asyncio_detailed( - *, - client: Client, - json_body: TestInlineObjectsJsonBody, + *, json_body: TestInlineObjectsJsonBody, client: "MyTestApiClient" ) -> Response[TestInlineObjectsResponse200]: """Test Inline Objects @@ -119,7 +108,7 @@ async def asyncio_detailed( json_body (TestInlineObjectsJsonBody): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -137,18 +126,14 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, - json_body: TestInlineObjectsJsonBody, -) -> Optional[TestInlineObjectsResponse200]: +async def asyncio(*, json_body: TestInlineObjectsJsonBody, client: "MyTestApiClient") -> TestInlineObjectsResponse200: """Test Inline Objects Args: json_body (TestInlineObjectsJsonBody): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py index 994f1ee4e..e1e79c187 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/token_with_cookie_auth_token_with_cookie_get.py @@ -1,18 +1,16 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - *, - client: Client, - my_token: str, -) -> Dict[str, Any]: +def _get_kwargs(*, my_token: str, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/auth/token_with_cookie".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -30,18 +28,17 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None + response_200 = cast(Any, response.json()) + return response_200 if response.status_code == HTTPStatus.UNAUTHORIZED: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_401 = None + raise errors.UnexpectedStatus(response.status_code, response.content, response_401) + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -50,11 +47,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, - my_token: str, -) -> Response[Any]: +def sync_detailed(*, my_token: str, client: "MyTestApiClient") -> Response[Any]: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -63,7 +56,7 @@ def sync_detailed( my_token (str): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -83,11 +76,7 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, - my_token: str, -) -> Response[Any]: +def sync(*, my_token: str, client: "MyTestApiClient") -> Any: """TOKEN_WITH_COOKIE Test optional cookie parameters @@ -96,7 +85,29 @@ async def asyncio_detailed( my_token (str): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + my_token=my_token, + ).parsed + + +async def asyncio_detailed(*, my_token: str, client: "MyTestApiClient") -> Response[Any]: + """TOKEN_WITH_COOKIE + + Test optional cookie parameters + + Args: + my_token (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -112,3 +123,27 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(*, my_token: str, client: "MyTestApiClient") -> Any: + """TOKEN_WITH_COOKIE + + Test optional cookie parameters + + Args: + my_token (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + my_token=my_token, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py index 6b719cb38..53f5d8d53 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/unsupported_content_tests_unsupported_content_get.py @@ -1,17 +1,16 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + from ... import errors -from ...client import Client from ...types import Response -def _get_kwargs( - *, - client: Client, -) -> Dict[str, Any]: +def _get_kwargs(client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/unsupported_content".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -27,16 +26,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = cast(Any, response.json()) + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -45,14 +42,11 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, -) -> Response[Any]: +def sync_detailed(client: "MyTestApiClient") -> Response[Any]: """Unsupported Content Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -71,14 +65,27 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, -) -> Response[Any]: +def sync(client: "MyTestApiClient") -> Any: + """Unsupported Content + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + ).parsed + + +async def asyncio_detailed(client: "MyTestApiClient") -> Response[Any]: """Unsupported Content Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -93,3 +100,21 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(client: "MyTestApiClient") -> Any: + """Unsupported Content + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py index 8a49818fb..9ba30e662 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_file_tests_upload_post.py @@ -1,20 +1,20 @@ from http import HTTPStatus -from typing import Any, Dict, Optional, Union, cast +from typing import TYPE_CHECKING, Any, Dict, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict, cast + from ... import errors -from ...client import Client from ...models.body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost from ...models.http_validation_error import HTTPValidationError from ...types import Response -def _get_kwargs( - *, - client: Client, - multipart_data: BodyUploadFileTestsUploadPost, -) -> Dict[str, Any]: +def _get_kwargs(*, multipart_data: BodyUploadFileTestsUploadPost, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/upload".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -33,21 +33,18 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) - return response_422 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content, response_422) + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -56,11 +53,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni ) -def sync_detailed( - *, - client: Client, - multipart_data: BodyUploadFileTestsUploadPost, -) -> Response[Union[Any, HTTPValidationError]]: +def sync_detailed(*, multipart_data: BodyUploadFileTestsUploadPost, client: "MyTestApiClient") -> Response[Any]: """Upload File Upload a file @@ -69,11 +62,11 @@ def sync_detailed( multipart_data (BodyUploadFileTestsUploadPost): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -89,11 +82,7 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, - multipart_data: BodyUploadFileTestsUploadPost, -) -> Optional[Union[Any, HTTPValidationError]]: +def sync(*, multipart_data: BodyUploadFileTestsUploadPost, client: "MyTestApiClient") -> Any: """Upload File Upload a file @@ -102,11 +91,11 @@ def sync( multipart_data (BodyUploadFileTestsUploadPost): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return sync_detailed( @@ -116,10 +105,8 @@ def sync( async def asyncio_detailed( - *, - client: Client, - multipart_data: BodyUploadFileTestsUploadPost, -) -> Response[Union[Any, HTTPValidationError]]: + *, multipart_data: BodyUploadFileTestsUploadPost, client: "MyTestApiClient" +) -> Response[Any]: """Upload File Upload a file @@ -128,11 +115,11 @@ async def asyncio_detailed( multipart_data (BodyUploadFileTestsUploadPost): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -146,11 +133,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, - multipart_data: BodyUploadFileTestsUploadPost, -) -> Optional[Union[Any, HTTPValidationError]]: +async def asyncio(*, multipart_data: BodyUploadFileTestsUploadPost, client: "MyTestApiClient") -> Any: """Upload File Upload a file @@ -159,11 +142,11 @@ async def asyncio( multipart_data (BodyUploadFileTestsUploadPost): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py index ff5d5132d..57c149e04 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/tests/upload_multiple_files_tests_upload_post.py @@ -1,19 +1,19 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import TYPE_CHECKING, Any, Dict, List, cast import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from typing import Dict, List, cast + from ... import errors -from ...client import Client from ...models.http_validation_error import HTTPValidationError from ...types import File, Response -def _get_kwargs( - *, - client: Client, - multipart_data: List[File], -) -> Dict[str, Any]: +def _get_kwargs(*, multipart_data: List[File], client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/tests/upload/multiple".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -36,21 +36,18 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Union[Any, HTTPValidationError]]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: response_200 = cast(Any, response.json()) return response_200 if response.status_code == HTTPStatus.UNPROCESSABLE_ENTITY: response_422 = HTTPValidationError.from_dict(response.json()) - return response_422 - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.UnexpectedStatus(response.status_code, response.content, response_422) + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Union[Any, HTTPValidationError]]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -59,11 +56,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Uni ) -def sync_detailed( - *, - client: Client, - multipart_data: List[File], -) -> Response[Union[Any, HTTPValidationError]]: +def sync_detailed(*, multipart_data: List[File], client: "MyTestApiClient") -> Response[Any]: """Upload multiple files Upload several files in the same request @@ -72,11 +65,11 @@ def sync_detailed( multipart_data (List[File]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -92,11 +85,7 @@ def sync_detailed( return _build_response(client=client, response=response) -def sync( - *, - client: Client, - multipart_data: List[File], -) -> Optional[Union[Any, HTTPValidationError]]: +def sync(*, multipart_data: List[File], client: "MyTestApiClient") -> Any: """Upload multiple files Upload several files in the same request @@ -105,11 +94,11 @@ def sync( multipart_data (List[File]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return sync_detailed( @@ -118,11 +107,7 @@ def sync( ).parsed -async def asyncio_detailed( - *, - client: Client, - multipart_data: List[File], -) -> Response[Union[Any, HTTPValidationError]]: +async def asyncio_detailed(*, multipart_data: List[File], client: "MyTestApiClient") -> Response[Any]: """Upload multiple files Upload several files in the same request @@ -131,11 +116,11 @@ async def asyncio_detailed( multipart_data (List[File]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ kwargs = _get_kwargs( @@ -149,11 +134,7 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -async def asyncio( - *, - client: Client, - multipart_data: List[File], -) -> Optional[Union[Any, HTTPValidationError]]: +async def asyncio(*, multipart_data: List[File], client: "MyTestApiClient") -> Any: """Upload multiple files Upload several files in the same request @@ -162,11 +143,11 @@ async def asyncio( multipart_data (List[File]): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: - Response[Union[Any, HTTPValidationError]] + Response[Any] """ return ( diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/true_/__init__.py b/end_to_end_tests/golden-record/my_test_api_client/api/true_/__init__.py index e69de29bb..80c4de474 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/true_/__init__.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/true_/__init__.py @@ -0,0 +1,55 @@ +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from ...client import MyTestApiClient + +from . import false_ + + +class True_: + def __init__(self, client: "MyTestApiClient"): + self.__client = client + + def false_( + self, + *, + import_: str, + ) -> Any: + """ + Args: + import_ (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return false_.sync( + client=self.__client, + import_=import_, + ) + + async def false__async( + self, + *, + import_: str, + ) -> Any: + """ + Args: + import_ (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return await false_.asyncio( + client=self.__client, + import_=import_, + ) diff --git a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py index 05967d439..5f28d963d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py +++ b/end_to_end_tests/golden-record/my_test_api_client/api/true_/false_.py @@ -1,18 +1,16 @@ from http import HTTPStatus -from typing import Any, Dict, Optional +from typing import TYPE_CHECKING, Any, Dict import httpx +if TYPE_CHECKING: + from ...client import MyTestApiClient + from ... import errors -from ...client import Client from ...types import UNSET, Response -def _get_kwargs( - *, - client: Client, - import_: str, -) -> Dict[str, Any]: +def _get_kwargs(*, import_: str, client: "MyTestApiClient") -> Dict[str, Any]: url = "{}/naming/keywords".format(client.base_url) headers: Dict[str, str] = client.get_headers() @@ -34,16 +32,14 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[Any]: +def _parse_response(*, client: "MyTestApiClient", response: httpx.Response) -> Any: if response.status_code == HTTPStatus.OK: - return None - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + response_200 = None + return response_200 + raise errors.UnexpectedStatus(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[Any]: +def _build_response(*, client: "MyTestApiClient", response: httpx.Response) -> Response[Any]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -52,17 +48,13 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[Any ) -def sync_detailed( - *, - client: Client, - import_: str, -) -> Response[Any]: +def sync_detailed(*, import_: str, client: "MyTestApiClient") -> Response[Any]: """ Args: import_ (str): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -82,17 +74,32 @@ def sync_detailed( return _build_response(client=client, response=response) -async def asyncio_detailed( - *, - client: Client, - import_: str, -) -> Response[Any]: +def sync(*, import_: str, client: "MyTestApiClient") -> Any: """ Args: import_ (str): Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return sync_detailed( + client=client, + import_=import_, + ).parsed + + +async def asyncio_detailed(*, import_: str, client: "MyTestApiClient") -> Response[Any]: + """ + Args: + import_ (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: @@ -108,3 +115,24 @@ async def asyncio_detailed( response = await _client.request(**kwargs) return _build_response(client=client, response=response) + + +async def asyncio(*, import_: str, client: "MyTestApiClient") -> Any: + """ + Args: + import_ (str): + + Raises: + errors.UnexpectedStatus: If the server returns a non 2xx status code. + httpx.TimeoutException: If the request takes longer than Client.timeout. + + Returns: + Response[Any] + """ + + return ( + await asyncio_detailed( + client=client, + import_=import_, + ) + ).parsed diff --git a/end_to_end_tests/golden-record/my_test_api_client/client.py b/end_to_end_tests/golden-record/my_test_api_client/client.py index 2f45c655b..5b33e3699 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/client.py +++ b/end_to_end_tests/golden-record/my_test_api_client/client.py @@ -1,11 +1,17 @@ import ssl from typing import Dict, Union -import attr +from .api.default import Default +from .api.location import Location +from .api.parameter_references import ParameterReferences +from .api.parameters import Parameters +from .api.responses import Responses +from .api.tag1 import Tag1 +from .api.tests import Tests +from .api.true_ import True_ -@attr.s(auto_attribs=True) -class Client: +class MyTestApiClient: """A class for keeping track of data related to the API Attributes: @@ -18,49 +24,52 @@ class Client: but can be set to False for testing purposes. raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a status code that was not documented in the source OpenAPI document. - follow_redirects: Whether or not to follow redirects. Default value is False. + follow_redirects: Whether or not to follow redirects. Default value is True. """ - base_url: str - cookies: Dict[str, str] = attr.ib(factory=dict, kw_only=True) - headers: Dict[str, str] = attr.ib(factory=dict, kw_only=True) - timeout: float = attr.ib(5.0, kw_only=True) - verify_ssl: Union[str, bool, ssl.SSLContext] = attr.ib(True, kw_only=True) - raise_on_unexpected_status: bool = attr.ib(False, kw_only=True) - follow_redirects: bool = attr.ib(False, kw_only=True) + def __init__( + self, + base_url: str, + cookies: Union[Dict[str, str], None] = None, + headers: Union[Dict[str, str], None] = None, + timeout: float = 5.0, + verify_ssl: Union[str, bool, ssl.SSLContext] = True, + follow_redirects: bool = True, + token: Union[str, None] = None, + prefix: str = "Bearer", + auth_header_name: str = "Authorization", + ): + cookies = cookies if cookies is not None else {} + headers = headers if headers is not None else {} + + self.base_url = base_url + self.cookies = cookies + self.headers = headers + self.timeout = timeout + self.verify_ssl = verify_ssl + self.follow_redirects = follow_redirects + self.token = token + self.prefix = prefix + self.auth_header_name = auth_header_name + + self.tests = Tests(client=self) + self.responses = Responses(client=self) + self.default = Default(client=self) + self.parameters = Parameters(client=self) + self.tag1 = Tag1(client=self) + self.location = Location(client=self) + self.true_ = True_(client=self) + self.parameter_references = ParameterReferences(client=self) def get_headers(self) -> Dict[str, str]: """Get headers to be used in all endpoints""" - return {**self.headers} - - def with_headers(self, headers: Dict[str, str]) -> "Client": - """Get a new client matching this one with additional headers""" - return attr.evolve(self, headers={**self.headers, **headers}) + if not self.token: + return {**self.headers} + auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token + return {self.auth_header_name: auth_header_value, **self.headers} def get_cookies(self) -> Dict[str, str]: return {**self.cookies} - def with_cookies(self, cookies: Dict[str, str]) -> "Client": - """Get a new client matching this one with additional cookies""" - return attr.evolve(self, cookies={**self.cookies, **cookies}) - def get_timeout(self) -> float: return self.timeout - - def with_timeout(self, timeout: float) -> "Client": - """Get a new client matching this one with a new timeout (in seconds)""" - return attr.evolve(self, timeout=timeout) - - -@attr.s(auto_attribs=True) -class AuthenticatedClient(Client): - """A Client which has been authenticated for use on secured endpoints""" - - token: str - prefix: str = "Bearer" - auth_header_name: str = "Authorization" - - def get_headers(self) -> Dict[str, str]: - """Get headers to be used in authenticated endpoints""" - auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token - return {self.auth_header_name: auth_header_value, **self.headers} diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AFormData.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AFormData.md new file mode 100644 index 000000000..332f519ea --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AFormData.md @@ -0,0 +1,10 @@ +# AFormData + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +an_required_field | str | None +an_optional_field | Union[Unset, str] | None +a_simple_dict | Union[Unset, Dict[str, Any]] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AModel.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AModel.md new file mode 100644 index 000000000..72887ffcb --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AModel.md @@ -0,0 +1,32 @@ +# AModelA Model for testing all the ways custom objects can be used + + + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +an_enum_value | AnEnum | For testing Enums in all the ways they can be used +an_allof_enum_with_overridden_default | AnAllOfEnum | None +a_camel_date_time | Union[datetime.date, datetime.datetime] | None +a_date | datetime.date | None +required_not_nullable | str | None +one_of_models | Union['FreeFormModel', 'ModelWithUnionProperty', Any] | None +model | ModelWithUnionProperty | +any_value | Union[Unset, Any] | None +an_optional_allof_enum | Union[Unset, AnAllOfEnum] | None +nested_list_of_enums | Union[Unset, List[List[DifferentEnum]]] | None +a_nullable_date | Optional[datetime.date] | None +a_not_required_date | Union[Unset, datetime.date] | None +attr_1_leading_digit | Union[Unset, str] | None +attr_leading_underscore | Union[Unset, str] | None +required_nullable | Optional[str] | None +not_required_nullable | Union[Unset, None, str] | None +not_required_not_nullable | Union[Unset, str] | None +nullable_one_of_models | Union['FreeFormModel', 'ModelWithUnionProperty', None] | None +not_required_one_of_models | Union['FreeFormModel', 'ModelWithUnionProperty', Unset] | None +not_required_nullable_one_of_models | Union['FreeFormModel', 'ModelWithUnionProperty', None, Unset, str] | None +nullable_model | Optional[ModelWithUnionProperty] | +not_required_model | Union[Unset, ModelWithUnionProperty] | +not_required_nullable_model | Union[Unset, None, ModelWithUnionProperty] | + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AModelWithPropertiesReferenceThatAreNotObject.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AModelWithPropertiesReferenceThatAreNotObject.md new file mode 100644 index 000000000..6f52243d7 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AModelWithPropertiesReferenceThatAreNotObject.md @@ -0,0 +1,37 @@ +# AModelWithPropertiesReferenceThatAreNotObject + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +enum_properties_ref | List[AnEnum] | None +str_properties_ref | List[str] | None +date_properties_ref | List[datetime.date] | None +datetime_properties_ref | List[datetime.datetime] | None +int32_properties_ref | List[int] | None +int64_properties_ref | List[int] | None +float_properties_ref | List[float] | None +double_properties_ref | List[float] | None +file_properties_ref | List[File] | None +bytestream_properties_ref | List[str] | None +enum_properties | List[AnEnum] | None +str_properties | List[str] | None +date_properties | List[datetime.date] | None +datetime_properties | List[datetime.datetime] | None +int32_properties | List[int] | None +int64_properties | List[int] | None +float_properties | List[float] | None +double_properties | List[float] | None +file_properties | List[File] | None +bytestream_properties | List[str] | None +enum_property_ref | AnEnum | For testing Enums in all the ways they can be used +str_property_ref | str | None +date_property_ref | datetime.date | None +datetime_property_ref | datetime.datetime | None +int32_property_ref | int | None +int64_property_ref | int | None +float_property_ref | float | None +double_property_ref | float | None +file_property_ref | File | None +bytestream_property_ref | str | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AllOfHasPropertiesButNoType.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AllOfHasPropertiesButNoType.md new file mode 100644 index 000000000..548b18a80 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AllOfHasPropertiesButNoType.md @@ -0,0 +1,10 @@ +# AllOfHasPropertiesButNoType + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a_sub_property | Union[Unset, str] | None +type | Union[Unset, str] | None +type_enum | Union[Unset, AllOfHasPropertiesButNoTypeTypeEnum] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AllOfSubModel.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AllOfSubModel.md new file mode 100644 index 000000000..a4a8ac4b7 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AllOfSubModel.md @@ -0,0 +1,10 @@ +# AllOfSubModel + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a_sub_property | Union[Unset, str] | None +type | Union[Unset, str] | None +type_enum | Union[Unset, AllOfSubModelTypeEnum] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectAItem.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectAItem.md new file mode 100644 index 000000000..edf433323 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectAItem.md @@ -0,0 +1,8 @@ +# AnArrayWithACircularRefInItemsObjectAItem + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +circular | Union[Unset, List['AnArrayWithACircularRefInItemsObjectBItem']] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem.md new file mode 100644 index 000000000..34eea0943 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem.md @@ -0,0 +1,4 @@ +# AnArrayWithACircularRefInItemsObjectAdditionalPropertiesAItem + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem.md new file mode 100644 index 000000000..e8450fa9c --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem.md @@ -0,0 +1,4 @@ +# AnArrayWithACircularRefInItemsObjectAdditionalPropertiesBItem + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectBItem.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectBItem.md new file mode 100644 index 000000000..c7716909d --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithACircularRefInItemsObjectBItem.md @@ -0,0 +1,8 @@ +# AnArrayWithACircularRefInItemsObjectBItem + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +circular | Union[Unset, List['AnArrayWithACircularRefInItemsObjectAItem']] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem.md new file mode 100644 index 000000000..0696ae57d --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem.md @@ -0,0 +1,4 @@ +# AnArrayWithARecursiveRefInItemsObjectAdditionalPropertiesItem + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithARecursiveRefInItemsObjectItem.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithARecursiveRefInItemsObjectItem.md new file mode 100644 index 000000000..57f71c128 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AnArrayWithARecursiveRefInItemsObjectItem.md @@ -0,0 +1,8 @@ +# AnArrayWithARecursiveRefInItemsObjectItem + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +recursive | Union[Unset, List['AnArrayWithARecursiveRefInItemsObjectItem']] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/AnotherAllOfSubModel.md b/end_to_end_tests/golden-record/my_test_api_client/docs/AnotherAllOfSubModel.md new file mode 100644 index 000000000..6bbd5a1d9 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/AnotherAllOfSubModel.md @@ -0,0 +1,10 @@ +# AnotherAllOfSubModel + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +another_sub_property | Union[Unset, str] | None +type | Union[Unset, AnotherAllOfSubModelType] | None +type_enum | Union[Unset, AnotherAllOfSubModelTypeEnum] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPost.md b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPost.md new file mode 100644 index 000000000..d4b77ffcc --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPost.md @@ -0,0 +1,18 @@ +# BodyUploadFileTestsUploadPost + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +some_file | File | None +some_object | BodyUploadFileTestsUploadPostSomeObject | +some_optional_file | Union[Unset, File] | None +some_string | Union[Unset, str] | None +a_datetime | Union[Unset, datetime.datetime] | None +a_date | Union[Unset, datetime.date] | None +some_number | Union[Unset, float] | None +some_array | Union[Unset, List[float]] | None +some_optional_object | Union[Unset, BodyUploadFileTestsUploadPostSomeOptionalObject] | +some_nullable_object | Optional[BodyUploadFileTestsUploadPostSomeNullableObject] | +some_enum | Union[Unset, DifferentEnum] | An enumeration. + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostAdditionalProperty.md b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostAdditionalProperty.md new file mode 100644 index 000000000..b5f9c74f9 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostAdditionalProperty.md @@ -0,0 +1,8 @@ +# BodyUploadFileTestsUploadPostAdditionalProperty + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +foo | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostSomeNullableObject.md b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostSomeNullableObject.md new file mode 100644 index 000000000..fb6dd31de --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostSomeNullableObject.md @@ -0,0 +1,8 @@ +# BodyUploadFileTestsUploadPostSomeNullableObject + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +bar | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostSomeObject.md b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostSomeObject.md new file mode 100644 index 000000000..f2b19b783 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostSomeObject.md @@ -0,0 +1,9 @@ +# BodyUploadFileTestsUploadPostSomeObject + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +num | float | None +text | str | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostSomeOptionalObject.md b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostSomeOptionalObject.md new file mode 100644 index 000000000..8ac1a48dd --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/BodyUploadFileTestsUploadPostSomeOptionalObject.md @@ -0,0 +1,8 @@ +# BodyUploadFileTestsUploadPostSomeOptionalObject + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +foo | str | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/Default.md b/end_to_end_tests/golden-record/my_test_api_client/docs/Default.md new file mode 100644 index 000000000..96fff7333 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/Default.md @@ -0,0 +1,33 @@ +# default + + +Method | HTTP Request | Description +------------- | ------------- | ------------- +[**get_common_parameters**](#get_common_parameters) | GET /common_parameters | +[**post_common_parameters**](#post_common_parameters) | POST /common_parameters | + + +# **get_common_parameters** + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +common | str | None + + +### Response Type +Any + +# **post_common_parameters** + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +common | str | None + + +### Response Type +Any + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/FreeFormModel.md b/end_to_end_tests/golden-record/my_test_api_client/docs/FreeFormModel.md new file mode 100644 index 000000000..5474efd01 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/FreeFormModel.md @@ -0,0 +1,8 @@ +# FreeFormModel + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +prop | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/HTTPValidationError.md b/end_to_end_tests/golden-record/my_test_api_client/docs/HTTPValidationError.md new file mode 100644 index 000000000..7319d9617 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/HTTPValidationError.md @@ -0,0 +1,8 @@ +# HTTPValidationError + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +detail | Union[Unset, List['ValidationError']] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/Import.md b/end_to_end_tests/golden-record/my_test_api_client/docs/Import.md new file mode 100644 index 000000000..0575432f0 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/Import.md @@ -0,0 +1,8 @@ +# Import + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +prop | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/Location.md b/end_to_end_tests/golden-record/my_test_api_client/docs/Location.md new file mode 100644 index 000000000..eb35e2498 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/Location.md @@ -0,0 +1,41 @@ +# location + + +Method | HTTP Request | Description +------------- | ------------- | ------------- +[**get_location_query_optionality**](#get_location_query_optionality) | GET /location/query/optionality | +[**get_location_header_types**](#get_location_header_types) | GET /location/header/types | + + +# **get_location_query_optionality** + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +not_null_required | datetime.datetime | None +null_required | datetime.datetime | None +null_not_required | datetime.datetime | None +not_null_not_required | datetime.datetime | None + + +### Response Type +Any + +# **get_location_header_types** + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +boolean_header | bool | None +string_header | str | None +number_header | float | None +integer_header | int | None +int_enum_header | GetLocationHeaderTypesIntEnumHeader | None +string_enum_header | GetLocationHeaderTypesStringEnumHeader | None + + +### Response Type +Any + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelFromAllOf.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelFromAllOf.md new file mode 100644 index 000000000..694fb819a --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelFromAllOf.md @@ -0,0 +1,11 @@ +# ModelFromAllOf + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a_sub_property | Union[Unset, str] | None +type | Union[Unset, AnotherAllOfSubModelType] | None +type_enum | Union[Unset, AnotherAllOfSubModelTypeEnum] | None +another_sub_property | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelName.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelName.md new file mode 100644 index 000000000..bef2d3e58 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelName.md @@ -0,0 +1,8 @@ +# ModelName + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +prop | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelReferenceWithPeriods.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelReferenceWithPeriods.md new file mode 100644 index 000000000..f09fd73d3 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelReferenceWithPeriods.md @@ -0,0 +1,10 @@ +# ModelReferenceWithPeriodsA Model with periods in its reference + + + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +prop | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAdditionalPropertiesInlined.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAdditionalPropertiesInlined.md new file mode 100644 index 000000000..3d25b363d --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAdditionalPropertiesInlined.md @@ -0,0 +1,8 @@ +# ModelWithAdditionalPropertiesInlined + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a_number | Union[Unset, float] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAdditionalPropertiesInlinedAdditionalProperty.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAdditionalPropertiesInlinedAdditionalProperty.md new file mode 100644 index 000000000..e58ddac23 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAdditionalPropertiesInlinedAdditionalProperty.md @@ -0,0 +1,8 @@ +# ModelWithAdditionalPropertiesInlinedAdditionalProperty + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +extra_props_prop | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAdditionalPropertiesRefed.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAdditionalPropertiesRefed.md new file mode 100644 index 000000000..00b0ee4a7 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAdditionalPropertiesRefed.md @@ -0,0 +1,4 @@ +# ModelWithAdditionalPropertiesRefed + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAnyJsonProperties.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAnyJsonProperties.md new file mode 100644 index 000000000..7a5fd47b0 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAnyJsonProperties.md @@ -0,0 +1,4 @@ +# ModelWithAnyJsonProperties + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAnyJsonPropertiesAdditionalPropertyType0.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAnyJsonPropertiesAdditionalPropertyType0.md new file mode 100644 index 000000000..de7099313 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithAnyJsonPropertiesAdditionalPropertyType0.md @@ -0,0 +1,4 @@ +# ModelWithAnyJsonPropertiesAdditionalPropertyType0 + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithBackslashInDescription.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithBackslashInDescription.md new file mode 100644 index 000000000..baf8e8c08 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithBackslashInDescription.md @@ -0,0 +1,10 @@ +# ModelWithBackslashInDescriptionDescription with special character: \ + + + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +prop | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefA.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefA.md new file mode 100644 index 000000000..8c23cafb1 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefA.md @@ -0,0 +1,8 @@ +# ModelWithCircularRefA + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +circular | Union[Unset, ModelWithCircularRefB] | + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefB.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefB.md new file mode 100644 index 000000000..22b045906 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefB.md @@ -0,0 +1,8 @@ +# ModelWithCircularRefB + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +circular | Union[Unset, ModelWithCircularRefA] | + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefInAdditionalPropertiesA.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefInAdditionalPropertiesA.md new file mode 100644 index 000000000..4ee16f476 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefInAdditionalPropertiesA.md @@ -0,0 +1,4 @@ +# ModelWithCircularRefInAdditionalPropertiesA + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefInAdditionalPropertiesB.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefInAdditionalPropertiesB.md new file mode 100644 index 000000000..8b9d4175d --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithCircularRefInAdditionalPropertiesB.md @@ -0,0 +1,4 @@ +# ModelWithCircularRefInAdditionalPropertiesB + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithDateTimeProperty.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithDateTimeProperty.md new file mode 100644 index 000000000..60c264345 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithDateTimeProperty.md @@ -0,0 +1,8 @@ +# ModelWithDateTimeProperty + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +datetime_ | Union[Unset, datetime.datetime] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithPrimitiveAdditionalProperties.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithPrimitiveAdditionalProperties.md new file mode 100644 index 000000000..b65a652b7 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithPrimitiveAdditionalProperties.md @@ -0,0 +1,8 @@ +# ModelWithPrimitiveAdditionalProperties + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a_date_holder | Union[Unset, ModelWithPrimitiveAdditionalPropertiesADateHolder] | + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithPrimitiveAdditionalPropertiesADateHolder.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithPrimitiveAdditionalPropertiesADateHolder.md new file mode 100644 index 000000000..5ebf021d1 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithPrimitiveAdditionalPropertiesADateHolder.md @@ -0,0 +1,4 @@ +# ModelWithPrimitiveAdditionalPropertiesADateHolder + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithPropertyRef.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithPropertyRef.md new file mode 100644 index 000000000..85570ce43 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithPropertyRef.md @@ -0,0 +1,8 @@ +# ModelWithPropertyRef + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +inner | Union[Unset, ModelName] | + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithRecursiveRef.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithRecursiveRef.md new file mode 100644 index 000000000..66bb03472 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithRecursiveRef.md @@ -0,0 +1,8 @@ +# ModelWithRecursiveRef + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +recursive | Union[Unset, ModelWithRecursiveRef] | + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithRecursiveRefInAdditionalProperties.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithRecursiveRefInAdditionalProperties.md new file mode 100644 index 000000000..8c1c54a45 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithRecursiveRefInAdditionalProperties.md @@ -0,0 +1,4 @@ +# ModelWithRecursiveRefInAdditionalProperties + + + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionProperty.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionProperty.md new file mode 100644 index 000000000..7e6b70473 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionProperty.md @@ -0,0 +1,8 @@ +# ModelWithUnionProperty + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a_property | Union[AnEnum, AnIntEnum, Unset] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionPropertyInlined.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionPropertyInlined.md new file mode 100644 index 000000000..84be33853 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionPropertyInlined.md @@ -0,0 +1,8 @@ +# ModelWithUnionPropertyInlined + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +fruit | Union['ModelWithUnionPropertyInlinedFruitType0', 'ModelWithUnionPropertyInlinedFruitType1', Unset] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionPropertyInlinedFruitType0.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionPropertyInlinedFruitType0.md new file mode 100644 index 000000000..9d3cbd5d9 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionPropertyInlinedFruitType0.md @@ -0,0 +1,8 @@ +# ModelWithUnionPropertyInlinedFruitType0 + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +apples | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionPropertyInlinedFruitType1.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionPropertyInlinedFruitType1.md new file mode 100644 index 000000000..665ea6e45 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ModelWithUnionPropertyInlinedFruitType1.md @@ -0,0 +1,8 @@ +# ModelWithUnionPropertyInlinedFruitType1 + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +bananas | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/None_.md b/end_to_end_tests/golden-record/my_test_api_client/docs/None_.md new file mode 100644 index 000000000..1affa74ed --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/None_.md @@ -0,0 +1,8 @@ +# None_ + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +prop | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ParameterReferences.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ParameterReferences.md new file mode 100644 index 000000000..a844011a5 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ParameterReferences.md @@ -0,0 +1,26 @@ +# parameter-references + + +Method | HTTP Request | Description +------------- | ------------- | ------------- +[**get_parameter_references_path_param**](#get_parameter_references_path_param) | GET /parameter-references/{path_param} | + + +# **get_parameter_references_path_param** + +Test different types of parameter references + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +path_param | str | None +string_param | str | None +integer_param | int | None +header_param | str | None +cookie_param | str | None + + +### Response Type +Any + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/Parameters.md b/end_to_end_tests/golden-record/my_test_api_client/docs/Parameters.md new file mode 100644 index 000000000..9956383d6 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/Parameters.md @@ -0,0 +1,69 @@ +# parameters + + +Method | HTTP Request | Description +------------- | ------------- | ------------- +[**get_common_parameters_overriding_param**](#get_common_parameters_overriding_param) | GET /common_parameters_overriding/{param} | Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code +[**delete_common_parameters_overriding_param**](#delete_common_parameters_overriding_param) | DELETE /common_parameters_overriding/{param} | +[**get_same_name_multiple_locations_param**](#get_same_name_multiple_locations_param) | GET /same-name-multiple-locations/{param} | +[**multiple_path_parameters**](#multiple_path_parameters) | GET /multiple-path-parameters/{param4}/something/{param2}/{param1}/{param3} | + + +# **get_common_parameters_overriding_param** + + Test that if you have an overriding property from `PathItem` in `Operation`, it produces valid code + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +param_path | str | None +param_query | str | A parameter with the same name as another. + + +### Response Type +Any + +# **delete_common_parameters_overriding_param** + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +param_path | str | None +param_query | str | None + + +### Response Type +Any + +# **get_same_name_multiple_locations_param** + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +param_path | str | None +param_query | str | None +param_header | str | None +param_cookie | str | None + + +### Response Type +Any + +# **multiple_path_parameters** + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +param4 | str | None +param2 | int | None +param1 | str | None +param3 | int | None + + +### Response Type +Any + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/PostFormDataInlineData.md b/end_to_end_tests/golden-record/my_test_api_client/docs/PostFormDataInlineData.md new file mode 100644 index 000000000..0130bd733 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/PostFormDataInlineData.md @@ -0,0 +1,9 @@ +# PostFormDataInlineData + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a_required_field | str | None +an_optional_field | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/PostResponsesUnionsSimpleBeforeComplexResponse200.md b/end_to_end_tests/golden-record/my_test_api_client/docs/PostResponsesUnionsSimpleBeforeComplexResponse200.md new file mode 100644 index 000000000..253f71d9b --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/PostResponsesUnionsSimpleBeforeComplexResponse200.md @@ -0,0 +1,8 @@ +# PostResponsesUnionsSimpleBeforeComplexResponse200 + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a | Union['PostResponsesUnionsSimpleBeforeComplexResponse200AType1', str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/PostResponsesUnionsSimpleBeforeComplexResponse200AType1.md b/end_to_end_tests/golden-record/my_test_api_client/docs/PostResponsesUnionsSimpleBeforeComplexResponse200AType1.md new file mode 100644 index 000000000..71e3d0104 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/PostResponsesUnionsSimpleBeforeComplexResponse200AType1.md @@ -0,0 +1,8 @@ +# PostResponsesUnionsSimpleBeforeComplexResponse200AType1 + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +prop | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/Responses.md b/end_to_end_tests/golden-record/my_test_api_client/docs/Responses.md new file mode 100644 index 000000000..baebe912a --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/Responses.md @@ -0,0 +1,17 @@ +# responses + + +Method | HTTP Request | Description +------------- | ------------- | ------------- +[**post_responses_unions_simple_before_complex**](#post_responses_unions_simple_before_complex) | POST /responses/unions/simple_before_complex | Regression test for #603 + + +# **post_responses_unions_simple_before_complex** + + Regression test for #603 + + + +### Response Type +PostResponsesUnionsSimpleBeforeComplexResponse200 + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/Tag1.md b/end_to_end_tests/golden-record/my_test_api_client/docs/Tag1.md new file mode 100644 index 000000000..4299e29e7 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/Tag1.md @@ -0,0 +1,15 @@ +# 1 + + +Method | HTTP Request | Description +------------- | ------------- | ------------- +[**get_tag_with_number**](#get_tag_with_number) | GET /tag_with_number | + + +# **get_tag_with_number** + + + +### Response Type +Any + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/TestInlineObjectsJsonBody.md b/end_to_end_tests/golden-record/my_test_api_client/docs/TestInlineObjectsJsonBody.md new file mode 100644 index 000000000..ddf767eb1 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/TestInlineObjectsJsonBody.md @@ -0,0 +1,8 @@ +# TestInlineObjectsJsonBody + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a_property | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/TestInlineObjectsResponse200.md b/end_to_end_tests/golden-record/my_test_api_client/docs/TestInlineObjectsResponse200.md new file mode 100644 index 000000000..79199769a --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/TestInlineObjectsResponse200.md @@ -0,0 +1,8 @@ +# TestInlineObjectsResponse200 + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +a_property | Union[Unset, str] | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/Tests.md b/end_to_end_tests/golden-record/my_test_api_client/docs/Tests.md new file mode 100644 index 000000000..e6d545f4d --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/Tests.md @@ -0,0 +1,296 @@ +# tests + + +Method | HTTP Request | Description +------------- | ------------- | ------------- +[**get_user_list**](#get_user_list) | GET /tests/ | Get a list of things +[**get_basic_list_of_strings**](#get_basic_list_of_strings) | GET /tests/basic_lists/strings | Get a list of strings +[**get_basic_list_of_integers**](#get_basic_list_of_integers) | GET /tests/basic_lists/integers | Get a list of integers +[**get_basic_list_of_floats**](#get_basic_list_of_floats) | GET /tests/basic_lists/floats | Get a list of floats +[**get_basic_list_of_booleans**](#get_basic_list_of_booleans) | GET /tests/basic_lists/booleans | Get a list of booleans +[**post_form_data**](#post_form_data) | POST /tests/post_form_data | Post form data +[**post_form_data_inline**](#post_form_data_inline) | POST /tests/post_form_data_inline | Post form data (inline schema) +[**upload_file_tests_upload_post**](#upload_file_tests_upload_post) | POST /tests/upload | Upload a file +[**upload_multiple_files_tests_upload_post**](#upload_multiple_files_tests_upload_post) | POST /tests/upload/multiple | Upload several files in the same request +[**json_body_tests_json_body_post**](#json_body_tests_json_body_post) | POST /tests/json_body | Try sending a JSON body +[**post_tests_json_body_string**](#post_tests_json_body_string) | POST /tests/json_body/string | +[**defaults_tests_defaults_post**](#defaults_tests_defaults_post) | POST /tests/defaults | +[**octet_stream_tests_octet_stream_get**](#octet_stream_tests_octet_stream_get) | GET /tests/octet_stream | +[**no_response_tests_no_response_get**](#no_response_tests_no_response_get) | GET /tests/no_response | +[**unsupported_content_tests_unsupported_content_get**](#unsupported_content_tests_unsupported_content_get) | GET /tests/unsupported_content | +[**int_enum_tests_int_enum_post**](#int_enum_tests_int_enum_post) | POST /tests/int_enum | +[**test_inline_objects**](#test_inline_objects) | POST /tests/inline_objects | +[**token_with_cookie_auth_token_with_cookie_get**](#token_with_cookie_auth_token_with_cookie_get) | GET /auth/token_with_cookie | Test optional cookie parameters +[**callback_test**](#callback_test) | POST /tests/callback | Try sending a request related to a callback +[**description_with_backslash**](#description_with_backslash) | GET /tests/description-with-backslash | Test description with \ + + +# **get_user_list** + +Get List + + Get a list of things + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +an_enum_value | [List[AnEnum]](List[AnEnum]) | None +an_enum_value_with_null | [List[Optional[AnEnumWithNull]]](List[Optional[AnEnumWithNull]]) | None +an_enum_value_with_only_null | [List[None]](List[None]) | None +some_date | [Union[datetime.date, datetime.datetime]](Union[datetime.date, datetime.datetime]) | None + + +### Response Type +List['AModel'] + +# **get_basic_list_of_strings** + +Get Basic List Of Strings + + Get a list of strings + + + +### Response Type +List[str] + +# **get_basic_list_of_integers** + +Get Basic List Of Integers + + Get a list of integers + + + +### Response Type +List[int] + +# **get_basic_list_of_floats** + +Get Basic List Of Floats + + Get a list of floats + + + +### Response Type +List[float] + +# **get_basic_list_of_booleans** + +Get Basic List Of Booleans + + Get a list of booleans + + + +### Response Type +List[bool] + +# **post_form_data** + +Post form data + + Post form data + + + +### Response Type +Any + +# **post_form_data_inline** + +Post form data (inline schema) + + Post form data (inline schema) + + + +### Response Type +Any + +# **upload_file_tests_upload_post** + +Upload File + + Upload a file + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +multipart_data | [BodyUploadFileTestsUploadPost](BodyUploadFileTestsUploadPost) | + + +### Response Type +Any + +# **upload_multiple_files_tests_upload_post** + +Upload multiple files + + Upload several files in the same request + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +multipart_data | [List[File]](List[File]) | None + + +### Response Type +Any + +# **json_body_tests_json_body_post** + +Json Body + + Try sending a JSON body + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +json_body | [AModel](AModel) | A Model for testing all the ways custom objects can be used + + +### Response Type +Any + +# **post_tests_json_body_string** + +Json Body Which is String + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +json_body | str | None + + +### Response Type +str + +# **defaults_tests_defaults_post** + +Defaults + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +string_prop | str | None +date_prop | datetime.date | None +float_prop | float | None +int_prop | int | None +boolean_prop | bool | None +list_prop | [List[AnEnum]](List[AnEnum]) | None +union_prop | [Union[float, str]](Union[float, str]) | None +union_prop_with_ref | [Union[AnEnum, float]](Union[AnEnum, float]) | None +enum_prop | AnEnum | For testing Enums in all the ways they can be used +model_prop | [ModelWithUnionProperty](ModelWithUnionProperty) | +required_model_prop | [ModelWithUnionProperty](ModelWithUnionProperty) | + + +### Response Type +Any + +# **octet_stream_tests_octet_stream_get** + +Octet Stream + + + +### Response Type +File + +# **no_response_tests_no_response_get** + +No Response + + + +### Response Type +Any + +# **unsupported_content_tests_unsupported_content_get** + +Unsupported Content + + + +### Response Type +Any + +# **int_enum_tests_int_enum_post** + +Int Enum + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +int_enum | AnIntEnum | An enumeration. + + +### Response Type +Any + +# **test_inline_objects** + +Test Inline Objects + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +json_body | [TestInlineObjectsJsonBody](TestInlineObjectsJsonBody) | + + +### Response Type +TestInlineObjectsResponse200 + +# **token_with_cookie_auth_token_with_cookie_get** + +TOKEN_WITH_COOKIE + + Test optional cookie parameters + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +my_token | str | None + + +### Response Type +Any + +# **callback_test** + +Path with callback + + Try sending a request related to a callback + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +json_body | [AModel](AModel) | A Model for testing all the ways custom objects can be used + + +### Response Type +Any + +# **description_with_backslash** + +Test description with \ + + Test description with \ + + + +### Response Type +Any + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/True_.md b/end_to_end_tests/golden-record/my_test_api_client/docs/True_.md new file mode 100644 index 000000000..327c80f44 --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/True_.md @@ -0,0 +1,20 @@ +# true + + +Method | HTTP Request | Description +------------- | ------------- | ------------- +[**false_**](#false_) | GET /naming/keywords | + + +# **false_** + + +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +import_ | str | None + + +### Response Type +Any + diff --git a/end_to_end_tests/golden-record/my_test_api_client/docs/ValidationError.md b/end_to_end_tests/golden-record/my_test_api_client/docs/ValidationError.md new file mode 100644 index 000000000..95d4423cf --- /dev/null +++ b/end_to_end_tests/golden-record/my_test_api_client/docs/ValidationError.md @@ -0,0 +1,10 @@ +# ValidationError + + +## Properties +Name | Type | Description +------------ | ------------- | ------------- +loc | List[str] | None +msg | str | None +type | str | None + diff --git a/end_to_end_tests/golden-record/my_test_api_client/errors.py b/end_to_end_tests/golden-record/my_test_api_client/errors.py index 426f8a2ed..24d933312 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/errors.py +++ b/end_to_end_tests/golden-record/my_test_api_client/errors.py @@ -1,12 +1,18 @@ """ Contains shared errors types that can be raised from API functions """ -class UnexpectedStatus(Exception): +from typing import Generic, Optional, TypeVar + +T = TypeVar("T") + + +class UnexpectedStatus(Exception, Generic[T]): """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" - def __init__(self, status_code: int, content: bytes): + def __init__(self, status_code: int, content: bytes, parsed: Optional[T]): self.status_code = status_code self.content = content + self.parsed = parsed super().__init__(f"Unexpected status code: {status_code}") diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/a_form_data.py b/end_to_end_tests/golden-record/my_test_api_client/models/a_form_data.py index 958b24ab5..b3606f842 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/a_form_data.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/a_form_data.py @@ -13,15 +13,18 @@ class AFormData: Attributes: an_required_field (str): an_optional_field (Union[Unset, str]): + a_simple_dict (Union[Unset, Dict[str, Any]]): """ an_required_field: str an_optional_field: Union[Unset, str] = UNSET + a_simple_dict: Union[Unset, Dict[str, Any]] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: an_required_field = self.an_required_field an_optional_field = self.an_optional_field + a_simple_dict = self.a_simple_dict field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) @@ -32,6 +35,8 @@ def to_dict(self) -> Dict[str, Any]: ) if an_optional_field is not UNSET: field_dict["an_optional_field"] = an_optional_field + if a_simple_dict is not UNSET: + field_dict["a_simple_dict"] = a_simple_dict return field_dict @@ -42,9 +47,12 @@ def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: an_optional_field = d.pop("an_optional_field", UNSET) + a_simple_dict = d.pop("a_simple_dict", UNSET) + a_form_data = cls( an_required_field=an_required_field, an_optional_field=an_optional_field, + a_simple_dict=a_simple_dict, ) a_form_data.additional_properties = d diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py b/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py index f8cc2151c..bb86c4bcc 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/free_form_model.py @@ -1,28 +1,41 @@ -from typing import Any, Dict, List, Type, TypeVar +from typing import Any, Dict, List, Type, TypeVar, Union import attr +from ..types import UNSET, Unset + T = TypeVar("T", bound="FreeFormModel") @attr.s(auto_attribs=True) class FreeFormModel: - """ """ + """ + Attributes: + prop (Union[Unset, str]): + """ + prop: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: + prop = self.prop field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) + if prop is not UNSET: + field_dict["prop"] = prop return field_dict @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - free_form_model = cls() + prop = d.pop("prop", UNSET) + + free_form_model = cls( + prop=prop, + ) free_form_model.additional_properties = d return free_form_model diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/import_.py b/end_to_end_tests/golden-record/my_test_api_client/models/import_.py index 276a4f21b..d7ea6a1ec 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/import_.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/import_.py @@ -1,28 +1,41 @@ -from typing import Any, Dict, List, Type, TypeVar +from typing import Any, Dict, List, Type, TypeVar, Union import attr +from ..types import UNSET, Unset + T = TypeVar("T", bound="Import") @attr.s(auto_attribs=True) class Import: - """ """ + """ + Attributes: + prop (Union[Unset, str]): + """ + prop: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: + prop = self.prop field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) + if prop is not UNSET: + field_dict["prop"] = prop return field_dict @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - import_ = cls() + prop = d.pop("prop", UNSET) + + import_ = cls( + prop=prop, + ) import_.additional_properties = d return import_ diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py index c87d4c208..f7df40af5 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_name.py @@ -1,28 +1,41 @@ -from typing import Any, Dict, List, Type, TypeVar +from typing import Any, Dict, List, Type, TypeVar, Union import attr +from ..types import UNSET, Unset + T = TypeVar("T", bound="ModelName") @attr.s(auto_attribs=True) class ModelName: - """ """ + """ + Attributes: + prop (Union[Unset, str]): + """ + prop: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: + prop = self.prop field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) + if prop is not UNSET: + field_dict["prop"] = prop return field_dict @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_name = cls() + prop = d.pop("prop", UNSET) + + model_name = cls( + prop=prop, + ) model_name.additional_properties = d return model_name diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py index 15bab8de5..41786141c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_reference_with_periods.py @@ -1,28 +1,42 @@ -from typing import Any, Dict, List, Type, TypeVar +from typing import Any, Dict, List, Type, TypeVar, Union import attr +from ..types import UNSET, Unset + T = TypeVar("T", bound="ModelReferenceWithPeriods") @attr.s(auto_attribs=True) class ModelReferenceWithPeriods: - """A Model with periods in its reference""" + """A Model with periods in its reference + + Attributes: + prop (Union[Unset, str]): + """ + prop: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: + prop = self.prop field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) + if prop is not UNSET: + field_dict["prop"] = prop return field_dict @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_reference_with_periods = cls() + prop = d.pop("prop", UNSET) + + model_reference_with_periods = cls( + prop=prop, + ) model_reference_with_periods.additional_properties = d return model_reference_with_periods diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_backslash_in_description.py b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_backslash_in_description.py index d52952236..b2d434021 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/model_with_backslash_in_description.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/model_with_backslash_in_description.py @@ -1,7 +1,9 @@ -from typing import Any, Dict, List, Type, TypeVar +from typing import Any, Dict, List, Type, TypeVar, Union import attr +from ..types import UNSET, Unset + T = TypeVar("T", bound="ModelWithBackslashInDescription") @@ -9,22 +11,32 @@ class ModelWithBackslashInDescription: r""" Description with special character: \ + Attributes: + prop (Union[Unset, str]): """ + prop: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: + prop = self.prop field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) + if prop is not UNSET: + field_dict["prop"] = prop return field_dict @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - model_with_backslash_in_description = cls() + prop = d.pop("prop", UNSET) + + model_with_backslash_in_description = cls( + prop=prop, + ) model_with_backslash_in_description.additional_properties = d return model_with_backslash_in_description diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/none.py b/end_to_end_tests/golden-record/my_test_api_client/models/none.py index e1722f094..4eb1314a7 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/none.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/none.py @@ -1,28 +1,41 @@ -from typing import Any, Dict, List, Type, TypeVar +from typing import Any, Dict, List, Type, TypeVar, Union import attr +from ..types import UNSET, Unset + T = TypeVar("T", bound="None_") @attr.s(auto_attribs=True) class None_: - """ """ + """ + Attributes: + prop (Union[Unset, str]): + """ + prop: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: + prop = self.prop field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) + if prop is not UNSET: + field_dict["prop"] = prop return field_dict @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - none = cls() + prop = d.pop("prop", UNSET) + + none = cls( + prop=prop, + ) none.additional_properties = d return none diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py b/end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py index 6b9ae2484..90c0c7db8 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/post_responses_unions_simple_before_complex_response_200a_type_1.py @@ -1,28 +1,41 @@ -from typing import Any, Dict, List, Type, TypeVar +from typing import Any, Dict, List, Type, TypeVar, Union import attr +from ..types import UNSET, Unset + T = TypeVar("T", bound="PostResponsesUnionsSimpleBeforeComplexResponse200AType1") @attr.s(auto_attribs=True) class PostResponsesUnionsSimpleBeforeComplexResponse200AType1: - """ """ + """ + Attributes: + prop (Union[Unset, str]): + """ + prop: Union[Unset, str] = UNSET additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict) def to_dict(self) -> Dict[str, Any]: + prop = self.prop field_dict: Dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update({}) + if prop is not UNSET: + field_dict["prop"] = prop return field_dict @classmethod def from_dict(cls: Type[T], src_dict: Dict[str, Any]) -> T: d = src_dict.copy() - post_responses_unions_simple_before_complex_response_200a_type_1 = cls() + prop = d.pop("prop", UNSET) + + post_responses_unions_simple_before_complex_response_200a_type_1 = cls( + prop=prop, + ) post_responses_unions_simple_before_complex_response_200a_type_1.additional_properties = d return post_responses_unions_simple_before_complex_response_200a_type_1 diff --git a/end_to_end_tests/golden-record/my_test_api_client/types.py b/end_to_end_tests/golden-record/my_test_api_client/types.py index 230efea92..2e9f7b08c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/types.py +++ b/end_to_end_tests/golden-record/my_test_api_client/types.py @@ -38,7 +38,7 @@ class Response(Generic[T]): status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] - parsed: Optional[T] + parsed: T __all__ = ["File", "Response", "FileJsonType"] diff --git a/end_to_end_tests/openapi.json b/end_to_end_tests/openapi.json index 11baa0cc5..6bff4d125 100644 --- a/end_to_end_tests/openapi.json +++ b/end_to_end_tests/openapi.json @@ -770,7 +770,14 @@ "a": { "oneOf": [ {"type": "string"}, - {"type": "object"} + { + "type": "object", + "properties": { + "prop" : { + "type": "string" + } + } + } ] } } @@ -1256,6 +1263,9 @@ }, "an_required_field": { "type": "string" + }, + "a_simple_dict": { + "type": "object" } }, "required": [ @@ -1676,7 +1686,12 @@ }, "FreeFormModel": { "title": "FreeFormModel", - "type": "object" + "type": "object", + "properties": { + "prop" : { + "type": "string" + } + } }, "ModelWithAdditionalPropertiesInlined": { "type": "object", @@ -1812,7 +1827,12 @@ }, "model_reference_doesnt_match": { "title": "ModelName", - "type": "object" + "type": "object", + "properties": { + "prop" : { + "type": "string" + } + } }, "ModelWithPropertyRef": { "type": "object", @@ -2128,14 +2148,29 @@ "format": "byte" }, "import": { - "type": "object" + "type": "object", + "properties": { + "prop" : { + "type": "string" + } + } }, "None": { - "type": "object" + "type": "object", + "properties": { + "prop" : { + "type": "string" + } + } }, "model.reference.with.Periods": { "type": "object", - "description": "A Model with periods in its reference" + "description": "A Model with periods in its reference", + "properties": { + "prop" : { + "type": "string" + } + } }, "ModelWithRecursiveRef": { "type": "object", @@ -2241,7 +2276,12 @@ }, "ModelWithBackslashInDescription": { "type": "object", - "description": "Description with special character: \\" + "description": "Description with special character: \\", + "properties": { + "prop" : { + "type": "string" + } + } } }, "parameters": { diff --git a/end_to_end_tests/regen_golden_record.py b/end_to_end_tests/regen_golden_record.py index 1d4dc943d..b387e0b94 100644 --- a/end_to_end_tests/regen_golden_record.py +++ b/end_to_end_tests/regen_golden_record.py @@ -76,4 +76,4 @@ def regen_custom_template_golden_record(): if __name__ == "__main__": regen_golden_record() - regen_custom_template_golden_record() + # regen_custom_template_golden_record() diff --git a/end_to_end_tests/test_custom_templates/client.py.jinja b/end_to_end_tests/test_custom_templates/client.py.jinja new file mode 100644 index 000000000..d60df5553 --- /dev/null +++ b/end_to_end_tests/test_custom_templates/client.py.jinja @@ -0,0 +1,60 @@ +import ssl +import threading +from typing import Dict, Union + + +class {{ client_name }}: + """A class for keeping track of data related to the API + + Attributes: + base_url: The base URL for the API, all requests are made to a relative path to this URL + cookies: A dictionary of cookies to be sent with every request + headers: A dictionary of headers to be sent with every request + timeout: The maximum amount of a time in seconds a request can take. API functions will raise + httpx.TimeoutException if this is exceeded. + verify_ssl: Whether or not to verify the SSL certificate of the API server. This should be True in production, + but can be set to False for testing purposes. + raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a + status code that was not documented in the source OpenAPI document. + follow_redirects: Whether or not to follow redirects. Default value is False. + """ + + def __init__( + self, + base_url: str, + cookies: Union[Dict[str, str], None] = None, + headers: Union[Dict[str, str], None] = None, + timeout: float = 5.0, + verify_ssl: Union[str, bool, ssl.SSLContext] = True, + raise_on_unexpected_status: bool = False, + follow_redirects: bool = False, + token: Union[str, None] = None, + prefix: str = "Bearer", + auth_header_name: str = "Authorization", + ): + cookies = cookies if cookies is not None else {} + headers = headers if headers is not None else {} + + self.base_url = base_url + self.cookies = cookies + self.headers = headers + self.timeout = timeout + self.verify_ssl = verify_ssl + self.raise_on_unexpected_status = raise_on_unexpected_status + self.follow_redirects = follow_redirects + self.token = token + self.prefix = prefix + self.auth_header_name = auth_header_name + + def get_headers(self) -> Dict[str, str]: + """Get headers to be used in all endpoints""" + if not self.token: + return {**self.headers} + auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token + return {self.auth_header_name: auth_header_value, **self.headers} + + def get_cookies(self) -> Dict[str, str]: + return {**self.cookies} + + def get_timeout(self) -> float: + return self.timeout diff --git a/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja b/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja index dd64d942c..a1470b26f 100644 --- a/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja +++ b/end_to_end_tests/test_custom_templates/endpoint_init.py.jinja @@ -5,7 +5,7 @@ import types from . import {{ python_identifier(endpoint.name) }} {% endfor %} -class {{ class_name(endpoint_collection.tag) }}Endpoints: +class {{ endpoint_collection.tag.class_name }}Endpoints: {% for endpoint in endpoint_collection.endpoints %} diff --git a/end_to_end_tests/test_end_to_end.py b/end_to_end_tests/test_end_to_end.py index 6ad49fcb9..db7daba94 100644 --- a/end_to_end_tests/test_end_to_end.py +++ b/end_to_end_tests/test_end_to_end.py @@ -97,6 +97,7 @@ def test_custom_templates(): expected_difference_paths = [ Path("README.md"), + Path("my_test_api_client").joinpath("client.py"), api_dir.joinpath("__init__.py"), ] diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index 109ce84c7..badc3010f 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -87,6 +87,7 @@ def __init__( self.project_dir /= self.project_name self.package_name: str = config.package_name_override or self.project_name.replace("-", "_") + self.client_name: str = utils.ClassName(self.package_name, config.field_prefix) self.package_dir: Path = self.project_dir / self.package_name self.package_description: str = utils.remove_string_escapes( f"A client library for accessing {self.openapi.title}" @@ -99,6 +100,7 @@ def __init__( python_identifier=lambda x: utils.PythonIdentifier(x, config.field_prefix), class_name=lambda x: utils.ClassName(x, config.field_prefix), package_name=self.package_name, + client_name=self.client_name, package_dir=self.package_dir, package_description=self.package_description, package_version=self.version, @@ -232,17 +234,24 @@ def _build_models(self) -> None: # Generate models models_dir = self.package_dir / "models" models_dir.mkdir() + docs_dir = self.package_dir / "docs" + docs_dir.mkdir(exist_ok=True) models_init = models_dir / "__init__.py" imports = [] alls = [] model_template = self.env.get_template("model.py.jinja") + model_doc_template = self.env.get_template("model.md.jinja") for model in self.openapi.models: module_path = models_dir / f"{model.class_info.module_name}.py" module_path.write_text(model_template.render(model=model), encoding=self.file_encoding) imports.append(import_string_from_class(model.class_info)) alls.append(model.class_info.name) + # Generate model docs + doc_path = docs_dir / f"{model.class_info.name}.md" + doc_path.write_text(model_doc_template.render(model=model), encoding=self.file_encoding) + # Generate enums str_enum_template = self.env.get_template("str_enum.py.jinja") int_enum_template = self.env.get_template("int_enum.py.jinja") @@ -270,6 +279,9 @@ def _build_api(self) -> None: errors_template = self.env.get_template("errors.py.jinja") errors_path.write_text(errors_template.render(), encoding=self.file_encoding) + docs_dir = self.package_dir / "docs" + docs_dir.mkdir(exist_ok=True) + # Generate endpoints api_dir = self.package_dir / "api" api_dir.mkdir() @@ -281,19 +293,26 @@ def _build_api(self) -> None: endpoint_template = self.env.get_template( "endpoint_module.py.jinja", globals={"isbool": lambda obj: obj.get_base_type_string() == "bool"} ) - for tag, collection in endpoint_collections_by_tag.items(): - tag_dir = api_dir / tag + api_doc_template = self.env.get_template( + "api.md.jinja", globals={"isbool": lambda obj: obj.get_base_type_string() == "bool"} + ) + for _, collection in endpoint_collections_by_tag.items(): + def module_name(endpoint): + return utils.PythonIdentifier(endpoint.name, self.config.field_prefix) + + tag = collection.tag + tag_dir = api_dir / tag.identifier_name tag_dir.mkdir() endpoint_init_path = tag_dir / "__init__.py" endpoint_init_template = self.env.get_template("endpoint_init.py.jinja") endpoint_init_path.write_text( - endpoint_init_template.render(endpoint_collection=collection), + endpoint_init_template.render(endpoint_collection=collection, module_name=module_name), encoding=self.file_encoding, ) - + for endpoint in collection.endpoints: - module_path = tag_dir / f"{utils.PythonIdentifier(endpoint.name, self.config.field_prefix)}.py" + module_path = tag_dir / f"{module_name(endpoint)}.py" module_path.write_text( endpoint_template.render( endpoint=endpoint, @@ -301,6 +320,12 @@ def _build_api(self) -> None: encoding=self.file_encoding, ) + api_doc_path = docs_dir / f"{tag.class_name}.md" + api_doc_path.write_text( + api_doc_template.render(endpoint_collection=collection, module_name=module_name), + encoding=self.file_encoding + ) + def _get_project_for_url_or_path( # pylint: disable=too-many-arguments url: Optional[str], diff --git a/openapi_python_client/config.py b/openapi_python_client/config.py index afca35758..251787cd5 100644 --- a/openapi_python_client/config.py +++ b/openapi_python_client/config.py @@ -17,6 +17,16 @@ class ClassOverride(BaseModel): module_name: Optional[str] = None +class TagOverride(BaseModel): + """An override of a single generated class. + + See https://github.com/openapi-generators/openapi-python-client#tag_overrides + """ + + class_name: Optional[str] = None + identifier_name: Optional[str] = None + + class Config(BaseModel): """Contains any configurable values passed by the user. @@ -24,6 +34,7 @@ class Config(BaseModel): """ class_overrides: Dict[str, ClassOverride] = {} + tag_overrides: Dict[str, TagOverride] = {} project_name_override: Optional[str] package_name_override: Optional[str] package_version_override: Optional[str] diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index b7c4a8142..56aaaa186 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -11,7 +11,7 @@ from .. import schema as oai from .. import utils from ..config import Config -from ..utils import PythonIdentifier +from ..utils import ClassName, PythonIdentifier from .errors import GeneratorError, ParseError, PropertyError from .properties import ( Class, @@ -39,7 +39,7 @@ def import_string_from_class(class_: Class, prefix: str = "") -> str: class EndpointCollection: """A bunch of endpoints grouped under a tag that will become a module""" - tag: str + tag: "Tag" endpoints: List["Endpoint"] = field(default_factory=list) parse_errors: List[ParseError] = field(default_factory=list) @@ -57,8 +57,9 @@ def from_data( operation: Optional[oai.Operation] = getattr(path_data, method) if operation is None: continue - tag = utils.PythonIdentifier(value=(operation.tags or ["default"])[0], prefix="tag") - collection = endpoints_by_tag.setdefault(tag, EndpointCollection(tag=tag)) + + tag = Tag.from_string(string=(operation.tags or ["default"])[0], config=config) + collection = endpoints_by_tag.setdefault(tag.identifier_name, EndpointCollection(tag=tag)) endpoint, schemas, parameters = Endpoint.from_data( data=operation, path=path, @@ -513,8 +514,9 @@ def from_data( return result, schemas, parameters def response_type(self) -> str: - """Get the Python type of any response from this endpoint""" - types = sorted({response.prop.get_type_string(quoted=False) for response in self.responses}) + """Get the Python type of success responses from this endpoint""" + success_responses = [response for response in self.responses if response.is_success] + types = sorted({response.prop.get_type_string(quoted=False) for response in success_responses }) if len(types) == 0: return "Any" if len(types) == 1: @@ -583,3 +585,27 @@ def from_dict(data: Dict[str, Any], *, config: Config) -> Union["GeneratorData", errors=schemas.errors + parameters.errors, enums=enums, ) + + +@dataclass +class Tag: + name: str + class_name: ClassName + identifier_name: PythonIdentifier + + @staticmethod + def from_string(*, string: str, config: Config) -> "Tag": + """Get a Class from an arbitrary string""" + identifier_name = PythonIdentifier(string, "tag") + override = config.tag_overrides.get(string) + + if override is not None and isinstance(override.identifier_name, str): + identifier_name = override.identifier_name + + if override is not None and isinstance(override.class_name, str): + class_name = override.class_name + else: + class_name = identifier_name + class_name = ClassName(class_name, "tag") + + return Tag(name=string, class_name=class_name, identifier_name=identifier_name) \ No newline at end of file diff --git a/openapi_python_client/parser/properties/__init__.py b/openapi_python_client/parser/properties/__init__.py index c4fe245e0..775b7f898 100644 --- a/openapi_python_client/parser/properties/__init__.py +++ b/openapi_python_client/parser/properties/__init__.py @@ -177,6 +177,12 @@ class BooleanProperty(Property): } template: ClassVar[str] = "boolean_property.py.jinja" +@attr.s(auto_attribs=True, frozen=True) +class DictProperty(Property): + """A property of type Dict[str, Any]""" + + _type_string: ClassVar[str] = "Dict[str, Any]" + _json_type_string: ClassVar[str] = "Dict[str, Any]" InnerProp = TypeVar("InnerProp", bound=Property) @@ -696,6 +702,19 @@ def _property_from_data( process_properties=process_properties, roots=roots, ) + if data.type == oai.DataType.OBJECT and not data.allOf and not data.properties and not data.additionalProperties: + return ( + DictProperty( + name=name, + default=data.default, + required=required, + nullable=data.nullable, + python_name=utils.PythonIdentifier(value=name, prefix=config.field_prefix), + description=data.description, + example=data.example, + ), + schemas, + ) if data.type == oai.DataType.OBJECT or data.allOf or (data.type is None and data.properties): return build_model_property( data=data, diff --git a/openapi_python_client/parser/responses.py b/openapi_python_client/parser/responses.py index e1f2cb49a..bb6cac596 100644 --- a/openapi_python_client/parser/responses.py +++ b/openapi_python_client/parser/responses.py @@ -20,6 +20,9 @@ class Response: prop: Property source: str + @property + def is_success(self): + return self.status_code >= 200 and self.status_code <= 299 def _source_by_content_type(content_type: str) -> Optional[str]: known_content_types = { diff --git a/openapi_python_client/templates/README.md.jinja b/openapi_python_client/templates/README.md.jinja index 1d50c8d2a..10b1d3104 100644 --- a/openapi_python_client/templates/README.md.jinja +++ b/openapi_python_client/templates/README.md.jinja @@ -2,49 +2,34 @@ {{ package_description }} ## Usage -First, create a client: +First, configure a client: ```python -from {{ package_name }} import Client +from {{ package_name }} import {{ client_name }} -client = Client(base_url="https://api.example.com") -``` - -If the endpoints you're going to hit require authentication, use `AuthenticatedClient` instead: - -```python -from {{ package_name }} import AuthenticatedClient - -client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken") +client = {{ client_name }}(base_url="https://api.example.com", token="SuperSecretToken") ``` Now call your endpoint and use your models: ```python from {{ package_name }}.models import MyDataModel -from {{ package_name }}.api.my_tag import get_my_data_model -from {{ package_name }}.types import Response -my_data: MyDataModel = get_my_data_model.sync(client=client) -# or if you need more info (e.g. status_code) -response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) +my_data: MyDataModel = client.my_tag.get_my_data_model() ``` Or do the same thing with an async version: ```python from {{ package_name }}.models import MyDataModel -from {{ package_name }}.api.my_tag import get_my_data_model -from {{ package_name }}.types import Response -my_data: MyDataModel = await get_my_data_model.asyncio(client=client) -response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) +my_data: MyDataModel = await client.get_my_data_model_async() ``` By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle. ```python -client = AuthenticatedClient( +client = {{ client_name }}( base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl="/path/to/certificate_bundle.pem", @@ -54,25 +39,23 @@ client = AuthenticatedClient( You can also disable certificate validation altogether, but beware that **this is a security risk**. ```python -client = AuthenticatedClient( +client = {{ client_name }}( base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False ) ``` -There are more settings on the generated `Client` class which let you control more runtime behavior, check out the docstring on that class for more info. +There are more settings on the generated `{{ client_name }}` class which let you control more runtime behavior, check out the docstring on that class for more info. Things to know: -1. Every path/method combo becomes a Python module with four functions: - 1. `sync`: Blocking request that returns parsed data (if successful) or `None` - 1. `sync_detailed`: Blocking request that always returns a `Request`, optionally with `parsed` set if the request was successful. - 1. `asyncio`: Like `sync` but async instead of blocking - 1. `asyncio_detailed`: Like `sync_detailed` but async instead of blocking +1. Every path/method combo becomes provides you with two functions. For example: get_my_data_model has these methods: + 1. `get_my_data_model`: Blocking request that returns parsed data (if successful) or `None` + 1. `get_my_data_model_async`: Like `sync` but async instead of blocking 1. All path/query params, and bodies become method arguments. 1. If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above) -1. Any endpoint which did not have a tag will be in `{{ package_name }}.api.default` +1. Any endpoint which did not have a tag will be in `{{ package_name }}.default` ## Building / publishing this Client This project uses [Poetry](https://python-poetry.org/) to manage dependencies and packaging. Here are the basics: diff --git a/openapi_python_client/templates/api.md.jinja b/openapi_python_client/templates/api.md.jinja new file mode 100644 index 000000000..5f4c23da2 --- /dev/null +++ b/openapi_python_client/templates/api.md.jinja @@ -0,0 +1,35 @@ +# {{endpoint_collection.tag.name}} + + +Method | HTTP Request | Description +------------- | ------------- | ------------- +{% for endpoint in endpoint_collection.endpoints %} +[**{{module_name(endpoint)}}**](#{{module_name(endpoint)}}) | {{endpoint.method.upper()}} {{endpoint.path}} | {{endpoint.description}} +{% endfor %} + + +{% for endpoint in endpoint_collection.endpoints %} +# **{{module_name(endpoint)}}** + +{% if endpoint.summary %}{{ endpoint.summary | wordwrap(100)}} + +{% endif -%} +{%- if endpoint.description %} {{ endpoint.description | wordwrap(100) }} + +{% endif %} + +{% set all_parameters = endpoint.list_all_parameters() %} +{% if all_parameters %} +### Parameters: +Name | Type | Description +------------ | ------------- | ------------- +{% for parameter in all_parameters %} +{{parameter.python_name}} | {% if parameter.is_base_type %}{{parameter.get_type_string(no_optional=True)}}{% else %}[{{parameter.get_type_string(no_optional=True)}}]({{parameter.get_type_string(no_optional=True)}}){% endif %} | {{parameter.description}} +{% endfor %} + +{% endif %} + +### Response Type +{{ endpoint.response_type() }} + +{% endfor %} \ No newline at end of file diff --git a/openapi_python_client/templates/client.py.jinja b/openapi_python_client/templates/client.py.jinja index c6e6b2305..1ec7fff7f 100644 --- a/openapi_python_client/templates/client.py.jinja +++ b/openapi_python_client/templates/client.py.jinja @@ -1,10 +1,14 @@ import ssl +import threading from typing import Dict, Union -import attr -@attr.s(auto_attribs=True) -class Client: - """ A class for keeping track of data related to the API +{% for collection in endpoint_collections_by_tag.values() %} +from .api.{{ collection.tag.identifier_name }} import {{ collection.tag.class_name }} +{% endfor %} + + +class {{ client_name }}: + """A class for keeping track of data related to the API Attributes: base_url: The base URL for the API, all requests are made to a relative path to this URL @@ -16,48 +20,48 @@ class Client: but can be set to False for testing purposes. raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a status code that was not documented in the source OpenAPI document. - follow_redirects: Whether or not to follow redirects. Default value is False. + follow_redirects: Whether or not to follow redirects. Default value is True. """ - base_url: str - cookies: Dict[str, str] = attr.ib(factory=dict, kw_only=True) - headers: Dict[str, str] = attr.ib(factory=dict, kw_only=True) - timeout: float = attr.ib(5.0, kw_only=True) - verify_ssl: Union[str, bool, ssl.SSLContext] = attr.ib(True, kw_only=True) - raise_on_unexpected_status: bool = attr.ib(False, kw_only=True) - follow_redirects: bool = attr.ib(False, kw_only=True) + def __init__( + self, + base_url: str, + cookies: Union[Dict[str, str], None] = None, + headers: Union[Dict[str, str], None] = None, + timeout: float = 5.0, + verify_ssl: Union[str, bool, ssl.SSLContext] = True, + follow_redirects: bool = True, + token: Union[str, None] = None, + prefix: str = "Bearer", + auth_header_name: str = "Authorization", + ): + cookies = cookies if cookies is not None else {} + headers = headers if headers is not None else {} + + self.base_url = base_url + self.cookies = cookies + self.headers = headers + self.timeout = timeout + self.verify_ssl = verify_ssl + self.follow_redirects = follow_redirects + self.token = token + self.prefix = prefix + self.auth_header_name = auth_header_name - def get_headers(self) -> Dict[str, str]: - """ Get headers to be used in all endpoints """ - return {**self.headers} - def with_headers(self, headers: Dict[str, str]) -> "Client": - """ Get a new client matching this one with additional headers """ - return attr.evolve(self, headers={**self.headers, **headers}) + {% for collection in endpoint_collections_by_tag.values() %} + self.{{ collection.tag.identifier_name }} = {{ collection.tag.class_name }}(client=self) + {% endfor %} + + def get_headers(self) -> Dict[str, str]: + """Get headers to be used in all endpoints""" + if not self.token: + return {**self.headers} + auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token + return {self.auth_header_name: auth_header_value, **self.headers} def get_cookies(self) -> Dict[str, str]: return {**self.cookies} - def with_cookies(self, cookies: Dict[str, str]) -> "Client": - """ Get a new client matching this one with additional cookies """ - return attr.evolve(self, cookies={**self.cookies, **cookies}) - def get_timeout(self) -> float: return self.timeout - - def with_timeout(self, timeout: float) -> "Client": - """ Get a new client matching this one with a new timeout (in seconds) """ - return attr.evolve(self, timeout=timeout) - -@attr.s(auto_attribs=True) -class AuthenticatedClient(Client): - """ A Client which has been authenticated for use on secured endpoints """ - - token: str - prefix: str = "Bearer" - auth_header_name: str = "Authorization" - - def get_headers(self) -> Dict[str, str]: - """Get headers to be used in authenticated endpoints""" - auth_header_value = f"{self.prefix} {self.token}" if self.prefix else self.token - return {self.auth_header_name: auth_header_value, **self.headers} diff --git a/openapi_python_client/templates/endpoint_init.py.jinja b/openapi_python_client/templates/endpoint_init.py.jinja index e69de29bb..da98288c6 100644 --- a/openapi_python_client/templates/endpoint_init.py.jinja +++ b/openapi_python_client/templates/endpoint_init.py.jinja @@ -0,0 +1,48 @@ +from typing import Any, TYPE_CHECKING + +if TYPE_CHECKING: + from ...client import {{ client_name }} + +from . import ( +{% for endpoint in endpoint_collection.endpoints %} +{{ module_name(endpoint) }}, +{% endfor %} +) + +{% for endpoint in endpoint_collection.endpoints %} +{% for relative in endpoint.relative_imports %} +{{ relative }} +{% endfor %} +{% endfor %} + +{% from "endpoint_macros.py.jinja" import arguments, docstring, kwargs %} + +class {{ endpoint_collection.tag.class_name }}: + def __init__(self, client: "{{ client_name }}"): + self.__client = client + +{% for endpoint in endpoint_collection.endpoints %} +{% set return_string = endpoint.response_type() %} +{% set mod = module_name(endpoint) %} + + def {{ mod }}( + self, + {{ arguments(endpoint) | indent(4) }} + ) -> {{ return_string }}: + {{ docstring(endpoint, return_string) | indent(8) }} + return {{ mod }}.sync( + client=self.__client, + {{ kwargs(endpoint, False) }} + ) + + async def {{ mod }}_async( + self, + {{ arguments(endpoint) | indent(4) }} + ) -> {{ return_string }}: + {{ docstring(endpoint, return_string) | indent(8) }} + return await {{ mod }}.asyncio( + client=self.__client, + {{ kwargs(endpoint, False) }} + ) + +{% endfor %} diff --git a/openapi_python_client/templates/endpoint_macros.py.jinja b/openapi_python_client/templates/endpoint_macros.py.jinja index fde2e018a..64e27f4c1 100644 --- a/openapi_python_client/templates/endpoint_macros.py.jinja +++ b/openapi_python_client/templates/endpoint_macros.py.jinja @@ -83,12 +83,8 @@ params = {k: v for k, v in params.items() if v is not UNSET and v is not None} {% for parameter in endpoint.path_parameters.values() %} {{ parameter.to_string() }}, {% endfor %} +{% if endpoint.form_body or endpoint.multipart_body or endpoint.json_body or endpoint.query_parameters or endpoint.header_parameters or endpoint.cookie_parameters %} *, -{# Proper client based on whether or not the endpoint requires authentication #} -{% if endpoint.requires_security %} -client: AuthenticatedClient, -{% else %} -client: Client, {% endif %} {# Form data if any #} {% if endpoint.form_body %} @@ -116,11 +112,13 @@ json_body: {{ endpoint.json_body.get_type_string() }}, {% endmacro %} {# Just lists all kwargs to endpoints as name=name for passing to other functions #} -{% macro kwargs(endpoint) %} +{% macro kwargs(endpoint, include_client=True) %} {% for parameter in endpoint.path_parameters.values() %} {{ parameter.python_name }}={{ parameter.python_name }}, {% endfor %} +{% if include_client %} client=client, +{% endif %} {% if endpoint.form_body %} form_data=form_data, {% endif %} @@ -161,7 +159,7 @@ Args: {% endif %} Raises: - errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. + errors.{{ client_name }}Error: If the server returns a non 2xx status code. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index 3ea8991fb..fb51038fe 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -1,9 +1,12 @@ from http import HTTPStatus -from typing import Any, Dict, List, Optional, Union, cast +from typing import Any, Dict, List, Optional, Union, cast, TYPE_CHECKING + import httpx -from ...client import AuthenticatedClient, Client +if TYPE_CHECKING: + from ...client import {{ client_name }} + from ...types import Response, UNSET from ... import errors @@ -15,10 +18,11 @@ from ... import errors arguments, client, kwargs, parse_response, docstring %} {% set return_string = endpoint.response_type() %} -{% set parsed_responses = (endpoint.responses | length > 0) and return_string != "Any" %} +{% set parsed_responses = endpoint.responses | length > 0 %} def _get_kwargs( {{ arguments(endpoint) | indent(4) }} + client: "{{ client_name }}" ) -> Dict[str, Any]: url = "{}{{ endpoint.path }}".format( client.base_url @@ -60,27 +64,32 @@ def _get_kwargs( } -def _parse_response(*, client: Client, response: httpx.Response) -> Optional[{{ return_string }}]: +def _parse_response(*, client: "{{ client_name }}", response: httpx.Response) -> {{ return_string }}: {% for response in endpoint.responses %} if response.status_code == HTTPStatus.{{ response.status_code.name }}: {% if parsed_responses %}{% import "property_templates/" + response.prop.template as prop_template %} {% if prop_template.construct %} {{ prop_template.construct(response.prop, response.source) | indent(8) }} + {% elif response.source == "None" %} + {{ response.prop.python_name }} = None {% else %} {{ response.prop.python_name }} = cast({{ response.prop.get_type_string() }}, {{ response.source }}) {% endif %} + {% if response.is_success %} return {{ response.prop.python_name }} {% else %} + raise errors.{{ client_name }}Error(response.status_code, response.content, {{ response.prop.python_name }}) + {% endif %} + {% else %} + {% if response.is_success %} return None {% endif %} + {% endif %} {% endfor %} - if client.raise_on_unexpected_status: - raise errors.UnexpectedStatus(response.status_code, response.content) - else: - return None + raise errors.{{ client_name }}Error(response.status_code, response.content) -def _build_response(*, client: Client, response: httpx.Response) -> Response[{{ return_string }}]: +def _build_response(*, client: "{{ client_name }}", response: httpx.Response) -> Response[{{ return_string }}]: return Response( status_code=HTTPStatus(response.status_code), content=response.content, @@ -91,6 +100,7 @@ def _build_response(*, client: Client, response: httpx.Response) -> Response[{{ def sync_detailed( {{ arguments(endpoint) | indent(4) }} + client: "{{ client_name }}" ) -> Response[{{ return_string }}]: {{ docstring(endpoint, return_string) | indent(4) }} @@ -105,19 +115,19 @@ def sync_detailed( return _build_response(client=client, response=response) -{% if parsed_responses %} def sync( {{ arguments(endpoint) | indent(4) }} -) -> Optional[{{ return_string }}]: + client: "{{ client_name }}" +) -> {{ return_string }}: {{ docstring(endpoint, return_string) | indent(4) }} return sync_detailed( {{ kwargs(endpoint) }} ).parsed -{% endif %} async def asyncio_detailed( {{ arguments(endpoint) | indent(4) }} + client: "{{ client_name }}" ) -> Response[{{ return_string }}]: {{ docstring(endpoint, return_string) | indent(4) }} @@ -132,13 +142,12 @@ async def asyncio_detailed( return _build_response(client=client, response=response) -{% if parsed_responses %} async def asyncio( {{ arguments(endpoint) | indent(4) }} -) -> Optional[{{ return_string }}]: + client: "{{ client_name }}" +) -> {{ return_string }}: {{ docstring(endpoint, return_string) | indent(4) }} return (await asyncio_detailed( {{ kwargs(endpoint) }} )).parsed -{% endif %} diff --git a/openapi_python_client/templates/errors.py.jinja b/openapi_python_client/templates/errors.py.jinja index 514d3c1b9..1a5da2bcf 100644 --- a/openapi_python_client/templates/errors.py.jinja +++ b/openapi_python_client/templates/errors.py.jinja @@ -1,12 +1,19 @@ """ Contains shared errors types that can be raised from API functions """ -class UnexpectedStatus(Exception): - """ Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True """ - def __init__(self, status_code: int, content: bytes): +from typing import Generic, Optional, TypeVar + +T = TypeVar("T") + +class {{ client_name }}Error(Exception, Generic[T]): + """Raised by api functions when the response status an undocumented status and Client.raise_on_unexpected_status is True""" + + def __init__(self, status_code: int, content: bytes, parsed: Optional[T]): self.status_code = status_code self.content = content + self.parsed = parsed super().__init__(f"Unexpected status code: {status_code}") -__all__ = ["UnexpectedStatus"] + +__all__ = ["{{ client_name }}Error"] \ No newline at end of file diff --git a/openapi_python_client/templates/model.md.jinja b/openapi_python_client/templates/model.md.jinja new file mode 100644 index 000000000..6409f1df2 --- /dev/null +++ b/openapi_python_client/templates/model.md.jinja @@ -0,0 +1,20 @@ +# {{ model.class_info.name }} + +{%- if model.description %}{{ model.description | wordwrap(120) }} + +{% endif %} + +{% if model.example %} +### Example: +{{ model.example | string | wordwrap(120) | indent(12) }} +{% endif %} + + +{% if model.required_properties or model.optional_properties %} +## Properties +Name | Type | Description +------------ | ------------- | ------------- +{% for property in model.required_properties + model.optional_properties %} +{{property.python_name}} | {{property.get_type_string()}} | {{property.description}} +{% endfor %}{% endif %} + diff --git a/openapi_python_client/templates/package_init.py.jinja b/openapi_python_client/templates/package_init.py.jinja index ecf60e74d..0ff5d905c 100644 --- a/openapi_python_client/templates/package_init.py.jinja +++ b/openapi_python_client/templates/package_init.py.jinja @@ -1,9 +1,8 @@ {% from "helpers.jinja" import safe_docstring %} {{ safe_docstring(package_description) }} -from .client import AuthenticatedClient, Client +from .client import {{ client_name }} __all__ = ( - "AuthenticatedClient", - "Client", + "{{ client_name }}", ) diff --git a/openapi_python_client/templates/types.py.jinja b/openapi_python_client/templates/types.py.jinja index c746db6e1..82a522c6f 100644 --- a/openapi_python_client/templates/types.py.jinja +++ b/openapi_python_client/templates/types.py.jinja @@ -39,7 +39,7 @@ class Response(Generic[T]): status_code: HTTPStatus content: bytes headers: MutableMapping[str, str] - parsed: Optional[T] + parsed: T __all__ = ["File", "Response", "FileJsonType"] diff --git a/openapi_python_client/utils.py b/openapi_python_client/utils.py index c16237533..de1b020d7 100644 --- a/openapi_python_client/utils.py +++ b/openapi_python_client/utils.py @@ -48,7 +48,7 @@ def split_words(value: str) -> List[str]: return re.findall(rf"[^{DELIMITERS}]+", value) -RESERVED_WORDS = (set(dir(builtins)) | {"self", "true", "false", "datetime"}) - {"type", "id"} +RESERVED_WORDS = (set(dir(builtins)) | {"self", "true", "false", "datetime"}) - {"type", "id", "input", "min", "max"} def fix_reserved_words(value: str) -> str: diff --git a/tests/conftest.py b/tests/conftest.py index 7f8442ab7..c9c60d11d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,6 +8,7 @@ BooleanProperty, DateProperty, DateTimeProperty, + DictProperty, EnumProperty, FileProperty, IntProperty, @@ -193,6 +194,19 @@ def _factory(**kwargs): return _factory +@pytest.fixture +def dict_property_factory() -> Callable[..., DictProperty]: + """ + This fixture surfaces in the test as a function which manufactures StringProperties with defaults. + + You can pass the same params into this as the StringProperty constructor to override defaults. + """ + + def _factory(**kwargs): + kwargs = _common_kwargs(kwargs) + return DictProperty(**kwargs) + + return _factory @pytest.fixture def file_property_factory() -> Callable[..., FileProperty]: diff --git a/tests/test_parser/test_openapi.py b/tests/test_parser/test_openapi.py index 9cc7398d9..cd4eeb62f 100644 --- a/tests/test_parser/test_openapi.py +++ b/tests/test_parser/test_openapi.py @@ -6,7 +6,7 @@ import openapi_python_client.schema as oai from openapi_python_client import Config, GeneratorError from openapi_python_client.parser.errors import ParseError -from openapi_python_client.parser.openapi import Endpoint, EndpointCollection +from openapi_python_client.parser.openapi import Endpoint, EndpointCollection, Tag from openapi_python_client.parser.properties import IntProperty, Parameters, Schemas from openapi_python_client.schema import ParameterLocation @@ -1264,6 +1264,8 @@ def test_from_data(self, mocker): schemas = mocker.MagicMock() parameters = mocker.MagicMock() config = MagicMock() + tag_1 = Tag.from_string(string="default", config=config) + tag_2 = Tag.from_string(string="tag_2", config=config) result = EndpointCollection.from_data(data=data, schemas=schemas, parameters=parameters, config=config) @@ -1273,7 +1275,7 @@ def test_from_data(self, mocker): data=path_1_put, path="path_1", method="put", - tag="default", + tag=tag_1, schemas=schemas, parameters=parameters, config=config, @@ -1282,7 +1284,7 @@ def test_from_data(self, mocker): data=path_1_post, path="path_1", method="post", - tag="tag_2", + tag=tag_2, schemas=schemas_1, parameters=parameters_1, config=config, @@ -1291,7 +1293,7 @@ def test_from_data(self, mocker): data=path_2_get, path="path_2", method="get", - tag="default", + tag=tag_1, schemas=schemas_2, parameters=parameters_2, config=config, @@ -1300,8 +1302,8 @@ def test_from_data(self, mocker): ) assert result == ( { - "default": EndpointCollection("default", endpoints=[endpoint_1, endpoint_3]), - "tag_2": EndpointCollection("tag_2", endpoints=[endpoint_2]), + "default": EndpointCollection(tag=tag_1, endpoints=[endpoint_1, endpoint_3]), + "tag_2": EndpointCollection(tag=tag_2, endpoints=[endpoint_2]), }, schemas_3, parameters_3, @@ -1363,6 +1365,8 @@ def test_from_data_errors(self, mocker): schemas = mocker.MagicMock() parameters = mocker.MagicMock() config = MagicMock() + tag_1 = Tag.from_string(string="default", config=config) + tag_2 = Tag.from_string(string="tag_2", config=config) result, result_schemas, result_parameters = EndpointCollection.from_data( data=data, schemas=schemas, config=config, parameters=parameters @@ -1374,7 +1378,7 @@ def test_from_data_errors(self, mocker): data=path_1_put, path="path_1", method="put", - tag="default", + tag=tag_1, schemas=schemas, parameters=parameters, config=config, @@ -1383,7 +1387,7 @@ def test_from_data_errors(self, mocker): data=path_1_post, path="path_1", method="post", - tag="tag_2", + tag=tag_2, schemas=schemas_1, parameters=parameters_1, config=config, @@ -1392,7 +1396,7 @@ def test_from_data_errors(self, mocker): data=path_2_get, path="path_2", method="get", - tag="default", + tag=tag_1, schemas=schemas_2, parameters=parameters_2, config=config, @@ -1437,6 +1441,9 @@ def test_from_data_tags_snake_case_sanitizer(self, mocker): schemas = mocker.MagicMock() parameters = mocker.MagicMock() config = MagicMock() + tag_1 = Tag.from_string(string="default", config=config) + tag_2 = Tag.from_string(string="AMF Subscription Info (Document)", config=config) + tag_3 = Tag.from_string(string="3. ABC", config=config) result = EndpointCollection.from_data(data=data, schemas=schemas, parameters=parameters, config=config) @@ -1446,7 +1453,7 @@ def test_from_data_tags_snake_case_sanitizer(self, mocker): data=path_1_put, path="path_1", method="put", - tag="default", + tag=tag_1, schemas=schemas, parameters=parameters, config=config, @@ -1455,7 +1462,7 @@ def test_from_data_tags_snake_case_sanitizer(self, mocker): data=path_1_post, path="path_1", method="post", - tag="amf_subscription_info_document", + tag=tag_2, schemas=schemas_1, parameters=parameters_1, config=config, @@ -1464,7 +1471,7 @@ def test_from_data_tags_snake_case_sanitizer(self, mocker): data=path_2_get, path="path_2", method="get", - tag="tag3_abc", + tag=tag_3, schemas=schemas_2, parameters=parameters_2, config=config, @@ -1473,11 +1480,10 @@ def test_from_data_tags_snake_case_sanitizer(self, mocker): ) assert result == ( { - "default": EndpointCollection("default", endpoints=[endpoint_1]), - "amf_subscription_info_document": EndpointCollection( - "amf_subscription_info_document", endpoints=[endpoint_2] + "default": EndpointCollection(tag=tag_1, endpoints=[endpoint_1]), + "amf_subscription_info_document": EndpointCollection(tag=tag_2, endpoints=[endpoint_2] ), - "tag3_abc": EndpointCollection("tag3_abc", endpoints=[endpoint_3]), + "tag3_abc": EndpointCollection(tag=tag_3, endpoints=[endpoint_3]), }, schemas_3, parameters_3, diff --git a/tests/test_parser/test_properties/test_init.py b/tests/test_parser/test_properties/test_init.py index 85ffe8570..b625eaa05 100644 --- a/tests/test_parser/test_properties/test_init.py +++ b/tests/test_parser/test_properties/test_init.py @@ -763,43 +763,19 @@ def test_property_from_data_array(self, mocker): roots=roots, ) - def test_property_from_data_object(self, mocker): - from openapi_python_client.parser.properties import Schemas, property_from_data - - name = mocker.MagicMock() - required = mocker.MagicMock() - data = oai.Schema( - type="object", - ) - build_model_property = mocker.patch(f"{MODULE_NAME}.build_model_property") - mocker.patch("openapi_python_client.utils.remove_string_escapes", return_value=name) - schemas = Schemas() - config = MagicMock() - roots = {"root"} - process_properties = False - - response = property_from_data( - name=name, - required=required, - data=data, - schemas=schemas, - parent_name="parent", - config=config, - process_properties=process_properties, - roots=roots, - ) + @pytest.mark.parametrize( + "required, nullable, expected", + ( + (True, False, "Dict[str, Any]"), + (True, True, "Optional[Dict[str, Any]]"), + (False, True, "Union[Unset, None, Dict[str, Any]]"), + (False, False, "Union[Unset, Dict[str, Any]]"), + ), + ) + def test_property_from_data_object(self, dict_property_factory, required, nullable, expected): + p = dict_property_factory(required=required, nullable=nullable) - assert response == build_model_property.return_value - build_model_property.assert_called_once_with( - data=data, - name=name, - required=required, - schemas=schemas, - parent_name="parent", - config=config, - process_properties=process_properties, - roots=roots, - ) + assert p.get_type_string() == expected def test_property_from_data_union(self, mocker): from openapi_python_client.parser.properties import Schemas, property_from_data diff --git a/tests/test_parser/test_properties/test_model_property.py b/tests/test_parser/test_properties/test_model_property.py index 8e82145bb..d3d507c7c 100644 --- a/tests/test_parser/test_properties/test_model_property.py +++ b/tests/test_parser/test_properties/test_model_property.py @@ -389,7 +389,8 @@ def test_process_properties_model_property_roots(self, model_property_factory): from openapi_python_client.parser.properties.model_property import _process_properties roots = {"root"} - data = oai.Schema(properties={"test_model_property": oai.Schema.construct(type="object")}) + data = oai.Schema(properties={"test_model_property": oai.Schema.construct( + type="object", properties={"test_model_nested_property": oai.Schema.construct(type="string")})}) result = _process_properties(data=data, class_name="", schemas=Schemas(), config=Config(), roots=roots)