diff --git a/modules/openapi-generator/src/main/resources/python-fastapi/api.mustache b/modules/openapi-generator/src/main/resources/python-fastapi/api.mustache index 7c87ef7543cd..d809367abe5f 100644 --- a/modules/openapi-generator/src/main/resources/python-fastapi/api.mustache +++ b/modules/openapi-generator/src/main/resources/python-fastapi/api.mustache @@ -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}} diff --git a/modules/openapi-generator/src/main/resources/python-fastapi/base_api.mustache b/modules/openapi-generator/src/main/resources/python-fastapi/base_api.mustache index d1d95c12eff8..5c83dfaa2140 100644 --- a/modules/openapi-generator/src/main/resources/python-fastapi/base_api.mustache +++ b/modules/openapi-generator/src/main/resources/python-fastapi/base_api.mustache @@ -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}} diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api_base.py b/samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api_base.py index 1c71537aa944..f3c0a519499b 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api_base.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api_base.py @@ -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: """""" ... diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api.py b/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api.py index a4aa3a6e71ec..ab4c16e7deb0 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api.py @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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) diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api_base.py b/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api_base.py index 608762c7a8db..225b2d3ddcd5 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api_base.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api_base.py @@ -18,6 +18,7 @@ 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: """""" ... @@ -25,8 +26,8 @@ async def add_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: """""" ... @@ -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""" ... @@ -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.""" ... @@ -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""" ... @@ -59,6 +63,7 @@ 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: """""" ... @@ -66,9 +71,8 @@ async def update_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: """""" ... @@ -76,9 +80,8 @@ async def update_pet_with_form( 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: """""" ... diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api.py b/samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api.py index 21d2aceb380d..68601a090d43 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api.py @@ -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( diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api_base.py b/samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api_base.py index 20629628e50e..4aa62ddb5dfb 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api_base.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api_base.py @@ -16,7 +16,7 @@ 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""" ... @@ -24,6 +24,8 @@ async def delete_order( async def get_inventory( self, + + token_api_key: str ) -> Dict[str, int]: """Returns a map of status codes to quantities""" ... @@ -31,7 +33,7 @@ async def get_inventory( 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""" ... @@ -39,7 +41,7 @@ async def get_order_by_id( 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: """""" ... diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api.py b/samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api.py index 8f848f0131de..5a61f09ebee3 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api.py @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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) diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api_base.py b/samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api_base.py index fb86c924a58f..4e330d69c3f7 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api_base.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/apis/user_api_base.py @@ -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.""" ... @@ -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: """""" ... @@ -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: """""" ... @@ -41,6 +44,7 @@ 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.""" ... @@ -48,7 +52,7 @@ async def delete_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: """""" ... @@ -56,8 +60,7 @@ async def get_user_by_name( 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: """""" ... @@ -65,6 +68,8 @@ async def login_user( async def logout_user( self, + + token_api_key: str ) -> None: """""" ... @@ -72,8 +77,8 @@ async def logout_user( 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.""" ...