There may be a better way to do this, but this worked for me, and it is compatible with FastAPI's use of Enums.
This works if the fields are to be autogenerated using numbers, however to be useful with FastAPI Enum has to have values as str.
Probably not, I would be glad to get an example of the above working, and compatible with FastAPI's Query Enums.
My use is:
post_orders: Ordering = {
"created_time": "Oldest First",
"comment_count": "Most Comments",
"inverse_comment_count": "Fewest Comments",
}
PostOrders = create_strenum("PostOrders", svc_post.post_orders)
@router.get("/posts/", response_model=Posts)
async def get_all(
order: PostOrders,
) -> Posts:
pass
With the Enum functional example the FastAPI choices would be integers rather than the strings.