How can I set a sort order for the API methods in the FastAPI Swagger autodocs?
This answer shows how to do it in Java. How can I do it in Python? Is there a pure Python solution?
For example, I would like all my methods grouped by type (GET, POST, PUT, DELETE). The blue GET methods should be at the top:
from fastapi import FastAPI
app = FastAPI()
@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
>Solution :
You can configure Swagger UI parameters through the FastAPI constructor.
app = FastAPI(swagger_ui_parameters={"operationsSorter": "method"})
The full list of parameters can be found in the swagger documentation.
