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

[BUG][Python-fastapi] Ensure that authentication tokens are passed from the endpoint to implementation #20317

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 @@ -68,7 +68,7 @@ async def {{operationId}}(
{{#notes}}"""{{.}}"""
{{/notes}}if not Base{{classname}}.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await Base{{classname}}.subclasses[0]().{{operationId}}({{#allParams}}{{>impl_argument}}{{^-last}}, {{/-last}}{{/allParams}})
return await Base{{classname}}.subclasses[0]().{{operationId}}({{#allParams}}{{>impl_argument}}{{^-last}}, {{/-last}}{{/allParams}}{{#authMethods}}{{#hasParams}}, {{/hasParams}}{{#authMethods}}token_{{name}}=token_{{name}}{{^-last}}, {{/-last}}{{/authMethods}}{{/authMethods}})
{{^-last}}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ class Base{{classname}}:
async def {{operationId}}(
self,
{{#allParams}}
{{>impl_argument_definition}},
{{/allParams}}
{{>impl_argument_definition}}{{^-last}},{{/-last}}{{/allParams}}{{#authMethods}}{{#hasParams}},{{/hasParams}}{{#authMethods}}
token_{{name}}: str{{^-last}},{{/-last}}{{/authMethods}}{{/authMethods}}
) -> {{returnType}}{{^returnType}}None{{/returnType}}:
{{#notes}}"""{{.}}"""
...{{/notes}}{{^notes}}...{{/notes}}
{{^-last}}


{{/-last}}
{{/operation}}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def __init_subclass__(cls, **kwargs):
BaseFakeApi.subclasses = BaseFakeApi.subclasses + (cls,)
async def fake_query_param_default(
self,
has_default: Annotated[Optional[StrictStr], Field(description="has default value")],
no_default: Annotated[Optional[StrictStr], Field(description="no default value")],
has_default: Annotated[Optional[StrictStr], Field(description="has default value")], no_default: Annotated[Optional[StrictStr], Field(description="no default value")]
) -> None:
""""""
...
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def add_pet(
""""""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().add_pet(pet)
return await BasePetApi.subclasses[0]().add_pet(pet, token_petstore_auth=token_petstore_auth)


@router.delete(
Expand All @@ -78,7 +78,7 @@ async def delete_pet(
""""""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().delete_pet(petId, api_key)
return await BasePetApi.subclasses[0]().delete_pet(petId, api_key, token_petstore_auth=token_petstore_auth)


@router.get(
Expand All @@ -100,7 +100,7 @@ async def find_pets_by_status(
"""Multiple status values can be provided with comma separated strings"""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().find_pets_by_status(status)
return await BasePetApi.subclasses[0]().find_pets_by_status(status, token_petstore_auth=token_petstore_auth)


@router.get(
Expand All @@ -122,7 +122,7 @@ async def find_pets_by_tags(
"""Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().find_pets_by_tags(tags)
return await BasePetApi.subclasses[0]().find_pets_by_tags(tags, token_petstore_auth=token_petstore_auth)


@router.get(
Expand All @@ -145,7 +145,7 @@ async def get_pet_by_id(
"""Returns a single pet"""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().get_pet_by_id(petId)
return await BasePetApi.subclasses[0]().get_pet_by_id(petId, token_api_key=token_api_key)


@router.put(
Expand All @@ -169,7 +169,7 @@ async def update_pet(
""""""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().update_pet(pet)
return await BasePetApi.subclasses[0]().update_pet(pet, token_petstore_auth=token_petstore_auth)


@router.post(
Expand All @@ -192,7 +192,7 @@ async def update_pet_with_form(
""""""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().update_pet_with_form(petId, name, status)
return await BasePetApi.subclasses[0]().update_pet_with_form(petId, name, status, token_petstore_auth=token_petstore_auth)


@router.post(
Expand All @@ -215,4 +215,4 @@ async def upload_file(
""""""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().upload_file(petId, additional_metadata, file)
return await BasePetApi.subclasses[0]().upload_file(petId, additional_metadata, file, token_petstore_auth=token_petstore_auth)
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ def __init_subclass__(cls, **kwargs):
async def add_pet(
self,
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
token_petstore_auth: str
) -> Pet:
""""""
...


async def delete_pet(
self,
petId: Annotated[StrictInt, Field(description="Pet id to delete")],
api_key: Optional[StrictStr],
petId: Annotated[StrictInt, Field(description="Pet id to delete")], api_key: Optional[StrictStr],
token_petstore_auth: str
) -> None:
""""""
...
Expand All @@ -35,6 +36,7 @@ async def delete_pet(
async def find_pets_by_status(
self,
status: Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")],
token_petstore_auth: str
) -> List[Pet]:
"""Multiple status values can be provided with comma separated strings"""
...
Expand All @@ -43,6 +45,7 @@ async def find_pets_by_status(
async def find_pets_by_tags(
self,
tags: Annotated[List[StrictStr], Field(description="Tags to filter by")],
token_petstore_auth: str
) -> List[Pet]:
"""Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing."""
...
Expand All @@ -51,6 +54,7 @@ async def find_pets_by_tags(
async def get_pet_by_id(
self,
petId: Annotated[StrictInt, Field(description="ID of pet to return")],
token_api_key: str
) -> Pet:
"""Returns a single pet"""
...
Expand All @@ -59,26 +63,25 @@ async def get_pet_by_id(
async def update_pet(
self,
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
token_petstore_auth: str
) -> Pet:
""""""
...


async def update_pet_with_form(
self,
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")],
name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")],
status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")],
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")], name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")], status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")],
token_petstore_auth: str
) -> None:
""""""
...


async def upload_file(
self,
petId: Annotated[StrictInt, Field(description="ID of pet to update")],
additional_metadata: Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")],
file: Annotated[Optional[Union[StrictBytes, StrictStr, Tuple[StrictStr, StrictBytes]]], Field(description="file to upload")],
petId: Annotated[StrictInt, Field(description="ID of pet to update")], additional_metadata: Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")], file: Annotated[Optional[Union[StrictBytes, StrictStr, Tuple[StrictStr, StrictBytes]]], Field(description="file to upload")],
token_petstore_auth: str
) -> ApiResponse:
""""""
...
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async def get_inventory(
"""Returns a map of status codes to quantities"""
if not BaseStoreApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BaseStoreApi.subclasses[0]().get_inventory()
return await BaseStoreApi.subclasses[0]().get_inventory(token_api_key=token_api_key)


@router.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,32 @@ def __init_subclass__(cls, **kwargs):
BaseStoreApi.subclasses = BaseStoreApi.subclasses + (cls,)
async def delete_order(
self,
orderId: Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")],
orderId: Annotated[StrictStr, Field(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"""
...


async def get_inventory(
self,

token_api_key: str
) -> Dict[str, int]:
"""Returns a map of status codes to quantities"""
...


async def get_order_by_id(
self,
orderId: Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")],
orderId: Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")]
) -> Order:
"""For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions"""
...


async def place_order(
self,
order: Annotated[Order, Field(description="order placed for purchasing the pet")],
order: Annotated[Order, Field(description="order placed for purchasing the pet")]
) -> Order:
""""""
...
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def create_user(
"""This can only be done by the logged in user."""
if not BaseUserApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BaseUserApi.subclasses[0]().create_user(user)
return await BaseUserApi.subclasses[0]().create_user(user, token_api_key=token_api_key)


@router.post(
Expand All @@ -75,7 +75,7 @@ async def create_users_with_array_input(
""""""
if not BaseUserApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BaseUserApi.subclasses[0]().create_users_with_array_input(user)
return await BaseUserApi.subclasses[0]().create_users_with_array_input(user, token_api_key=token_api_key)


@router.post(
Expand All @@ -96,7 +96,7 @@ async def create_users_with_list_input(
""""""
if not BaseUserApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BaseUserApi.subclasses[0]().create_users_with_list_input(user)
return await BaseUserApi.subclasses[0]().create_users_with_list_input(user, token_api_key=token_api_key)


@router.delete(
Expand All @@ -118,7 +118,7 @@ async def delete_user(
"""This can only be done by the logged in user."""
if not BaseUserApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BaseUserApi.subclasses[0]().delete_user(username)
return await BaseUserApi.subclasses[0]().delete_user(username, token_api_key=token_api_key)


@router.get(
Expand Down Expand Up @@ -178,7 +178,7 @@ async def logout_user(
""""""
if not BaseUserApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BaseUserApi.subclasses[0]().logout_user()
return await BaseUserApi.subclasses[0]().logout_user(token_api_key=token_api_key)


@router.put(
Expand All @@ -201,4 +201,4 @@ async def update_user(
"""This can only be done by the logged in user."""
if not BaseUserApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BaseUserApi.subclasses[0]().update_user(username, user)
return await BaseUserApi.subclasses[0]().update_user(username, user, token_api_key=token_api_key)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init_subclass__(cls, **kwargs):
async def create_user(
self,
user: Annotated[User, Field(description="Created user object")],
token_api_key: str
) -> None:
"""This can only be done by the logged in user."""
...
Expand All @@ -25,6 +26,7 @@ async def create_user(
async def create_users_with_array_input(
self,
user: Annotated[List[User], Field(description="List of user object")],
token_api_key: str
) -> None:
""""""
...
Expand All @@ -33,6 +35,7 @@ async def create_users_with_array_input(
async def create_users_with_list_input(
self,
user: Annotated[List[User], Field(description="List of user object")],
token_api_key: str
) -> None:
""""""
...
Expand All @@ -41,39 +44,41 @@ async def create_users_with_list_input(
async def delete_user(
self,
username: Annotated[StrictStr, Field(description="The name that needs to be deleted")],
token_api_key: str
) -> None:
"""This can only be done by the logged in user."""
...


async def get_user_by_name(
self,
username: Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")],
username: Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")]
) -> User:
""""""
...


async def login_user(
self,
username: Annotated[str, Field(strict=True, description="The user name for login")],
password: Annotated[StrictStr, Field(description="The password for login in clear text")],
username: Annotated[str, Field(strict=True, description="The user name for login")], password: Annotated[StrictStr, Field(description="The password for login in clear text")]
) -> str:
""""""
...


async def logout_user(
self,

token_api_key: str
) -> None:
""""""
...


async def update_user(
self,
username: Annotated[StrictStr, Field(description="name that need to be deleted")],
user: Annotated[User, Field(description="Updated user object")],
username: Annotated[StrictStr, Field(description="name that need to be deleted")], user: Annotated[User, Field(description="Updated user object")],
token_api_key: str
) -> None:
"""This can only be done by the logged in user."""
...