mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-26 01:19:05 +00:00
* [python-fastapi] Fix: Skip sorting of path operations (#22163)
Make use of helpful code added in
243f501aef to skip sorting of path
parameters. In FastAPI, order matters, see link for details:
https://fastapi.tiangolo.com/tutorial/path-params/?h=path#order-matters
Issue: https://github.com/OpenAPITools/openapi-generator/issues/22163
* Update samples after previous commit
Reading comprehension is hard. I missed the part of step 3 where
samples would be updated in response to the change I had previous
submitted.
Via this commit, update samples to match expectations. The order of
various endpoint implementations is now changed in the sample, matchcing
the order in the yaml files that created them.
This commit is contained in:
@@ -37,6 +37,30 @@ for _, name, _ in pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + "."):
|
||||
importlib.import_module(name)
|
||||
|
||||
|
||||
@router.put(
|
||||
"/pet",
|
||||
responses={
|
||||
200: {"model": Pet, "description": "successful operation"},
|
||||
400: {"description": "Invalid ID supplied"},
|
||||
404: {"description": "Pet not found"},
|
||||
405: {"description": "Validation exception"},
|
||||
},
|
||||
tags=["pet"],
|
||||
summary="Update an existing pet",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def update_pet(
|
||||
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(None, description="Pet object that needs to be added to the store"),
|
||||
token_petstore_auth: TokenModel = Security(
|
||||
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
|
||||
),
|
||||
) -> Pet:
|
||||
""""""
|
||||
if not BasePetApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BasePetApi.subclasses[0]().update_pet(pet)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/pet",
|
||||
responses={
|
||||
@@ -59,28 +83,6 @@ async def add_pet(
|
||||
return await BasePetApi.subclasses[0]().add_pet(pet)
|
||||
|
||||
|
||||
@router.delete(
|
||||
"/pet/{petId}",
|
||||
responses={
|
||||
400: {"description": "Invalid pet value"},
|
||||
},
|
||||
tags=["pet"],
|
||||
summary="Deletes a pet",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def delete_pet(
|
||||
petId: Annotated[StrictInt, Field(description="Pet id to delete")] = Path(..., description="Pet id to delete"),
|
||||
api_key: Optional[StrictStr] = Header(None, description=""),
|
||||
token_petstore_auth: TokenModel = Security(
|
||||
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
|
||||
),
|
||||
) -> None:
|
||||
""""""
|
||||
if not BasePetApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BasePetApi.subclasses[0]().delete_pet(petId, api_key)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/pet/findByStatus",
|
||||
responses={
|
||||
@@ -148,30 +150,6 @@ async def get_pet_by_id(
|
||||
return await BasePetApi.subclasses[0]().get_pet_by_id(petId)
|
||||
|
||||
|
||||
@router.put(
|
||||
"/pet",
|
||||
responses={
|
||||
200: {"model": Pet, "description": "successful operation"},
|
||||
400: {"description": "Invalid ID supplied"},
|
||||
404: {"description": "Pet not found"},
|
||||
405: {"description": "Validation exception"},
|
||||
},
|
||||
tags=["pet"],
|
||||
summary="Update an existing pet",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def update_pet(
|
||||
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")] = Body(None, description="Pet object that needs to be added to the store"),
|
||||
token_petstore_auth: TokenModel = Security(
|
||||
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
|
||||
),
|
||||
) -> Pet:
|
||||
""""""
|
||||
if not BasePetApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BasePetApi.subclasses[0]().update_pet(pet)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/pet/{petId}",
|
||||
responses={
|
||||
@@ -195,6 +173,28 @@ async def update_pet_with_form(
|
||||
return await BasePetApi.subclasses[0]().update_pet_with_form(petId, name, status)
|
||||
|
||||
|
||||
@router.delete(
|
||||
"/pet/{petId}",
|
||||
responses={
|
||||
400: {"description": "Invalid pet value"},
|
||||
},
|
||||
tags=["pet"],
|
||||
summary="Deletes a pet",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def delete_pet(
|
||||
petId: Annotated[StrictInt, Field(description="Pet id to delete")] = Path(..., description="Pet id to delete"),
|
||||
api_key: Optional[StrictStr] = Header(None, description=""),
|
||||
token_petstore_auth: TokenModel = Security(
|
||||
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
|
||||
),
|
||||
) -> None:
|
||||
""""""
|
||||
if not BasePetApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BasePetApi.subclasses[0]().delete_pet(petId, api_key)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/pet/{petId}/uploadImage",
|
||||
responses={
|
||||
|
||||
@@ -15,7 +15,7 @@ class BasePetApi:
|
||||
def __init_subclass__(cls, **kwargs):
|
||||
super().__init_subclass__(**kwargs)
|
||||
BasePetApi.subclasses = BasePetApi.subclasses + (cls,)
|
||||
async def add_pet(
|
||||
async def update_pet(
|
||||
self,
|
||||
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
|
||||
) -> Pet:
|
||||
@@ -23,11 +23,10 @@ class BasePetApi:
|
||||
...
|
||||
|
||||
|
||||
async def delete_pet(
|
||||
async def add_pet(
|
||||
self,
|
||||
petId: Annotated[StrictInt, Field(description="Pet id to delete")],
|
||||
api_key: Optional[StrictStr],
|
||||
) -> None:
|
||||
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
|
||||
) -> Pet:
|
||||
""""""
|
||||
...
|
||||
|
||||
@@ -56,14 +55,6 @@ class BasePetApi:
|
||||
...
|
||||
|
||||
|
||||
async def update_pet(
|
||||
self,
|
||||
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
|
||||
) -> Pet:
|
||||
""""""
|
||||
...
|
||||
|
||||
|
||||
async def update_pet_with_form(
|
||||
self,
|
||||
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")],
|
||||
@@ -74,6 +65,15 @@ class BasePetApi:
|
||||
...
|
||||
|
||||
|
||||
async def delete_pet(
|
||||
self,
|
||||
petId: Annotated[StrictInt, Field(description="Pet id to delete")],
|
||||
api_key: Optional[StrictStr],
|
||||
) -> None:
|
||||
""""""
|
||||
...
|
||||
|
||||
|
||||
async def upload_file(
|
||||
self,
|
||||
petId: Annotated[StrictInt, Field(description="ID of pet to update")],
|
||||
|
||||
@@ -36,25 +36,6 @@ for _, name, _ in pkgutil.iter_modules(ns_pkg.__path__, ns_pkg.__name__ + "."):
|
||||
importlib.import_module(name)
|
||||
|
||||
|
||||
@router.delete(
|
||||
"/store/order/{orderId}",
|
||||
responses={
|
||||
400: {"description": "Invalid ID supplied"},
|
||||
404: {"description": "Order not found"},
|
||||
},
|
||||
tags=["store"],
|
||||
summary="Delete purchase order by ID",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def delete_order(
|
||||
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"),
|
||||
) -> None:
|
||||
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
|
||||
if not BaseStoreApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BaseStoreApi.subclasses[0]().delete_order(orderId)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/store/inventory",
|
||||
responses={
|
||||
@@ -75,6 +56,25 @@ async def get_inventory(
|
||||
return await BaseStoreApi.subclasses[0]().get_inventory()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/store/order",
|
||||
responses={
|
||||
200: {"model": Order, "description": "successful operation"},
|
||||
400: {"description": "Invalid Order"},
|
||||
},
|
||||
tags=["store"],
|
||||
summary="Place an order for a pet",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def place_order(
|
||||
order: Annotated[Order, Field(description="order placed for purchasing the pet")] = Body(None, description="order placed for purchasing the pet"),
|
||||
) -> Order:
|
||||
""""""
|
||||
if not BaseStoreApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BaseStoreApi.subclasses[0]().place_order(order)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/store/order/{orderId}",
|
||||
responses={
|
||||
@@ -95,20 +95,20 @@ async def get_order_by_id(
|
||||
return await BaseStoreApi.subclasses[0]().get_order_by_id(orderId)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/store/order",
|
||||
@router.delete(
|
||||
"/store/order/{orderId}",
|
||||
responses={
|
||||
200: {"model": Order, "description": "successful operation"},
|
||||
400: {"description": "Invalid Order"},
|
||||
400: {"description": "Invalid ID supplied"},
|
||||
404: {"description": "Order not found"},
|
||||
},
|
||||
tags=["store"],
|
||||
summary="Place an order for a pet",
|
||||
summary="Delete purchase order by ID",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def place_order(
|
||||
order: Annotated[Order, Field(description="order placed for purchasing the pet")] = Body(None, description="order placed for purchasing the pet"),
|
||||
) -> Order:
|
||||
""""""
|
||||
async def delete_order(
|
||||
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"),
|
||||
) -> None:
|
||||
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
|
||||
if not BaseStoreApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BaseStoreApi.subclasses[0]().place_order(order)
|
||||
return await BaseStoreApi.subclasses[0]().delete_order(orderId)
|
||||
|
||||
@@ -14,14 +14,6 @@ class BaseStoreApi:
|
||||
def __init_subclass__(cls, **kwargs):
|
||||
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")],
|
||||
) -> None:
|
||||
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
|
||||
...
|
||||
|
||||
|
||||
async def get_inventory(
|
||||
self,
|
||||
) -> Dict[str, int]:
|
||||
@@ -29,6 +21,14 @@ class BaseStoreApi:
|
||||
...
|
||||
|
||||
|
||||
async def place_order(
|
||||
self,
|
||||
order: Annotated[Order, Field(description="order placed for purchasing the pet")],
|
||||
) -> Order:
|
||||
""""""
|
||||
...
|
||||
|
||||
|
||||
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")],
|
||||
@@ -37,9 +37,9 @@ class BaseStoreApi:
|
||||
...
|
||||
|
||||
|
||||
async def place_order(
|
||||
async def delete_order(
|
||||
self,
|
||||
order: Annotated[Order, Field(description="order placed for purchasing the pet")],
|
||||
) -> Order:
|
||||
""""""
|
||||
orderId: Annotated[StrictStr, Field(description="ID of the order that needs to be deleted")],
|
||||
) -> None:
|
||||
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
|
||||
...
|
||||
|
||||
@@ -99,48 +99,6 @@ async def create_users_with_list_input(
|
||||
return await BaseUserApi.subclasses[0]().create_users_with_list_input(user)
|
||||
|
||||
|
||||
@router.delete(
|
||||
"/user/{username}",
|
||||
responses={
|
||||
400: {"description": "Invalid username supplied"},
|
||||
404: {"description": "User not found"},
|
||||
},
|
||||
tags=["user"],
|
||||
summary="Delete user",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def delete_user(
|
||||
username: Annotated[StrictStr, Field(description="The name that needs to be deleted")] = Path(..., description="The name that needs to be deleted"),
|
||||
token_api_key: TokenModel = Security(
|
||||
get_token_api_key
|
||||
),
|
||||
) -> None:
|
||||
"""This can only be done by the logged in user."""
|
||||
if not BaseUserApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BaseUserApi.subclasses[0]().delete_user(username)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/user/{username}",
|
||||
responses={
|
||||
200: {"model": User, "description": "successful operation"},
|
||||
400: {"description": "Invalid username supplied"},
|
||||
404: {"description": "User not found"},
|
||||
},
|
||||
tags=["user"],
|
||||
summary="Get user by user name",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def get_user_by_name(
|
||||
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."),
|
||||
) -> User:
|
||||
""""""
|
||||
if not BaseUserApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BaseUserApi.subclasses[0]().get_user_by_name(username)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/user/login",
|
||||
responses={
|
||||
@@ -181,6 +139,26 @@ async def logout_user(
|
||||
return await BaseUserApi.subclasses[0]().logout_user()
|
||||
|
||||
|
||||
@router.get(
|
||||
"/user/{username}",
|
||||
responses={
|
||||
200: {"model": User, "description": "successful operation"},
|
||||
400: {"description": "Invalid username supplied"},
|
||||
404: {"description": "User not found"},
|
||||
},
|
||||
tags=["user"],
|
||||
summary="Get user by user name",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def get_user_by_name(
|
||||
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."),
|
||||
) -> User:
|
||||
""""""
|
||||
if not BaseUserApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BaseUserApi.subclasses[0]().get_user_by_name(username)
|
||||
|
||||
|
||||
@router.put(
|
||||
"/user/{username}",
|
||||
responses={
|
||||
@@ -202,3 +180,25 @@ async def update_user(
|
||||
if not BaseUserApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BaseUserApi.subclasses[0]().update_user(username, user)
|
||||
|
||||
|
||||
@router.delete(
|
||||
"/user/{username}",
|
||||
responses={
|
||||
400: {"description": "Invalid username supplied"},
|
||||
404: {"description": "User not found"},
|
||||
},
|
||||
tags=["user"],
|
||||
summary="Delete user",
|
||||
response_model_by_alias=True,
|
||||
)
|
||||
async def delete_user(
|
||||
username: Annotated[StrictStr, Field(description="The name that needs to be deleted")] = Path(..., description="The name that needs to be deleted"),
|
||||
token_api_key: TokenModel = Security(
|
||||
get_token_api_key
|
||||
),
|
||||
) -> None:
|
||||
"""This can only be done by the logged in user."""
|
||||
if not BaseUserApi.subclasses:
|
||||
raise HTTPException(status_code=500, detail="Not implemented")
|
||||
return await BaseUserApi.subclasses[0]().delete_user(username)
|
||||
|
||||
@@ -38,22 +38,6 @@ class BaseUserApi:
|
||||
...
|
||||
|
||||
|
||||
async def delete_user(
|
||||
self,
|
||||
username: Annotated[StrictStr, Field(description="The name that needs to be deleted")],
|
||||
) -> None:
|
||||
"""This can only be done by the logged in user."""
|
||||
...
|
||||
|
||||
|
||||
async def get_user_by_name(
|
||||
self,
|
||||
username: Annotated[StrictStr, Field(description="The name that needs to be fetched. Use user1 for testing.")],
|
||||
) -> User:
|
||||
""""""
|
||||
...
|
||||
|
||||
|
||||
async def login_user(
|
||||
self,
|
||||
username: Annotated[str, Field(strict=True, description="The user name for login")],
|
||||
@@ -70,6 +54,14 @@ 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.")],
|
||||
) -> User:
|
||||
""""""
|
||||
...
|
||||
|
||||
|
||||
async def update_user(
|
||||
self,
|
||||
username: Annotated[StrictStr, Field(description="name that need to be deleted")],
|
||||
@@ -77,3 +69,11 @@ class BaseUserApi:
|
||||
) -> None:
|
||||
"""This can only be done by the logged in user."""
|
||||
...
|
||||
|
||||
|
||||
async def delete_user(
|
||||
self,
|
||||
username: Annotated[StrictStr, Field(description="The name that needs to be deleted")],
|
||||
) -> None:
|
||||
"""This can only be done by the logged in user."""
|
||||
...
|
||||
|
||||
Reference in New Issue
Block a user