Problem statement
The reports endpoint takes category as plain text, so a typo like /reports/sale gets through to the handler. Constrain category to an Enum, so only the real report categories reach the handler and FastAPI rejects everything else.
Requirements
The app, the GET / home route, the ReportCategory enum in app/schemas.py and the report data REPORTS in app/store.py are already provided, and both are imported in app/main.py. The route GET /reports/{category} is declared too. Your task has one part, in app/main.py: finish the get_report handler.
An Enum lists the only values a parameter may take. When a path parameter has an Enum type, FastAPI accepts only those values, gives the handler the matching member, and shows the values in the API docs.
- get_report takes category typed as the ReportCategory enum and returns that category's report from REPORTS. /reports/sales returns {"category": "sales", "metric": "revenue", "total": 42500}
- Any other value, such as sale, Sales or revenue, is rejected by FastAPI with a 422 validation error that lists the allowed values, and get_report does not run
- The API docs, at /docs and /openapi.json, show the three allowed values for category: sales, inventory and users
Sample Requests & Responses
GET /reports/sales
Response (200 OK):
{"category": "sales", "metric": "revenue", "total": 42500}
GET /reports/inventory
Response (200 OK):
{"category": "inventory", "metric": "units_in_stock", "total": 1280}
GET /reports/users
Response (200 OK):
{"category": "users", "metric": "active_users", "total": 512}
GET /reports/revenue
Response (422 Unprocessable Entity):
{"detail": [{"type": "enum", "loc": ["path", "category"], "msg": "Input should be 'sales', 'inventory' or 'users'", "input": "revenue", "ctx": {"expected": "'sales', 'inventory' or 'users'"}}]}
GET /openapi.json
Response (200 OK), the part that describes category:
{"type": "string", "enum": ["sales", "inventory", "users"], "title": "ReportCategory"}
