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|
|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

View File

@ -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).",

View File

@ -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

View File

@ -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}}

View File

@ -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,

View File

@ -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:
""""""
...

View File

@ -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,

View File

@ -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:
""""""
...

View File

@ -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,

View File

@ -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:
""""""
...

View File

@ -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,

View File

@ -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."""
...