fix(api): encode untyped datetime responses

This commit is contained in:
2026-07-31 18:39:36 +08:00
parent eac6b78598
commit 0be31869b5
2 changed files with 53 additions and 0 deletions
+33
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
from datetime import datetime, timezone
from pathlib import Path
from uuid import uuid4
@@ -282,3 +283,35 @@ def test_rest_runtime_wraps_handler_paginated_list() -> None:
"limit": 2,
"offset": 1,
}
def test_rest_runtime_json_encodes_untyped_datetime_response() -> None:
source_router = APIRouter()
@source_router.get("/simulation-result")
async def simulation_result():
return {
"result": [
{
"time": datetime(2026, 7, 30, 4, tzinfo=timezone.utc),
"id": "4277",
}
]
}
app = FastAPI(redirect_slashes=False)
app.include_router(build_rest_router(source_router.routes), prefix="/api/v1")
response = TestClient(app, raise_server_exceptions=False).get(
"/api/v1/simulation-result"
)
assert response.status_code == 200
assert response.json() == {
"result": [
{
"time": "2026-07-30T04:00:00+00:00",
"id": "4277",
}
]
}