99
1010import typing as t
1111from sqlmesh .utils .pydantic import PydanticModel
12+ from web .server .models import Model
1213
1314API_FEATURE = "sqlmesh/api"
1415
@@ -28,7 +29,28 @@ class ApiRequest(PydanticModel):
2829class ApiResponse (PydanticModel ):
2930 """
3031 Response from the SQLMesh API.
31- This is a generic response that can be used to return data from any API endpoint.
32+ This is a generic base class that can be used to return data from any API endpoint.
33+ Specific API responses should inherit from this class and specify the data type more precisely.
3234 """
3335
3436 data : t .Union [t .Dict [str , t .Any ], t .List [t .Any ]]
37+
38+
39+ class ApiResponseGetModels (ApiResponse ):
40+ """
41+ Response from the SQLMesh API for the get_models endpoint.
42+ Specifies the data type more precisely as a list of models.
43+ """
44+ data : t .List [Model ]
45+
46+ def __init__ (self , ** data ):
47+ # Convert datetime objects to strings before passing to parent constructor
48+ if "data" in data and isinstance (data ["data" ], list ):
49+ for model in data ["data" ]:
50+ if hasattr (model , "details" ) and model .details :
51+ # Convert datetime fields to None or string to avoid serialization issues
52+ for field in ["stamp" , "start" , "cron_prev" , "cron_next" ]:
53+ if hasattr (model .details , field ) and getattr (model .details , field ) is not None :
54+ setattr (model .details , field , None )
55+
56+ super ().__init__ (** data )
0 commit comments