fixed default source folder and empty lines in templates

This commit is contained in:
Aditya Mayukh Som 2025-04-12 19:00:28 +05:30
parent 8ffc9579d8
commit 05e30becb3
No known key found for this signature in database
GPG Key ID: 53F2894D9280123A
12 changed files with 23 additions and 30 deletions

View File

@ -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| |serverPort|TCP port to listen to in app.run| |8080|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true| |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments 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 ## IMPORT MAPPING

View File

@ -155,7 +155,7 @@ public class PythonFastAPIServerCodegen extends AbstractPythonCodegen {
addOption(CodegenConstants.SOURCE_FOLDER, addOption(CodegenConstants.SOURCE_FOLDER,
"directory for generated python source code", "directory for generated python source code",
outputFolder); DEFAULT_SOURCE_FOLDER);
addOption(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE, addOption(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE,
"python package name for the implementation code (convention: snake_case).", "python package name for the implementation code (convention: snake_case).",

View File

@ -5,11 +5,9 @@ import importlib
import pkgutil import pkgutil
from {{apiPackage}}.{{classFilename}}_{{baseSuffix}} import Base{{classname}} from {{apiPackage}}.{{classFilename}}_{{baseSuffix}} import Base{{classname}}
{{^isLibrary}} {{^isLibrary}}{{#fastapiImplementationPackage}}
{{#fastapiImplementationPackage}}
import {{fastapiImplementationPackage}} import {{fastapiImplementationPackage}}
{{/fastapiImplementationPackage}} {{/fastapiImplementationPackage}}{{/isLibrary}}
{{/isLibrary}}
from fastapi import ( # noqa: F401 from fastapi import ( # noqa: F401

View File

@ -18,8 +18,8 @@ class Base{{classname}}{{#isLibrary}}(ABC){{/isLibrary}}:
Base{{classname}}.subclasses = Base{{classname}}.subclasses + (cls,) Base{{classname}}.subclasses = Base{{classname}}.subclasses + (cls,)
{{#operations}} {{#operations}}
{{#operation}} {{#operation}}{{#isLibrary}}
{{#isLibrary}}@abstractmethod{{/isLibrary}} @abstractmethod{{/isLibrary}}
async def {{operationId}}( async def {{operationId}}(
self, self,
{{#allParams}} {{#allParams}}
@ -30,7 +30,7 @@ class Base{{classname}}{{#isLibrary}}(ABC){{/isLibrary}}:
...{{/notes}}{{^notes}}...{{/notes}} ...{{/notes}}{{^notes}}...{{/notes}}
{{^-last}} {{^-last}}
{{/-last}} {{/-last}}
{{/operation}} {{/operation}}
{{/operations}} {{/operations}}

View File

@ -5,9 +5,11 @@ import importlib
import pkgutil import pkgutil
from openapi_server.apis.fake_api_base import BaseFakeApi from openapi_server.apis.fake_api_base import BaseFakeApi
import openapi_server.impl import openapi_server.impl
from fastapi import ( # noqa: F401 from fastapi import ( # noqa: F401
APIRouter, APIRouter,
Body, Body,

View File

@ -22,3 +22,4 @@ class BaseFakeApi:
) -> None: ) -> None:
"""""" """"""
... ...

View File

@ -5,9 +5,11 @@ import importlib
import pkgutil import pkgutil
from openapi_server.apis.pet_api_base import BasePetApi from openapi_server.apis.pet_api_base import BasePetApi
import openapi_server.impl import openapi_server.impl
from fastapi import ( # noqa: F401 from fastapi import ( # noqa: F401
APIRouter, APIRouter,
Body, Body,

View File

@ -25,7 +25,6 @@ class BasePetApi:
... ...
async def delete_pet( async def delete_pet(
self, self,
petId: Annotated[StrictInt, Field(description="Pet id to delete")], petId: Annotated[StrictInt, Field(description="Pet id to delete")],
@ -35,7 +34,6 @@ class BasePetApi:
... ...
async def find_pets_by_status( async def find_pets_by_status(
self, self,
status: Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")], 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( async def find_pets_by_tags(
self, self,
tags: Annotated[List[StrictStr], Field(description="Tags to filter by")], tags: Annotated[List[StrictStr], Field(description="Tags to filter by")],
@ -53,7 +50,6 @@ class BasePetApi:
... ...
async def get_pet_by_id( async def get_pet_by_id(
self, self,
petId: Annotated[StrictInt, Field(description="ID of pet to return")], petId: Annotated[StrictInt, Field(description="ID of pet to return")],
@ -62,7 +58,6 @@ class BasePetApi:
... ...
async def update_pet( async def update_pet(
self, self,
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")], 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( async def update_pet_with_form(
self, self,
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")], petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")],
@ -82,7 +76,6 @@ class BasePetApi:
... ...
async def upload_file( async def upload_file(
self, self,
petId: Annotated[StrictInt, Field(description="ID of pet to update")], petId: Annotated[StrictInt, Field(description="ID of pet to update")],
@ -91,3 +84,4 @@ class BasePetApi:
) -> ApiResponse: ) -> ApiResponse:
"""""" """"""
... ...

View File

@ -5,9 +5,11 @@ import importlib
import pkgutil import pkgutil
from openapi_server.apis.store_api_base import BaseStoreApi from openapi_server.apis.store_api_base import BaseStoreApi
import openapi_server.impl import openapi_server.impl
from fastapi import ( # noqa: F401 from fastapi import ( # noqa: F401
APIRouter, APIRouter,
Body, Body,

View File

@ -24,7 +24,6 @@ class BaseStoreApi:
... ...
async def get_inventory( async def get_inventory(
self, self,
) -> Dict[str, int]: ) -> Dict[str, int]:
@ -32,7 +31,6 @@ class BaseStoreApi:
... ...
async def get_order_by_id( async def get_order_by_id(
self, 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")],
@ -41,10 +39,10 @@ class BaseStoreApi:
... ...
async def place_order( async def place_order(
self, self,
order: Annotated[Order, Field(description="order placed for purchasing the pet")], order: Annotated[Order, Field(description="order placed for purchasing the pet")],
) -> Order: ) -> Order:
"""""" """"""
... ...

View File

@ -5,9 +5,11 @@ import importlib
import pkgutil import pkgutil
from openapi_server.apis.user_api_base import BaseUserApi from openapi_server.apis.user_api_base import BaseUserApi
import openapi_server.impl import openapi_server.impl
from fastapi import ( # noqa: F401 from fastapi import ( # noqa: F401
APIRouter, APIRouter,
Body, Body,

View File

@ -24,7 +24,6 @@ class BaseUserApi:
... ...
async def create_users_with_array_input( async def create_users_with_array_input(
self, self,
user: Annotated[List[User], Field(description="List of user object")], user: Annotated[List[User], Field(description="List of user object")],
@ -33,7 +32,6 @@ class BaseUserApi:
... ...
async def create_users_with_list_input( async def create_users_with_list_input(
self, self,
user: Annotated[List[User], Field(description="List of user object")], user: Annotated[List[User], Field(description="List of user object")],
@ -42,7 +40,6 @@ class BaseUserApi:
... ...
async def delete_user( async def delete_user(
self, self,
username: Annotated[StrictStr, Field(description="The name that needs to be deleted")], username: Annotated[StrictStr, Field(description="The name that needs to be deleted")],
@ -51,7 +48,6 @@ class BaseUserApi:
... ...
async def get_user_by_name( async def get_user_by_name(
self, 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.")],
@ -60,7 +56,6 @@ class BaseUserApi:
... ...
async def login_user( async def login_user(
self, self,
username: Annotated[str, Field(strict=True, description="The user name for login")], username: Annotated[str, Field(strict=True, description="The user name for login")],
@ -70,7 +65,6 @@ class BaseUserApi:
... ...
async def logout_user( async def logout_user(
self, self,
) -> None: ) -> None:
@ -78,7 +72,6 @@ class BaseUserApi:
... ...
async def update_user( async def update_user(
self, self,
username: Annotated[StrictStr, Field(description="name that need to be deleted")], username: Annotated[StrictStr, Field(description="name that need to be deleted")],
@ -86,3 +79,4 @@ class BaseUserApi:
) -> None: ) -> None:
"""This can only be done by the logged in user.""" """This can only be done by the logged in user."""
... ...