Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python-fastapi] Fix api endpoint template #19139

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def {{operationId}}(
{{/hasAuthMethods}}
) -> {{returnType}}{{^returnType}}None{{/returnType}}:
{{#notes}}"""{{.}}"""
return Base{{classname}}.subclasses[0]().{{operationId}}({{#allParams}}{{>impl_argument}}{{^-last}}, {{/-last}}{{/allParams}}){{/notes}}{{^notes}}...{{/notes}}
{{/notes}}return await Base{{classname}}.subclasses[0]().{{operationId}}({{#allParams}}{{>impl_argument}}{{^-last}}, {{/-last}}{{/allParams}})
{{^-last}}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Base{{classname}}:
Base{{classname}}.subclasses = Base{{classname}}.subclasses + (cls,)
{{#operations}}
{{#operation}}
def {{operationId}}(
async def {{operationId}}(
self,
{{#allParams}}
{{>impl_argument_definition}},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ async def fake_query_param_default(
no_default: str = Query(None, description="no default value", alias="noDefault"),
) -> None:
""""""
return BaseFakeApi.subclasses[0]().fake_query_param_default(has_default, no_default)
return await BaseFakeApi.subclasses[0]().fake_query_param_default(has_default, no_default)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BaseFakeApi:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
BaseFakeApi.subclasses = BaseFakeApi.subclasses + (cls,)
def fake_query_param_default(
async def fake_query_param_default(
self,
has_default: str,
no_default: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async def add_pet(
),
) -> Pet:
""""""
return BasePetApi.subclasses[0]().add_pet(pet)
return await BasePetApi.subclasses[0]().add_pet(pet)


@router.delete(
Expand All @@ -70,7 +70,7 @@ async def delete_pet(
),
) -> None:
""""""
return BasePetApi.subclasses[0]().delete_pet(petId, api_key)
return await BasePetApi.subclasses[0]().delete_pet(petId, api_key)


@router.get(
Expand All @@ -90,7 +90,7 @@ async def find_pets_by_status(
),
) -> List[Pet]:
"""Multiple status values can be provided with comma separated strings"""
return BasePetApi.subclasses[0]().find_pets_by_status(status)
return await BasePetApi.subclasses[0]().find_pets_by_status(status)


@router.get(
Expand All @@ -110,7 +110,7 @@ async def find_pets_by_tags(
),
) -> List[Pet]:
"""Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."""
return BasePetApi.subclasses[0]().find_pets_by_tags(tags)
return await BasePetApi.subclasses[0]().find_pets_by_tags(tags)


@router.get(
Expand All @@ -131,7 +131,7 @@ async def get_pet_by_id(
),
) -> Pet:
"""Returns a single pet"""
return BasePetApi.subclasses[0]().get_pet_by_id(petId)
return await BasePetApi.subclasses[0]().get_pet_by_id(petId)


@router.put(
Expand All @@ -153,7 +153,7 @@ async def update_pet(
),
) -> Pet:
""""""
return BasePetApi.subclasses[0]().update_pet(pet)
return await BasePetApi.subclasses[0]().update_pet(pet)


@router.post(
Expand All @@ -174,7 +174,7 @@ async def update_pet_with_form(
),
) -> None:
""""""
return BasePetApi.subclasses[0]().update_pet_with_form(petId, name, status)
return await BasePetApi.subclasses[0]().update_pet_with_form(petId, name, status)


@router.post(
Expand All @@ -195,4 +195,4 @@ async def upload_file(
),
) -> ApiResponse:
""""""
return BasePetApi.subclasses[0]().upload_file(petId, additional_metadata, file)
return await BasePetApi.subclasses[0]().upload_file(petId, additional_metadata, file)
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class BasePetApi:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
BasePetApi.subclasses = BasePetApi.subclasses + (cls,)
def add_pet(
async def add_pet(
self,
pet: Pet,
) -> Pet:
""""""
...


def delete_pet(
async def delete_pet(
self,
petId: int,
api_key: str,
Expand All @@ -29,39 +29,39 @@ def delete_pet(
...


def find_pets_by_status(
async def find_pets_by_status(
self,
status: List[str],
) -> List[Pet]:
"""Multiple status values can be provided with comma separated strings"""
...


def find_pets_by_tags(
async def find_pets_by_tags(
self,
tags: List[str],
) -> List[Pet]:
"""Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."""
...


def get_pet_by_id(
async def get_pet_by_id(
self,
petId: int,
) -> Pet:
"""Returns a single pet"""
...


def update_pet(
async def update_pet(
self,
pet: Pet,
) -> Pet:
""""""
...


def update_pet_with_form(
async def update_pet_with_form(
self,
petId: int,
name: str,
Expand All @@ -71,7 +71,7 @@ def update_pet_with_form(
...


def upload_file(
async def upload_file(
self,
petId: int,
additional_metadata: str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def delete_order(
orderId: str = Path(..., description="ID of the order that needs to be deleted"),
) -> None:
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
return BaseStoreApi.subclasses[0]().delete_order(orderId)
return await BaseStoreApi.subclasses[0]().delete_order(orderId)


@router.get(
Expand All @@ -64,7 +64,7 @@ async def get_inventory(
),
) -> Dict[str, int]:
"""Returns a map of status codes to quantities"""
return BaseStoreApi.subclasses[0]().get_inventory()
return await BaseStoreApi.subclasses[0]().get_inventory()


@router.get(
Expand All @@ -82,7 +82,7 @@ async def get_order_by_id(
orderId: int = Path(..., description="ID of pet that needs to be fetched", ge=1, le=5),
) -> Order:
"""For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions"""
return BaseStoreApi.subclasses[0]().get_order_by_id(orderId)
return await BaseStoreApi.subclasses[0]().get_order_by_id(orderId)


@router.post(
Expand All @@ -99,4 +99,4 @@ async def place_order(
order: Order = Body(None, description="order placed for purchasing the pet"),
) -> Order:
""""""
return BaseStoreApi.subclasses[0]().place_order(order)
return await BaseStoreApi.subclasses[0]().place_order(order)
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ class BaseStoreApi:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
BaseStoreApi.subclasses = BaseStoreApi.subclasses + (cls,)
def delete_order(
async def delete_order(
self,
orderId: str,
) -> None:
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
...


def get_inventory(
async def get_inventory(
self,
) -> Dict[str, int]:
"""Returns a map of status codes to quantities"""
...


def get_order_by_id(
async def get_order_by_id(
self,
orderId: int,
) -> Order:
"""For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions"""
...


def place_order(
async def place_order(
self,
order: Order,
) -> Order:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def create_user(
),
) -> None:
"""This can only be done by the logged in user."""
return BaseUserApi.subclasses[0]().create_user(user)
return await BaseUserApi.subclasses[0]().create_user(user)


@router.post(
Expand All @@ -67,7 +67,7 @@ async def create_users_with_array_input(
),
) -> None:
""""""
return BaseUserApi.subclasses[0]().create_users_with_array_input(user)
return await BaseUserApi.subclasses[0]().create_users_with_array_input(user)


@router.post(
Expand All @@ -86,7 +86,7 @@ async def create_users_with_list_input(
),
) -> None:
""""""
return BaseUserApi.subclasses[0]().create_users_with_list_input(user)
return await BaseUserApi.subclasses[0]().create_users_with_list_input(user)


@router.delete(
Expand All @@ -106,7 +106,7 @@ async def delete_user(
),
) -> None:
"""This can only be done by the logged in user."""
return BaseUserApi.subclasses[0]().delete_user(username)
return await BaseUserApi.subclasses[0]().delete_user(username)


@router.get(
Expand All @@ -124,7 +124,7 @@ async def get_user_by_name(
username: str = Path(..., description="The name that needs to be fetched. Use user1 for testing."),
) -> User:
""""""
return BaseUserApi.subclasses[0]().get_user_by_name(username)
return await BaseUserApi.subclasses[0]().get_user_by_name(username)


@router.get(
Expand All @@ -142,7 +142,7 @@ async def login_user(
password: str = Query(None, description="The password for login in clear text", alias="password"),
) -> str:
""""""
return BaseUserApi.subclasses[0]().login_user(username, password)
return await BaseUserApi.subclasses[0]().login_user(username, password)


@router.get(
Expand All @@ -160,7 +160,7 @@ async def logout_user(
),
) -> None:
""""""
return BaseUserApi.subclasses[0]().logout_user()
return await BaseUserApi.subclasses[0]().logout_user()


@router.put(
Expand All @@ -181,4 +181,4 @@ async def update_user(
),
) -> None:
"""This can only be done by the logged in user."""
return BaseUserApi.subclasses[0]().update_user(username, user)
return await BaseUserApi.subclasses[0]().update_user(username, user)
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,47 @@ class BaseUserApi:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
BaseUserApi.subclasses = BaseUserApi.subclasses + (cls,)
def create_user(
async def create_user(
self,
user: User,
) -> None:
"""This can only be done by the logged in user."""
...


def create_users_with_array_input(
async def create_users_with_array_input(
self,
user: List[User],
) -> None:
""""""
...


def create_users_with_list_input(
async def create_users_with_list_input(
self,
user: List[User],
) -> None:
""""""
...


def delete_user(
async def delete_user(
self,
username: str,
) -> None:
"""This can only be done by the logged in user."""
...


def get_user_by_name(
async def get_user_by_name(
self,
username: str,
) -> User:
""""""
...


def login_user(
async def login_user(
self,
username: str,
password: str,
Expand All @@ -60,14 +60,14 @@ def login_user(
...


def logout_user(
async def logout_user(
self,
) -> None:
""""""
...


def update_user(
async def update_user(
self,
username: str,
user: User,
Expand Down
Loading