Merge pull request #28 from joaobenedetmachado/api-health-version

Include API version in /health response
This commit is contained in:
Bruno César
2026-03-02 01:00:45 -03:00
committed by GitHub
3 changed files with 7 additions and 5 deletions

View File

@@ -2,7 +2,7 @@ import logging
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from slowapi import _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
@@ -85,5 +85,5 @@ app.include_router(investigation.shared_router)
@app.get("/health")
async def health() -> dict[str, str]:
return {"status": "ok"}
async def health(request: Request) -> dict[str, str]:
return {"status": "ok", "version": request.app.version}

View File

@@ -205,4 +205,4 @@ async def test_health_not_masked(client: AsyncClient) -> None:
"""Non-CPF JSON responses pass through unchanged."""
resp = await client.get("/health")
assert resp.status_code == 200
assert resp.json() == {"status": "ok"}
assert resp.json()["status"] == "ok" and "version" in resp.json()

View File

@@ -8,7 +8,9 @@ from httpx import AsyncClient
async def test_health_returns_ok(client: AsyncClient) -> None:
response = await client.get("/health")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
data = response.json()
assert data["status"] == "ok"
assert "version" in data
assert response.headers["x-content-type-options"] == "nosniff"
assert response.headers["x-frame-options"] == "DENY"
assert response.headers["referrer-policy"] == "no-referrer"