Skip to content

Commit 825d07f

Browse files
committed
Adjust test to expect ...
Since the initial PR, a new test was added expecting None rather than '...'. Changing test and samples as needed.
1 parent 04581c5 commit 825d07f

5 files changed

Lines changed: 28 additions & 55 deletions

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonFastAPIServerCodegenTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void testRequestBodyExampleInBodyMetadata() throws IOException {
7171
final Path p = Paths.get(outputPath + "src/openapi_server/apis/user_api.py");
7272

7373
assertFileExists(p);
74-
assertFileContains(p, "user: Annotated[List[User], Field(description=\"List of user object\")] = Body(None, description=\"List of user object\", examples=[[{\"username\": \"foo\"}, {\"username\": \"bar\"}]])");
74+
assertFileContains(p, "user: Annotated[List[User], Field(description=\"List of user object\")] = Body(..., description=\"List of user object\", examples=[[{\"username\": \"foo\"}, {\"username\": \"bar\"}]])");
7575
assertFileNotContains(p, "examples=[[[],");
7676
}
7777

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@
4646
response_model_by_alias=True,
4747
)
4848
async def fake_query_param_default(
49-
has_default: Annotated[Optional[StrictStr], Field(description="has default value")] = Query('Hello World', description="has default value", alias="hasDefault")
50-
,
51-
no_default: Annotated[Optional[StrictStr], Field(description="no default value")] = Query(None, description="no default value", alias="noDefault")
52-
,
49+
has_default: Annotated[Optional[StrictStr], Field(description="has default value")] = Query('Hello World', description="has default value", alias="hasDefault"),
50+
no_default: Annotated[Optional[StrictStr], Field(description="no default value")] = Query(None, description="no default value", alias="noDefault"),
5351
) -> None:
5452
""""""
5553
if not BaseFakeApi.subclasses:

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

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@
5050
response_model_by_alias=True,
5151
)
5252
async def update_pet(
53-
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(..., description="Pet object that needs to be added to the store")
54-
,
53+
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(..., description="Pet object that needs to be added to the store"),
5554
token_petstore_auth: TokenModel = Security(
5655
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
5756
),
@@ -73,8 +72,7 @@ async def update_pet(
7372
response_model_by_alias=True,
7473
)
7574
async def add_pet(
76-
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(..., description="Pet object that needs to be added to the store")
77-
,
75+
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(..., description="Pet object that needs to be added to the store"),
7876
token_petstore_auth: TokenModel = Security(
7977
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
8078
),
@@ -96,8 +94,7 @@ async def add_pet(
9694
response_model_by_alias=True,
9795
)
9896
async def find_pets_by_status(
99-
status: Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")] = Query(..., description="Status values that need to be considered for filter", alias="status")
100-
,
97+
status: Annotated[List[StrictStr], Field(description="Status values that need to be considered for filter")] = Query(..., description="Status values that need to be considered for filter", alias="status"),
10198
token_petstore_auth: TokenModel = Security(
10299
get_token_petstore_auth, scopes=["read:pets"]
103100
),
@@ -119,8 +116,7 @@ async def find_pets_by_status(
119116
response_model_by_alias=True,
120117
)
121118
async def find_pets_by_tags(
122-
tags: Annotated[List[StrictStr], Field(description="Tags to filter by")] = Query(..., description="Tags to filter by", alias="tags")
123-
,
119+
tags: Annotated[List[StrictStr], Field(description="Tags to filter by")] = Query(..., description="Tags to filter by", alias="tags"),
124120
token_petstore_auth: TokenModel = Security(
125121
get_token_petstore_auth, scopes=["read:pets"]
126122
),
@@ -143,8 +139,7 @@ async def find_pets_by_tags(
143139
response_model_by_alias=True,
144140
)
145141
async def get_pet_by_id(
146-
petId: Annotated[StrictInt, Field(description="ID of pet to return")] = Path(..., description="ID of pet to return")
147-
,
142+
petId: Annotated[StrictInt, Field(description="ID of pet to return")] = Path(..., description="ID of pet to return"),
148143
token_api_key: TokenModel = Security(
149144
get_token_api_key
150145
),
@@ -165,12 +160,9 @@ async def get_pet_by_id(
165160
response_model_by_alias=True,
166161
)
167162
async def update_pet_with_form(
168-
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")] = Path(..., description="ID of pet that needs to be updated")
169-
,
170-
name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")] = Form(None, description="Updated name of the pet")
171-
,
172-
status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")] = Form(None, description="Updated status of the pet")
173-
,
163+
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")] = Path(..., description="ID of pet that needs to be updated"),
164+
name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")] = Form(None, description="Updated name of the pet"),
165+
status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")] = Form(None, description="Updated status of the pet"),
174166
token_petstore_auth: TokenModel = Security(
175167
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
176168
),
@@ -191,10 +183,8 @@ async def update_pet_with_form(
191183
response_model_by_alias=True,
192184
)
193185
async def delete_pet(
194-
petId: Annotated[StrictInt, Field(description="Pet id to delete")] = Path(..., description="Pet id to delete")
195-
,
196-
api_key: Optional[StrictStr] = Header(None, description="")
197-
,
186+
petId: Annotated[StrictInt, Field(description="Pet id to delete")] = Path(..., description="Pet id to delete"),
187+
api_key: Optional[StrictStr] = Header(None, description=""),
198188
token_petstore_auth: TokenModel = Security(
199189
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
200190
),
@@ -215,12 +205,9 @@ async def delete_pet(
215205
response_model_by_alias=True,
216206
)
217207
async def upload_file(
218-
petId: Annotated[StrictInt, Field(description="ID of pet to update")] = Path(..., description="ID of pet to update")
219-
,
220-
additional_metadata: Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = Form(None, description="Additional data to pass to server")
221-
,
222-
file: Annotated[Optional[Union[StrictBytes, StrictStr, Tuple[StrictStr, StrictBytes]]], Field(description="file to upload")] = Form(None, description="file to upload")
223-
,
208+
petId: Annotated[StrictInt, Field(description="ID of pet to update")] = Path(..., description="ID of pet to update"),
209+
additional_metadata: Annotated[Optional[StrictStr], Field(description="Additional data to pass to server")] = Form(None, description="Additional data to pass to server"),
210+
file: Annotated[Optional[Union[StrictBytes, StrictStr, Tuple[StrictStr, StrictBytes]]], Field(description="file to upload")] = Form(None, description="file to upload"),
224211
token_petstore_auth: TokenModel = Security(
225212
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
226213
),

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ async def get_inventory(
6767
response_model_by_alias=True,
6868
)
6969
async def place_order(
70-
order: Annotated[Order, Field(description="order placed for purchasing the pet")] = Body(..., description="order placed for purchasing the pet")
71-
,
70+
order: Annotated[Order, Field(description="order placed for purchasing the pet")] = Body(..., description="order placed for purchasing the pet"),
7271
) -> Order:
7372
""""""
7473
if not BaseStoreApi.subclasses:
@@ -88,8 +87,7 @@ async def place_order(
8887
response_model_by_alias=True,
8988
)
9089
async def get_order_by_id(
91-
orderId: Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")] = Path(..., description="ID of pet that needs to be fetched", ge=1, le=5)
92-
,
90+
orderId: Annotated[int, Field(le=5, strict=True, ge=1, description="ID of pet that needs to be fetched")] = Path(..., description="ID of pet that needs to be fetched", ge=1, le=5),
9391
) -> Order:
9492
"""For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions"""
9593
if not BaseStoreApi.subclasses:
@@ -108,8 +106,7 @@ async def get_order_by_id(
108106
response_model_by_alias=True,
109107
)
110108
async def delete_order(
111-
orderId: Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")] = Path(..., description="ID of the order that needs to be deleted")
112-
,
109+
orderId: Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")] = Path(..., description="ID of the order that needs to be deleted"),
113110
) -> None:
114111
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
115112
if not BaseStoreApi.subclasses:

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

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
response_model_by_alias=True,
4747
)
4848
async def create_user(
49-
user: Annotated[User, Field(description="Created user object")] = Body(..., description="Created user object")
50-
,
49+
user: Annotated[User, Field(description="Created user object")] = Body(..., description="Created user object"),
5150
token_api_key: TokenModel = Security(
5251
get_token_api_key
5352
),
@@ -68,8 +67,7 @@ async def create_user(
6867
response_model_by_alias=True,
6968
)
7069
async def create_users_with_array_input(
71-
user: Annotated[List[User], Field(description="List of user object")] = Body(..., description="List of user object")
72-
,
70+
user: Annotated[List[User], Field(description="List of user object")] = Body(..., description="List of user object"),
7371
token_api_key: TokenModel = Security(
7472
get_token_api_key
7573
),
@@ -90,8 +88,7 @@ async def create_users_with_array_input(
9088
response_model_by_alias=True,
9189
)
9290
async def create_users_with_list_input(
93-
user: Annotated[List[User], Field(description="List of user object")] = Body(..., description="List of user object")
94-
,
91+
user: Annotated[List[User], Field(description="List of user object")] = Body(..., description="List of user object"),
9592
token_api_key: TokenModel = Security(
9693
get_token_api_key
9794
),
@@ -113,10 +110,8 @@ async def create_users_with_list_input(
113110
response_model_by_alias=True,
114111
)
115112
async def login_user(
116-
username: Annotated[str, Field(strict=True, description="The user name for login")] = Query(..., description="The user name for login", alias="username", regex=r"^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$")
117-
,
118-
password: Annotated[StrictStr, Field(description="The password for login in clear text")] = Query(..., description="The password for login in clear text", alias="password")
119-
,
113+
username: Annotated[str, Field(strict=True, description="The user name for login")] = Query(..., description="The user name for login", alias="username", regex=r"^[a-zA-Z0-9]+[a-zA-Z0-9\.\-_]*[a-zA-Z0-9]+$"),
114+
password: Annotated[StrictStr, Field(description="The password for login in clear text")] = Query(..., description="The password for login in clear text", alias="password"),
120115
) -> str:
121116
""""""
122117
if not BaseUserApi.subclasses:
@@ -156,8 +151,7 @@ async def logout_user(
156151
response_model_by_alias=True,
157152
)
158153
async def get_user_by_name(
159-
username: Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")] = Path(..., description="The name that needs to be fetched. Use user1 for testing.")
160-
,
154+
username: Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")] = Path(..., description="The name that needs to be fetched. Use user1 for testing."),
161155
) -> User:
162156
""""""
163157
if not BaseUserApi.subclasses:
@@ -176,10 +170,8 @@ async def get_user_by_name(
176170
response_model_by_alias=True,
177171
)
178172
async def update_user(
179-
username: Annotated[StrictStr, Field(description="name that need to be deleted")] = Path(..., description="name that need to be deleted")
180-
,
181-
user: Annotated[User, Field(description="Updated user object")] = Body(..., description="Updated user object")
182-
,
173+
username: Annotated[StrictStr, Field(description="name that need to be deleted")] = Path(..., description="name that need to be deleted"),
174+
user: Annotated[User, Field(description="Updated user object")] = Body(..., description="Updated user object"),
183175
token_api_key: TokenModel = Security(
184176
get_token_api_key
185177
),
@@ -201,8 +193,7 @@ async def update_user(
201193
response_model_by_alias=True,
202194
)
203195
async def delete_user(
204-
username: Annotated[StrictStr, Field(description="The name that needs to be deleted")] = Path(..., description="The name that needs to be deleted")
205-
,
196+
username: Annotated[StrictStr, Field(description="The name that needs to be deleted")] = Path(..., description="The name that needs to be deleted"),
206197
token_api_key: TokenModel = Security(
207198
get_token_api_key
208199
),

0 commit comments

Comments
 (0)