Skip to content

Commit 05e30be

Browse files
fixed default source folder and empty lines in templates
1 parent 8ffc957 commit 05e30be

12 files changed

Lines changed: 23 additions & 30 deletions

File tree

docs/generators/python-fastapi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
3232
|serverPort|TCP port to listen to in app.run| |8080|
3333
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
3434
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
35-
|sourceFolder|directory for generated python source code| |generated-code/python-fastapi|
35+
|sourceFolder|directory for generated python source code| |src|
3636

3737
## IMPORT MAPPING
3838

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public PythonFastAPIServerCodegen() {
155155

156156
addOption(CodegenConstants.SOURCE_FOLDER,
157157
"directory for generated python source code",
158-
outputFolder);
158+
DEFAULT_SOURCE_FOLDER);
159159

160160
addOption(CodegenConstants.FASTAPI_IMPLEMENTATION_PACKAGE,
161161
"python package name for the implementation code (convention: snake_case).",

modules/openapi-generator/src/main/resources/python-fastapi/api.mustache

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import importlib
55
import pkgutil
66

77
from {{apiPackage}}.{{classFilename}}_{{baseSuffix}} import Base{{classname}}
8-
{{^isLibrary}}
9-
{{#fastapiImplementationPackage}}
8+
{{^isLibrary}}{{#fastapiImplementationPackage}}
109
import {{fastapiImplementationPackage}}
11-
{{/fastapiImplementationPackage}}
12-
{{/isLibrary}}
10+
{{/fastapiImplementationPackage}}{{/isLibrary}}
1311

1412

1513
from fastapi import ( # noqa: F401

modules/openapi-generator/src/main/resources/python-fastapi/base_api.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class Base{{classname}}{{#isLibrary}}(ABC){{/isLibrary}}:
1818
Base{{classname}}.subclasses = Base{{classname}}.subclasses + (cls,)
1919

2020
{{#operations}}
21-
{{#operation}}
22-
{{#isLibrary}}@abstractmethod{{/isLibrary}}
21+
{{#operation}}{{#isLibrary}}
22+
@abstractmethod{{/isLibrary}}
2323
async def {{operationId}}(
2424
self,
2525
{{#allParams}}
@@ -30,7 +30,7 @@ class Base{{classname}}{{#isLibrary}}(ABC){{/isLibrary}}:
3030
...{{/notes}}{{^notes}}...{{/notes}}
3131
{{^-last}}
3232

33-
3433
{{/-last}}
3534
{{/operation}}
3635
{{/operations}}
36+

samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import pkgutil
66

77
from openapi_server.apis.fake_api_base import BaseFakeApi
8+
89
import openapi_server.impl
910

1011

12+
1113
from fastapi import ( # noqa: F401
1214
APIRouter,
1315
Body,

samples/server/petstore/python-fastapi/src/openapi_server/apis/fake_api_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ def __init_subclass__(cls, **kwargs):
1414
super().__init_subclass__(**kwargs)
1515
BaseFakeApi.subclasses = BaseFakeApi.subclasses + (cls,)
1616

17-
17+
1818
async def fake_query_param_default(
1919
self,
2020
has_default: Annotated[Optional[StrictStr], Field(description="has default value")],
2121
no_default: Annotated[Optional[StrictStr], Field(description="no default value")],
2222
) -> None:
2323
""""""
2424
...
25+

samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import pkgutil
66

77
from openapi_server.apis.pet_api_base import BasePetApi
8+
89
import openapi_server.impl
910

1011

12+
1113
from fastapi import ( # noqa: F401
1214
APIRouter,
1315
Body,

samples/server/petstore/python-fastapi/src/openapi_server/apis/pet_api_base.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init_subclass__(cls, **kwargs):
1616
super().__init_subclass__(**kwargs)
1717
BasePetApi.subclasses = BasePetApi.subclasses + (cls,)
1818

19-
19+
2020
async def add_pet(
2121
self,
2222
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
@@ -25,7 +25,6 @@ async def add_pet(
2525
...
2626

2727

28-
2928
async def delete_pet(
3029
self,
3130
petId: Annotated[StrictInt, Field(description="Pet id to delete")],
@@ -35,7 +34,6 @@ async def delete_pet(
3534
...
3635

3736

38-
3937
async def find_pets_by_status(
4038
self,
4139
status: Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")],
@@ -44,7 +42,6 @@ async def find_pets_by_status(
4442
...
4543

4644

47-
4845
async def find_pets_by_tags(
4946
self,
5047
tags: Annotated[List[StrictStr], Field(description="Tags to filter by")],
@@ -53,7 +50,6 @@ async def find_pets_by_tags(
5350
...
5451

5552

56-
5753
async def get_pet_by_id(
5854
self,
5955
petId: Annotated[StrictInt, Field(description="ID of pet to return")],
@@ -62,7 +58,6 @@ async def get_pet_by_id(
6258
...
6359

6460

65-
6661
async def update_pet(
6762
self,
6863
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
@@ -71,7 +66,6 @@ async def update_pet(
7166
...
7267

7368

74-
7569
async def update_pet_with_form(
7670
self,
7771
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")],
@@ -82,7 +76,6 @@ async def update_pet_with_form(
8276
...
8377

8478

85-
8679
async def upload_file(
8780
self,
8881
petId: Annotated[StrictInt, Field(description="ID of pet to update")],
@@ -91,3 +84,4 @@ async def upload_file(
9184
) -> ApiResponse:
9285
""""""
9386
...
87+

samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import pkgutil
66

77
from openapi_server.apis.store_api_base import BaseStoreApi
8+
89
import openapi_server.impl
910

1011

12+
1113
from fastapi import ( # noqa: F401
1214
APIRouter,
1315
Body,

samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api_base.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init_subclass__(cls, **kwargs):
1515
super().__init_subclass__(**kwargs)
1616
BaseStoreApi.subclasses = BaseStoreApi.subclasses + (cls,)
1717

18-
18+
1919
async def delete_order(
2020
self,
2121
orderId: Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")],
@@ -24,15 +24,13 @@ async def delete_order(
2424
...
2525

2626

27-
2827
async def get_inventory(
2928
self,
3029
) -> Dict[str, int]:
3130
"""Returns a map of status codes to quantities"""
3231
...
3332

3433

35-
3634
async def get_order_by_id(
3735
self,
3836
orderId: Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")],
@@ -41,10 +39,10 @@ async def get_order_by_id(
4139
...
4240

4341

44-
4542
async def place_order(
4643
self,
4744
order: Annotated[Order, Field(description="order placed for purchasing the pet")],
4845
) -> Order:
4946
""""""
5047
...
48+

0 commit comments

Comments
 (0)