diff --git a/example/client/api/pet_api.py b/example/client/api/pet_api.py index fbb7e34..011a4be 100644 --- a/example/client/api/pet_api.py +++ b/example/client/api/pet_api.py @@ -27,11 +27,7 @@ def _build_for_delete_pet(self, pet_id: int, api_key: str = None) -> Awaitable[N headers["api_key"] = str(api_key) return self.api_client.request( - type_=None, - method="DELETE", - url="/pet/{petId}", - path_params=path_params, - headers=headers, + type_=None, method="DELETE", url="/pet/{petId}", path_params=path_params, headers=headers, ) def _build_for_find_pets_by_status(self, status: List[str]) -> Awaitable[List[m.Pet]]: @@ -40,12 +36,7 @@ def _build_for_find_pets_by_status(self, status: List[str]) -> Awaitable[List[m. """ query_params = {"status": str(status)} - return self.api_client.request( - type_=List[m.Pet], - method="GET", - url="/pet/findByStatus", - params=query_params, - ) + return self.api_client.request(type_=List[m.Pet], method="GET", url="/pet/findByStatus", params=query_params,) def _build_for_find_pets_by_tags(self, tags: List[str]) -> Awaitable[List[m.Pet]]: """ @@ -53,12 +44,7 @@ def _build_for_find_pets_by_tags(self, tags: List[str]) -> Awaitable[List[m.Pet] """ query_params = {"tags": str(tags)} - return self.api_client.request( - type_=List[m.Pet], - method="GET", - url="/pet/findByTags", - params=query_params, - ) + return self.api_client.request(type_=List[m.Pet], method="GET", url="/pet/findByTags", params=query_params,) def _build_for_get_pet_by_id(self, pet_id: int) -> Awaitable[m.Pet]: """ @@ -66,12 +52,7 @@ def _build_for_get_pet_by_id(self, pet_id: int) -> Awaitable[m.Pet]: """ path_params = {"petId": str(pet_id)} - return self.api_client.request( - type_=m.Pet, - method="GET", - url="/pet/{petId}", - path_params=path_params, - ) + return self.api_client.request(type_=m.Pet, method="GET", url="/pet/{petId}", path_params=path_params,) def _build_for_update_pet(self, body: m.Pet) -> Awaitable[None]: body = jsonable_encoder(body) diff --git a/example/client/api/store_api.py b/example/client/api/store_api.py index a459cce..094ec32 100644 --- a/example/client/api/store_api.py +++ b/example/client/api/store_api.py @@ -21,23 +21,14 @@ def _build_for_delete_order(self, order_id: int) -> Awaitable[None]: path_params = {"orderId": str(order_id)} return self.api_client.request( - type_=None, - method="DELETE", - url="/store/order/{orderId}", - path_params=path_params, + type_=None, method="DELETE", url="/store/order/{orderId}", path_params=path_params, ) - def _build_for_get_inventory( - self, - ) -> Awaitable[Dict[str, int]]: + def _build_for_get_inventory(self,) -> Awaitable[Dict[str, int]]: """ Returns a map of status codes to quantities """ - return self.api_client.request( - type_=Dict[str, int], - method="GET", - url="/store/inventory", - ) + return self.api_client.request(type_=Dict[str, int], method="GET", url="/store/inventory",) def _build_for_get_order_by_id(self, order_id: int) -> Awaitable[m.Order]: """ @@ -46,10 +37,7 @@ def _build_for_get_order_by_id(self, order_id: int) -> Awaitable[m.Order]: path_params = {"orderId": str(order_id)} return self.api_client.request( - type_=m.Order, - method="GET", - url="/store/order/{orderId}", - path_params=path_params, + type_=m.Order, method="GET", url="/store/order/{orderId}", path_params=path_params, ) def _build_for_place_order(self, body: m.Order) -> Awaitable[m.Order]: @@ -65,9 +53,7 @@ async def delete_order(self, order_id: int) -> None: """ return await self._build_for_delete_order(order_id=order_id) - async def get_inventory( - self, - ) -> Dict[str, int]: + async def get_inventory(self,) -> Dict[str, int]: """ Returns a map of status codes to quantities """ @@ -91,9 +77,7 @@ def delete_order(self, order_id: int) -> None: coroutine = self._build_for_delete_order(order_id=order_id) return get_event_loop().run_until_complete(coroutine) - def get_inventory( - self, - ) -> Dict[str, int]: + def get_inventory(self,) -> Dict[str, int]: """ Returns a map of status codes to quantities """ diff --git a/example/client/api/user_api.py b/example/client/api/user_api.py index 46c464b..f0ce35d 100644 --- a/example/client/api/user_api.py +++ b/example/client/api/user_api.py @@ -38,41 +38,20 @@ def _build_for_delete_user(self, username: str) -> Awaitable[None]: """ path_params = {"username": str(username)} - return self.api_client.request( - type_=None, - method="DELETE", - url="/user/{username}", - path_params=path_params, - ) + return self.api_client.request(type_=None, method="DELETE", url="/user/{username}", path_params=path_params,) def _build_for_get_user_by_name(self, username: str) -> Awaitable[m.User]: path_params = {"username": str(username)} - return self.api_client.request( - type_=m.User, - method="GET", - url="/user/{username}", - path_params=path_params, - ) + return self.api_client.request(type_=m.User, method="GET", url="/user/{username}", path_params=path_params,) def _build_for_login_user(self, username: str, password: str) -> Awaitable[str]: query_params = {"username": str(username), "password": str(password)} - return self.api_client.request( - type_=str, - method="GET", - url="/user/login", - params=query_params, - ) + return self.api_client.request(type_=str, method="GET", url="/user/login", params=query_params,) - def _build_for_logout_user( - self, - ) -> Awaitable[None]: - return self.api_client.request( - type_=None, - method="GET", - url="/user/logout", - ) + def _build_for_logout_user(self,) -> Awaitable[None]: + return self.api_client.request(type_=None, method="GET", url="/user/logout",) def _build_for_update_user(self, username: str, body: m.User) -> Awaitable[None]: """ @@ -112,9 +91,7 @@ async def get_user_by_name(self, username: str) -> m.User: async def login_user(self, username: str, password: str) -> str: return await self._build_for_login_user(username=username, password=password) - async def logout_user( - self, - ) -> None: + async def logout_user(self,) -> None: return await self._build_for_logout_user() async def update_user(self, username: str, body: m.User) -> None: @@ -155,9 +132,7 @@ def login_user(self, username: str, password: str) -> str: coroutine = self._build_for_login_user(username=username, password=password) return get_event_loop().run_until_complete(coroutine) - def logout_user( - self, - ) -> None: + def logout_user(self,) -> None: coroutine = self._build_for_logout_user() return get_event_loop().run_until_complete(coroutine) diff --git a/example/client/api_client.py b/example/client/api_client.py index fe24faf..2cce70a 100644 --- a/example/client/api_client.py +++ b/example/client/api_client.py @@ -59,7 +59,7 @@ async def request( # noqa F811 if path_params is None: path_params = {} url = (self.host or "") + url.format(**path_params) - request = Request(method, url, **kwargs) + request = self._async_client.build_request(method, url, **kwargs) return await self.send(request, type_) @overload diff --git a/openapi-python-templates/api_client.mustache b/openapi-python-templates/api_client.mustache index bcd43eb..33d9bed 100644 --- a/openapi-python-templates/api_client.mustache +++ b/openapi-python-templates/api_client.mustache @@ -53,7 +53,7 @@ class ApiClient: if path_params is None: path_params = {} url = (self.host or "") + url.format(**path_params) - request = Request(method, url, **kwargs) + request = self._async_client.build_request(method, url, **kwargs) return await self.send(request, type_) @overload diff --git a/tests/test_auth.py b/tests/test_auth.py index 3dec8a0..70158f3 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -1,6 +1,7 @@ from typing import Dict from fastapi.openapi.models import OAuthFlowPassword + from generated_client.api_client import ApiClient from generated_client.auth import AuthMiddleware, AuthState diff --git a/tests/test_client.py b/tests/test_client.py index e09d6c3..f289157 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -6,9 +6,10 @@ from asyncio import get_event_loop from typing import Tuple, Type +from mypy.ipc import TracebackType + import generated_client.models as models from generated_client.api_client import ApiClient, SyncApis -from mypy.ipc import TracebackType class Client(SyncApis):