Query parameters from pydantic model

The documentation gives a shortcut to avoid this kind of repetitions. In this case, it would give:

from fastapi import Depends

@app.post("/test-query-params")
def test_query(model: Model = Depends()): pass

This will allow you to request /test-query-params?x=1&y=2 and will also produce the correct OpenAPI description for this endpoint.

Similar solutions can be used for using Pydantic models as form-data descriptors.

Leave a Comment