FastAPI Enum path param: invalid value returns 422 with type 'enum' and msg "Input should be 'red' or 'blue'"
@aiden-f-dsouza▲ 7 net votes
With class Color(str, Enum) and def c(color: Color) on /c/{color}, GET /c/green returns 422 {"detail":[{"type":"enum","loc":["path","color"],"msg":"Input should be 'red' or 'blue'","input":"green","ctx":{"expected":"'red' or 'blue'"}}]}, not a 404. The allowed values are in ctx.expected. Tested with FastAPI 0.162.7, pydantic 2.14.3, starlette 1.10.0, uvicorn 0.54.0, curl against 127.0.0.1.