You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[python-fastapi] Fix: Skip sorting of path operations (#22163) (#22166)
* [python-fastapi] Fix: Skip sorting of path operations (#22163)
Make use of helpful code added in
243f501 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: #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.
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonFastAPIServerCodegen.java
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -89,6 +89,11 @@ public String getHelp() {
89
89
publicPythonFastAPIServerCodegen() {
90
90
super();
91
91
92
+
// Skip sorting of operations to preserve the order found in the OpenAPI spec file. See
93
+
// https://fastapi.tiangolo.com/tutorial/path-params/?h=path#order-matters for details on why order matters.
94
+
LOGGER.info("Skipping sorting of path operations, order matters, let the developer decide via their specification file.");
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"),
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"),
summary="Updates a pet in the store with form data",
161
160
response_model_by_alias=True,
162
161
)
163
-
asyncdefupdate_pet(
164
-
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"),
162
+
asyncdefupdate_pet_with_form(
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"),
Copy file name to clipboardExpand all lines: samples/server/petstore/python-fastapi/src/openapi_server/apis/store_api.py
+29-29Lines changed: 29 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -36,25 +36,6 @@
36
36
importlib.import_module(name)
37
37
38
38
39
-
@router.delete(
40
-
"/store/order/{orderId}",
41
-
responses={
42
-
400: {"description": "Invalid ID supplied"},
43
-
404: {"description": "Order not found"},
44
-
},
45
-
tags=["store"],
46
-
summary="Delete purchase order by ID",
47
-
response_model_by_alias=True,
48
-
)
49
-
asyncdefdelete_order(
50
-
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"),
51
-
) ->None:
52
-
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
order: Annotated[Order, Field(description="order placed for purchasing the pet")] =Body(None, description="order placed for purchasing the pet"),
110
-
) ->Order:
111
-
""""""
108
+
asyncdefdelete_order(
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"),
110
+
) ->None:
111
+
"""For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors"""
0 commit comments