11
22# main.py
33from datetime import datetime
4- from typing import Any , Dict , Optional
4+ from typing import Any , Optional
55
6+ from database import schemas_collection
7+ from datamodel import ALLOWED_FIELD_TYPES , SchemaDefinition , compute_schema_hash
68from fastapi import FastAPI , HTTPException
79from fastapi .encoders import jsonable_encoder
810from fastapi .middleware .cors import CORSMiddleware
911
10- from database import schemas_collection
11- from datamodel import SchemaDefinition , compute_schema_hash , ALLOWED_FIELD_TYPES
12-
1312# ---- FastAPI app & CORS ----
1413app = FastAPI ()
1514app .add_middleware (
2120)
2221
2322# ---- Helpers ----
24- def _merge_flat_content (existing : Optional [ Dict [ str , Any ]] , incoming : Optional [ Dict [ str , Any ]] ) -> Dict [str , Any ]:
23+ def _merge_flat_content (existing : dict [ str , Any ] | None , incoming : dict [ str , Any ] | None ) -> dict [str , Any ]:
2524 """
2625 Merge two flat dicts for schema `content`.
2726 - Existing values are overwritten by incoming values for the same key.
@@ -112,7 +111,7 @@ async def update_schema(id: str, update: SchemaDefinition) -> dict[str, str]:
112111 merged_version = payload .get ("version" ) if payload .get ("version" ) is not None else existing .get ("version" )
113112
114113 # --- Merge content (flat dict) ---
115- incoming_content = payload .get ("content" )
114+ incoming_content : dict [ str , Any ] | None = payload .get ("content" )
116115 merged_content = _merge_flat_content (existing .get ("content" ), incoming_content )
117116
118117 # Optional: validate merged content types
@@ -141,7 +140,7 @@ async def update_schema(id: str, update: SchemaDefinition) -> dict[str, str]:
141140
142141
143142@app .patch ("/schemas/{id}/content" , response_model = dict [str , str ])
144- async def patch_schema_content (id : str , content_updates : Dict [str , str ]) -> dict [str , str ]:
143+ async def patch_schema_content (id : str , content_updates : dict [str , str ]) -> dict [str , str ]:
145144 """
146145 Convenience endpoint to ONLY upsert fields in `content`:
147146 - Adds new fields.
@@ -195,6 +194,7 @@ async def patch_schema_content(id: str, content_updates: Dict[str, str]) -> dict
195194 return {"message" : "Content patched" , "id" : new_id }
196195
197196
197+
198198@app .delete ("/schemas/{id}" , response_model = dict [str , str ])
199199async def delete_schema (id : str ) -> dict [str , str ]:
200200 """
@@ -207,4 +207,6 @@ async def delete_schema(id: str) -> dict[str, str]:
207207 result = schemas_collection .delete_one ({"id" : id })
208208 if result .deleted_count == 0 :
209209 raise HTTPException (status_code = 404 , detail = "Schema not found" )
210- return {"message" : "Schema deleted" }
210+
211+ # ✅ Return a simple success message
212+ return {"message" : "Schema deleted" , "id" : id }
0 commit comments