Search code examples
pythonswaggerfastapiswagger-uiopenapi

FastAPI: query parameters are not editable in Swagger UI


According to FastAPI documentation list of query parameters, I can send a GET request with query parameters, e.g., /items?q=1&q=2..., and get back the list of query parameters. For example:

from fastapi import FastAPI, Query

app = FastAPI()
@app.get("/items/")
async def read_items(q: list[str] | None = Query(default=None)):
    query_items = {"q": q}
    return query_items

However I have an issue. Swagger does not allow editing this field. There is no form for edit at all.

enter image description here

FastAPI was installed by pip install "fastapi[all]" and current version is fastapi==0.93.0


Solution

  • You would first need to click the Try it out button, in order to be able to test an endpoint in OpenAPI/Swagger UI autodocs.

    If you would like to avoid doing that every time you use the /docs, you could configure the swagger_ui_parameters; more specifically, you could have the Try it out button enabled (clicked) by default, by setting the tryItOutEnabled parameter to True.

    Example

    from fastapi import FastAPI
    
    app = FastAPI(swagger_ui_parameters={"tryItOutEnabled": True})