Skip to content

Commit d32381f

Browse files
committed
Enhance API documentation and health check response
- Update health check to return a simplified response - Modify OpenAPI URL to include ROOT_PATH - Add redirect endpoint for scalar documentation - Update docker-compose to mount models directory
1 parent 6af2d1a commit d32381f

3 files changed

Lines changed: 19 additions & 9 deletions

File tree

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ services:
1313
- speech-transcription-postgres
1414
networks:
1515
- speech-transcription-network
16+
volumes:
17+
- ./models:/app/models
1618
#deploy:
1719
# resources:
1820
# reservations:

src/routes.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from datetime import datetime
2-
3-
from fastapi import APIRouter
1+
from fastapi import APIRouter, Request
42
from scalar_fastapi import get_scalar_api_reference
3+
from fastapi.responses import RedirectResponse
54

5+
from src.config import settings
66
from src.schemas import HealthCheck
77

88
router = APIRouter(tags=["Monitoring"])
@@ -21,12 +21,18 @@
2121
},
2222
)
2323
async def healthcheck() -> HealthCheck:
24-
return HealthCheck(timestamp=datetime.utcnow().isoformat())
24+
return HealthCheck()
2525

2626

2727
@router.get("/docs", include_in_schema=False)
2828
async def scalar_html():
2929
return get_scalar_api_reference(
30-
openapi_url="/openapi.json",
31-
title="Speech Transcription API",
30+
openapi_url=f"{settings.ROOT_PATH}/openapi.json",
31+
title="Speech recognition API",
3232
)
33+
34+
35+
@router.get("/docs/scalar", include_in_schema=False)
36+
async def redirect_to_docs(request: Request):
37+
docs_url = str(request.url_for("scalar_html"))
38+
return RedirectResponse(url=docs_url)

src/schemas.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from pydantic import BaseModel
1+
from datetime import datetime, timezone
2+
3+
from pydantic import BaseModel, Field
24

35

46
class BaseSchema(BaseModel):
57
model_config = {"from_attributes": True}
68

79

8-
class HealthCheck(BaseSchema):
10+
class HealthCheck(BaseModel):
911
status: str = "ok"
10-
timestamp: str
12+
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))

0 commit comments

Comments
 (0)