feat(templates): add OpenAPI-first CRUD app scaffold with mock data

- include CRUD OpenAPI spec
- add in-memory mock data store
- implement OpenAPI-bound route handlers
- provide runnable FastAPI bootstrap
- include end-to-end integration test
This commit is contained in:
2026-01-10 17:59:11 +05:30
parent 2f444a93ad
commit 2ac342240b
5 changed files with 311 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
"""
CRUD route handlers bound via OpenAPI operationId.
These handlers explicitly control HTTP status codes to ensure
runtime behavior matches the OpenAPI contract.
"""
from fastapi import Response, HTTPException
from data import (
list_items as _list_items,
get_item as _get_item,
create_item as _create_item,
update_item as _update_item,
delete_item as _delete_item,
)
def list_items():
return _list_items()
def get_item(item_id: int):
try:
return _get_item(item_id)
except KeyError:
raise HTTPException(status_code=404, detail="Item not found")
def create_item(payload: dict, response: Response):
item = _create_item(payload)
response.status_code = 201
return item
def update_item(item_id: int, payload: dict):
try:
return _update_item(item_id, payload)
except KeyError:
raise HTTPException(status_code=404, detail="Item not found")
def delete_item(item_id: int, response: Response):
try:
_delete_item(item_id)
except KeyError:
raise HTTPException(status_code=404, detail="Item not found")
response.status_code = 204
return None