Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public String getHelp() {
public PythonFastAPIServerCodegen() {
super();

// Skip sorting of operations to preserve the order found in the OpenAPI spec file. See
// https://fastapi.tiangolo.com/tutorial/path-params/?h=path#order-matters for details on why order matters.
LOGGER.info("Skipping sorting of path operations, order matters, let the developer decide via their specification file.");
setSkipSortingOperations(true);

modifyFeatureSet(features -> features.includeSecurityFeatures(
SecurityFeature.OAuth2_AuthorizationCode,
SecurityFeature.OAuth2_Password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@
importlib.import_module(name)


@router.post(
@router.put(
"/pet",
responses={
200: {"model": Pet, "description": "successful operation"},
405: {"description": "Invalid input"},
400: {"description": "Invalid ID supplied"},
404: {"description": "Pet not found"},
405: {"description": "Validation exception"},
},
tags=["pet"],
summary="Add a new pet to the store",
summary="Update an existing pet",
response_model_by_alias=True,
)
async def add_pet(
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"]
Expand All @@ -56,29 +58,29 @@ async def add_pet(
""""""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().add_pet(pet)
return await BasePetApi.subclasses[0]().update_pet(pet)


@router.delete(
"/pet/{petId}",
@router.post(
"/pet",
responses={
400: {"description": "Invalid pet value"},
200: {"model": Pet, "description": "successful operation"},
405: {"description": "Invalid input"},
},
tags=["pet"],
summary="Deletes a pet",
summary="Add a new pet to the store",
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=""),
async def add_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"]
),
) -> None:
) -> Pet:
""""""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().delete_pet(petId, api_key)
return await BasePetApi.subclasses[0]().add_pet(pet)


@router.get(
Expand Down Expand Up @@ -148,51 +150,49 @@ async def get_pet_by_id(
return await BasePetApi.subclasses[0]().get_pet_by_id(petId)


@router.put(
"/pet",
@router.post(
"/pet/{petId}",
responses={
200: {"model": Pet, "description": "successful operation"},
400: {"description": "Invalid ID supplied"},
404: {"description": "Pet not found"},
405: {"description": "Validation exception"},
405: {"description": "Invalid input"},
},
tags=["pet"],
summary="Update an existing pet",
summary="Updates a pet in the store with form data",
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"),
async def update_pet_with_form(
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")] = Path(..., description="ID of pet that needs to be updated"),
name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")] = Form(None, description="Updated name of the pet"),
status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")] = Form(None, description="Updated status of the pet"),
token_petstore_auth: TokenModel = Security(
get_token_petstore_auth, scopes=["write:pets", "read:pets"]
),
) -> Pet:
) -> None:
""""""
if not BasePetApi.subclasses:
raise HTTPException(status_code=500, detail="Not implemented")
return await BasePetApi.subclasses[0]().update_pet(pet)
return await BasePetApi.subclasses[0]().update_pet_with_form(petId, name, status)


@router.post(
@router.delete(
"/pet/{petId}",
responses={
405: {"description": "Invalid input"},
400: {"description": "Invalid pet value"},
},
tags=["pet"],
summary="Updates a pet in the store with form data",
summary="Deletes a pet",
response_model_by_alias=True,
)
async def update_pet_with_form(
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")] = Path(..., description="ID of pet that needs to be updated"),
name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")] = Form(None, description="Updated name of the pet"),
status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")] = Form(None, description="Updated status of the pet"),
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]().update_pet_with_form(petId, name, status)
return await BasePetApi.subclasses[0]().delete_pet(petId, api_key)


@router.post(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ 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:
""""""
...


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:
""""""
...

Expand Down Expand Up @@ -56,19 +55,20 @@ async def get_pet_by_id(
...


async def update_pet(
async def update_pet_with_form(
self,
pet: Annotated[Pet, Field(description="Pet object that needs to be added to the store")],
) -> Pet:
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")],
name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")],
status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")],
) -> None:
""""""
...


async def update_pet_with_form(
async def delete_pet(
self,
petId: Annotated[StrictInt, Field(description="ID of pet that needs to be updated")],
name: Annotated[Optional[StrictStr], Field(description="Updated name of the pet")],
status: Annotated[Optional[StrictStr], Field(description="Updated status of the pet")],
petId: Annotated[StrictInt, Field(description="Pet id to delete")],
api_key: Optional[StrictStr],
) -> None:
""""""
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@
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={
Expand All @@ -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={
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ class BaseStoreApi:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
BaseStoreApi.subclasses = BaseStoreApi.subclasses + (cls,)
async def delete_order(
async def get_inventory(
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"""
) -> Dict[str, int]:
"""Returns a map of status codes to quantities"""
...


async def get_inventory(
async def place_order(
self,
) -> Dict[str, int]:
"""Returns a map of status codes to quantities"""
order: Annotated[Order, Field(description="order placed for purchasing the pet")],
) -> Order:
""""""
...


Expand All @@ -37,9 +37,9 @@ async def get_order_by_id(
...


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"""
...
Loading
Loading