Skip to content

Commit 7267e80

Browse files
authored
[python-fastapi] Ensure path param is ... instead of None (#17532)
Fixes #16029 Code from #16029 (comment)
1 parent af48001 commit 7267e80

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{{#isPathParam}}{{baseName}}{{/isPathParam}}{{^isPathParam}}{{paramName}}{{/isPathParam}}: {{>param_type}} = {{#isPathParam}}Path{{/isPathParam}}{{#isHeaderParam}}Header{{/isHeaderParam}}{{#isFormParam}}Form{{/isFormParam}}{{#isQueryParam}}Query{{/isQueryParam}}{{#isCookieParam}}Cookie{{/isCookieParam}}{{#isBodyParam}}Body{{/isBodyParam}}({{&defaultValue}}{{^defaultValue}}None{{/defaultValue}}, description="{{description}}"{{#isQueryParam}}, alias="{{baseName}}"{{/isQueryParam}}{{#isLong}}{{#minimum}}, ge={{.}}{{/minimum}}{{#maximum}}, le={{.}}{{/maximum}}{{/isLong}}{{#isInteger}}{{#minimum}}, ge={{.}}{{/minimum}}{{#maximum}}, le={{.}}{{/maximum}}{{/isInteger}}{{#pattern}}, regex=r"{{.}}"{{/pattern}}{{#minLength}}, min_length={{.}}{{/minLength}}{{#maxLength}}, max_length={{.}}{{/maxLength}})
1+
{{#isPathParam}}{{baseName}}{{/isPathParam}}{{^isPathParam}}{{paramName}}{{/isPathParam}}: {{>param_type}} = {{#isPathParam}}Path{{/isPathParam}}{{#isHeaderParam}}Header{{/isHeaderParam}}{{#isFormParam}}Form{{/isFormParam}}{{#isQueryParam}}Query{{/isQueryParam}}{{#isCookieParam}}Cookie{{/isCookieParam}}{{#isBodyParam}}Body{{/isBodyParam}}({{&defaultValue}}{{^defaultValue}}{{#isPathParam}}...{{/isPathParam}}{{^isPathParam}}None{{/isPathParam}}{{/defaultValue}}, description="{{description}}"{{#isQueryParam}}, alias="{{baseName}}"{{/isQueryParam}}{{#isLong}}{{#minimum}}, ge={{.}}{{/minimum}}{{#maximum}}, le={{.}}{{/maximum}}{{/isLong}}{{#isInteger}}{{#minimum}}, ge={{.}}{{/minimum}}{{#maximum}}, le={{.}}{{/maximum}}{{/isInteger}}{{#pattern}}, regex=r"{{.}}"{{/pattern}}{{#minLength}}, min_length={{.}}{{/minLength}}{{#maxLength}}, max_length={{.}}{{/maxLength}})

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async def add_pet(
6363
response_model_by_alias=True,
6464
)
6565
async def delete_pet(
66-
petId: int = Path(None, description="Pet id to delete"),
66+
petId: int = Path(..., description="Pet id to delete"),
6767
api_key: str = Header(None, description=""),
6868
token_petstore_auth: TokenModel = Security(
6969
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
@@ -125,7 +125,7 @@ async def find_pets_by_tags(
125125
response_model_by_alias=True,
126126
)
127127
async def get_pet_by_id(
128-
petId: int = Path(None, description="ID of pet to return"),
128+
petId: int = Path(..., description="ID of pet to return"),
129129
token_api_key: TokenModel = Security(
130130
get_token_api_key
131131
),
@@ -166,7 +166,7 @@ async def update_pet(
166166
response_model_by_alias=True,
167167
)
168168
async def update_pet_with_form(
169-
petId: int = Path(None, description="ID of pet that needs to be updated"),
169+
petId: int = Path(..., description="ID of pet that needs to be updated"),
170170
name: str = Form(None, description="Updated name of the pet"),
171171
status: str = Form(None, description="Updated status of the pet"),
172172
token_petstore_auth: TokenModel = Security(
@@ -187,7 +187,7 @@ async def update_pet_with_form(
187187
response_model_by_alias=True,
188188
)
189189
async def upload_file(
190-
petId: int = Path(None, description="ID of pet to update"),
190+
petId: int = Path(..., description="ID of pet to update"),
191191
additional_metadata: str = Form(None, description="Additional data to pass to server"),
192192
file: str = Form(None, description="file to upload"),
193193
token_petstore_auth: TokenModel = Security(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
response_model_by_alias=True,
4444
)
4545
async def delete_order(
46-
orderId: str = Path(None, description="ID of the order that needs to be deleted"),
46+
orderId: str = Path(..., description="ID of the order that needs to be deleted"),
4747
) -> None:
4848
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
4949
return BaseStoreApi.subclasses[0]().delete_order(orderId)
@@ -79,7 +79,7 @@ async def get_inventory(
7979
response_model_by_alias=True,
8080
)
8181
async def get_order_by_id(
82-
orderId: int = Path(None, description="ID of pet that needs to be fetched", ge=1, le=5),
82+
orderId: int = Path(..., description="ID of pet that needs to be fetched", ge=1, le=5),
8383
) -> Order:
8484
"""For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions"""
8585
return BaseStoreApi.subclasses[0]().get_order_by_id(orderId)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async def create_users_with_list_input(
100100
response_model_by_alias=True,
101101
)
102102
async def delete_user(
103-
username: str = Path(None, description="The name that needs to be deleted"),
103+
username: str = Path(..., description="The name that needs to be deleted"),
104104
token_api_key: TokenModel = Security(
105105
get_token_api_key
106106
),
@@ -121,7 +121,7 @@ async def delete_user(
121121
response_model_by_alias=True,
122122
)
123123
async def get_user_by_name(
124-
username: str = Path(None, description="The name that needs to be fetched. Use user1 for testing."),
124+
username: str = Path(..., description="The name that needs to be fetched. Use user1 for testing."),
125125
) -> User:
126126
""""""
127127
return BaseUserApi.subclasses[0]().get_user_by_name(username)
@@ -174,7 +174,7 @@ async def logout_user(
174174
response_model_by_alias=True,
175175
)
176176
async def update_user(
177-
username: str = Path(None, description="name that need to be deleted"),
177+
username: str = Path(..., description="name that need to be deleted"),
178178
user: User = Body(None, description="Updated user object"),
179179
token_api_key: TokenModel = Security(
180180
get_token_api_key

0 commit comments

Comments
 (0)