32 lines
888 B
Python
32 lines
888 B
Python
from typing import Optional, List, Any
|
|||
|
|
from pydantic import BaseModel, model_validator
|
||
|
|
|
||
|
|
class ConnectionItem(BaseModel):
|
||
|
|
conn_id: str
|
||
|
|
conn_type: str
|
||
|
|
host: str
|
||
|
|
|
||
|
|
class ConnectionListResponse(BaseModel):
|
||
|
|
connections: List[ConnectionItem]
|
||
|
|
|
||
|
|
class CustomConnectionRequest(BaseModel):
|
||
|
|
conn_id: str
|
||
|
|
conn_type: str = "postgres"
|
||
|
|
host: str
|
||
|
|
port: int = 5432
|
||
|
|
db_schema: str = "public"
|
||
|
|
login: str = "postgres"
|
||
|
|
password: Optional[str] = ""
|
||
|
|
|
||
|
|
@model_validator(mode="before")
|
||
|
|
@classmethod
|
||
|
|
def handle_schema_alias(cls, data: Any) -> Any:
|
||
|
|
"""Support both 'schema' and 'db_schema' JSON payload keys safely."""
|
||
|
|
if isinstance(data, dict):
|
||
|
|
if "schema" in data and "db_schema" not in data:
|
||
|
|
data["db_schema"] = data.pop("schema")
|
||
|
|
return data
|
||
|
|
|
||
|
|
class ConnectionTestRequest(BaseModel):
|
||
|
|
connection_id: str
|