I'm trying to create a fastapi API endpoint that relies on HTTP GET parameters, has them documented and uses fastapi's validation capabilities. Consider the following minimal example:
import fastapi
app = fastapi.FastAPI(
)
@app.get("/endpoint")
def example_endpoint(
par1: int = fastapi.Query(
None,
description="example documentation1",
),
par2: int = fastapi.Query(
None,
description="example documentation2",
),
):
return {"test": par1 + par2}
This has the documentation support and works over HTTP GET parameters, but doesn't validate them - http://localhost:8000/endpoint?par1=2&par2=3 works fine, but http://localhost:8000/endpoint crashes with an internal server error, instead of notifying the user that a parameter was expected. Is there a way to make par1 and par2 required and keep the documentation feature?