diff --git a/docs/generators/python-fastapi.md b/docs/generators/python-fastapi.md index 540b5aa1b16..2ca99719228 100644 --- a/docs/generators/python-fastapi.md +++ b/docs/generators/python-fastapi.md @@ -32,7 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |serverPort|TCP port to listen to in app.run| |8080| |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| -|sourceFolder|directory for generated python source code| |generated-code/python-fastapi| +|sourceFolder|directory for generated python source code| |src| ## IMPORT MAPPING diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java index 4c07f75f68c..07126e67398 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java @@ -155,7 +155,7 @@ public class PythonFastAPIServerCodegen extends AbstractPythonCodegen { addOption(CodegenConstants.SOURCE_FOLDER, "directory for generated python source code", - outputFolder); + DEFAULT_SOURCE_FOLDER); addOption(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE, "python package name for the implementation code (convention: snake_case).", 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 43d6bae63bf..78b8f3a0352 100644 --- a/modules/openapi-generator/src/main/resources/python-fastapi/api.mustache +++ b/modules/openapi-generator/src/main/resources/python-fastapi/api.mustache @@ -5,11 +5,9 @@ import importlib import pkgutil from {{apiPackage}}.{{classFilename}}_{{baseSuffix}} import Base{{classname}} -{{^isLibrary}} -{{#fastapiImplementationPackage}} +{{^isLibrary}}{{#fastapiImplementationPackage}} import {{fastapiImplementationPackage}} -{{/fastapiImplementationPackage}} -{{/isLibrary}} +{{/fastapiImplementationPackage}}{{/isLibrary}} from fastapi import ( # noqa: F401 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 96f2b5638f8..908efdb6476 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,8 +18,8 @@ class Base{{classname}}{{#isLibrary}}(ABC){{/isLibrary}}: Base{{classname}}.subclasses = Base{{classname}}.subclasses + (cls,) {{#operations}} -{{#operation}} - {{#isLibrary}}@abstractmethod{{/isLibrary}} +{{#operation}}{{#isLibrary}} + @abstractmethod{{/isLibrary}} async def {{operationId}}( self, {{#allParams}} @@ -30,7 +30,7 @@ class Base{{classname}}{{#isLibrary}}(ABC){{/isLibrary}}: ...{{/notes}}{{^notes}}...{{/notes}} {{^-last}} - {{/-last}} {{/operation}} {{/operations}} + diff --git a/samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api.py b/samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api.py index 9b21b38523c..f3a400fa443 100644 --- a/samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api.py +++ b/samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api.py @@ -5,9 +5,11 @@ import importlib import pkgutil from openapi_server.apis.fake_api_base import BaseFakeApi + import openapi_server.impl + from fastapi import ( # noqa: F401 APIRouter, Body, 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 20dd90b86d0..7838330564b 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 @@ -14,7 +14,7 @@ class BaseFakeApi: super().__init_subclass__(**kwargs) BaseFakeApi.subclasses = BaseFakeApi.subclasses + (cls,) - + async def fake_query_param_default( self, has_default: Annotated[Optional[StrictStr], Field(description="has default value")], @@ -22,3 +22,4 @@ class BaseFakeApi: ) -> 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 d804f94866c..03c0971abd9 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 @@ -5,9 +5,11 @@ import importlib import pkgutil from openapi_server.apis.pet_api_base import BasePetApi + import openapi_server.impl + from fastapi import ( # noqa: F401 APIRouter, Body, 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 df1e303d36a..0c317fb0a44 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 @@ -16,7 +16,7 @@ class BasePetApi: super().__init_subclass__(**kwargs) BasePetApi.subclasses = BasePetApi.subclasses + (cls,) - + async def add_pet( self, pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")], @@ -25,7 +25,6 @@ class BasePetApi: ... - async def delete_pet( self, petId: Annotated[StrictInt, Field(description="Pet id to delete")], @@ -35,7 +34,6 @@ class BasePetApi: ... - async def find_pets_by_status( self, status: Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")], @@ -44,7 +42,6 @@ class BasePetApi: ... - async def find_pets_by_tags( self, tags: Annotated[List[StrictStr], Field(description="Tags to filter by")], @@ -53,7 +50,6 @@ class BasePetApi: ... - async def get_pet_by_id( self, petId: Annotated[StrictInt, Field(description="ID of pet to return")], @@ -62,7 +58,6 @@ class BasePetApi: ... - async def update_pet( self, pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")], @@ -71,7 +66,6 @@ class BasePetApi: ... - async def update_pet_with_form( self, petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")], @@ -82,7 +76,6 @@ class BasePetApi: ... - async def upload_file( self, petId: Annotated[StrictInt, Field(description="ID of pet to update")], @@ -91,3 +84,4 @@ class BasePetApi: ) -> 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 ab1ecfdc854..c222e0cdcd8 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 @@ -5,9 +5,11 @@ import importlib import pkgutil from openapi_server.apis.store_api_base import BaseStoreApi + import openapi_server.impl + from fastapi import ( # noqa: F401 APIRouter, Body, 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 74321606528..b6dbdbf7fa0 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 @@ -15,7 +15,7 @@ class BaseStoreApi: super().__init_subclass__(**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")], @@ -24,7 +24,6 @@ class BaseStoreApi: ... - async def get_inventory( self, ) -> Dict[str, int]: @@ -32,7 +31,6 @@ class BaseStoreApi: ... - 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")], @@ -41,10 +39,10 @@ class BaseStoreApi: ... - async def place_order( self, 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 427eb4ddf40..1975ab0f285 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 @@ -5,9 +5,11 @@ import importlib import pkgutil from openapi_server.apis.user_api_base import BaseUserApi + import openapi_server.impl + from fastapi import ( # noqa: F401 APIRouter, Body, 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 53c43ee6254..7a16c71c698 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 @@ -15,7 +15,7 @@ class BaseUserApi: super().__init_subclass__(**kwargs) BaseUserApi.subclasses = BaseUserApi.subclasses + (cls,) - + async def create_user( self, user: Annotated[User, Field(description="Created user object")], @@ -24,7 +24,6 @@ class BaseUserApi: ... - async def create_users_with_array_input( self, user: Annotated[List[User], Field(description="List of user object")], @@ -33,7 +32,6 @@ class BaseUserApi: ... - async def create_users_with_list_input( self, user: Annotated[List[User], Field(description="List of user object")], @@ -42,7 +40,6 @@ class BaseUserApi: ... - async def delete_user( self, username: Annotated[StrictStr, Field(description="The name that needs to be deleted")], @@ -51,7 +48,6 @@ class BaseUserApi: ... - async def get_user_by_name( self, username: Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")], @@ -60,7 +56,6 @@ class BaseUserApi: ... - async def login_user( self, username: Annotated[str, Field(strict=True, description="The user name for login")], @@ -70,7 +65,6 @@ class BaseUserApi: ... - async def logout_user( self, ) -> None: @@ -78,7 +72,6 @@ class BaseUserApi: ... - async def update_user( self, username: Annotated[StrictStr, Field(description="name that need to be deleted")], @@ -86,3 +79,4 @@ class BaseUserApi: ) -> None: """This can only be done by the logged in user.""" ... +