How can I set a custom sort order for the API methods in FastAPI Swagger autodocs?
This question shows how to do it in Java. My previous question asked how to sort by "Method", which is a supported sorting method. I would really like to take this a step further, so that I can determine which order the methods appear. Right now DELETE
appears at the top, but I want API methods to be in the order: GET
, POST
, PUT
, DELETE
.
I know it is possible to implement a custom sort in JavaScript and give that function to operationsSorter
, but you can't include it from the swagger_ui_parameters
property that is available in the Python bindings. Is there some way to accomplish this in Python?
from fastapi import FastAPI
app = FastAPI(swagger_ui_parameters={"operationsSorter": "method"})
@app.get("/")
def list_all_components():
pass
@app.get("/{component_id}")
def get_component(component_id: int):
pass
@app.post("/")
def create_component():
pass
@app.put("/{component_id}")
def update_component(component_id: int):
pass
@app.delete("/{component_id}")
def delete_component(component_id: int):
pass