[python-fastapi] Ensure path param is ... instead of None (#17532)

Fixes #16029
Code from https://github.com/OpenAPITools/openapi-generator/issues/16029#issuecomment-1776271921
This commit is contained in:
Sander Hoentjen
2024-01-31 04:03:14 +01:00
committed by GitHub
parent af4800132d
commit 7267e809c3
4 changed files with 10 additions and 10 deletions

View File

@@ -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}}) {{#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}})

View File

@@ -63,7 +63,7 @@ async def add_pet(
response_model_by_alias=True, response_model_by_alias=True,
) )
async def delete_pet( async def delete_pet(
petId: int = Path(None, description="Pet id to delete"), petId: int = Path(..., description="Pet id to delete"),
api_key: str = Header(None, description=""), api_key: str = Header(None, description=""),
token_petstore_auth: TokenModel = Security( token_petstore_auth: TokenModel = Security(
get_token_petstore_auth, scopes=["write:pets", "read:pets"] get_token_petstore_auth, scopes=["write:pets", "read:pets"]
@@ -125,7 +125,7 @@ async def find_pets_by_tags(
response_model_by_alias=True, response_model_by_alias=True,
) )
async def get_pet_by_id( async def get_pet_by_id(
petId: int = Path(None, description="ID of pet to return"), petId: int = Path(..., description="ID of pet to return"),
token_api_key: TokenModel = Security( token_api_key: TokenModel = Security(
get_token_api_key get_token_api_key
), ),
@@ -166,7 +166,7 @@ async def update_pet(
response_model_by_alias=True, response_model_by_alias=True,
) )
async def update_pet_with_form( async def update_pet_with_form(
petId: int = Path(None, description="ID of pet that needs to be updated"), petId: int = Path(..., description="ID of pet that needs to be updated"),
name: str = Form(None, description="Updated name of the pet"), name: str = Form(None, description="Updated name of the pet"),
status: str = Form(None, description="Updated status of the pet"), status: str = Form(None, description="Updated status of the pet"),
token_petstore_auth: TokenModel = Security( token_petstore_auth: TokenModel = Security(
@@ -187,7 +187,7 @@ async def update_pet_with_form(
response_model_by_alias=True, response_model_by_alias=True,
) )
async def upload_file( async def upload_file(
petId: int = Path(None, description="ID of pet to update"), petId: int = Path(..., description="ID of pet to update"),
additional_metadata: str = Form(None, description="Additional data to pass to server"), additional_metadata: str = Form(None, description="Additional data to pass to server"),
file: str = Form(None, description="file to upload"), file: str = Form(None, description="file to upload"),
token_petstore_auth: TokenModel = Security( token_petstore_auth: TokenModel = Security(

View File

@@ -43,7 +43,7 @@ for _, name, _ in pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + "."):
response_model_by_alias=True, response_model_by_alias=True,
) )
async def delete_order( async def delete_order(
orderId: str = Path(None, description="ID of the order that needs to be deleted"), orderId: str = Path(..., description="ID of the order that needs to be deleted"),
) -> None: ) -> None:
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors""" """For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
return BaseStoreApi.subclasses[0]().delete_order(orderId) return BaseStoreApi.subclasses[0]().delete_order(orderId)
@@ -79,7 +79,7 @@ async def get_inventory(
response_model_by_alias=True, response_model_by_alias=True,
) )
async def get_order_by_id( async def get_order_by_id(
orderId: int = Path(None, description="ID of pet that needs to be fetched", ge=1, le=5), orderId: int = Path(..., description="ID of pet that needs to be fetched", ge=1, le=5),
) -> Order: ) -> Order:
"""For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions""" """For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions"""
return BaseStoreApi.subclasses[0]().get_order_by_id(orderId) return BaseStoreApi.subclasses[0]().get_order_by_id(orderId)

View File

@@ -100,7 +100,7 @@ async def create_users_with_list_input(
response_model_by_alias=True, response_model_by_alias=True,
) )
async def delete_user( async def delete_user(
username: str = Path(None, description="The name that needs to be deleted"), username: str = Path(..., description="The name that needs to be deleted"),
token_api_key: TokenModel = Security( token_api_key: TokenModel = Security(
get_token_api_key get_token_api_key
), ),
@@ -121,7 +121,7 @@ async def delete_user(
response_model_by_alias=True, response_model_by_alias=True,
) )
async def get_user_by_name( async def get_user_by_name(
username: str = Path(None, description="The name that needs to be fetched. Use user1 for testing."), username: str = Path(..., description="The name that needs to be fetched. Use user1 for testing."),
) -> User: ) -> User:
"""""" """"""
return BaseUserApi.subclasses[0]().get_user_by_name(username) return BaseUserApi.subclasses[0]().get_user_by_name(username)
@@ -174,7 +174,7 @@ async def logout_user(
response_model_by_alias=True, response_model_by_alias=True,
) )
async def update_user( async def update_user(
username: str = Path(None, description="name that need to be deleted"), username: str = Path(..., description="name that need to be deleted"),
user: User = Body(None, description="Updated user object"), user: User = Body(None, description="Updated user object"),
token_api_key: TokenModel = Security( token_api_key: TokenModel = Security(
get_token_api_key get_token_api_key