Skip to content

Commit 812b491

Browse files
committed
feat: return all available page-style endpoints on index
1 parent ffb133a commit 812b491

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

papyrus/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,28 @@ async def general_exception_handler(request: Request, exc: Exception) -> JSONRes
149149
if settings.debug:
150150
include_debug_routers(app)
151151

152+
@app.get("/", tags=["Index"])
153+
async def index(request: Request) -> dict[str, object]:
154+
"""Return the available page-style endpoints for this server."""
155+
pages: list[dict[str, str]] = []
156+
157+
if app.docs_url is not None:
158+
pages.append({"name": "docs", "path": app.docs_url})
159+
160+
if app.redoc_url is not None:
161+
pages.append({"name": "redoc", "path": app.redoc_url})
162+
163+
if app.openapi_url is not None:
164+
pages.append({"name": "openapi", "path": app.openapi_url})
165+
166+
if any(route.path == "/__dev/auth-sandbox" for route in request.app.routes):
167+
pages.append({"name": "auth_sandbox", "path": "/__dev/auth-sandbox"})
168+
169+
return {
170+
"name": "Papyrus Server API",
171+
"pages": pages,
172+
}
173+
152174
@app.get("/health", tags=["Health"])
153175
async def health_check() -> dict[str, str]:
154176
"""Check API health status."""

tests/api/routes/test_health.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@
33
from httpx import AsyncClient
44

55

6+
async def test_index_lists_available_pages(prod_client: AsyncClient):
7+
"""Test root index returns the available page endpoints."""
8+
response = await prod_client.get("/")
9+
assert response.status_code == 200
10+
data = response.json()
11+
12+
pages = {page["name"]: page["path"] for page in data["pages"]}
13+
assert data["name"] == "Papyrus Server API"
14+
assert pages["docs"] == "/docs"
15+
assert pages["redoc"] == "/redoc"
16+
assert pages["openapi"] == "/openapi.json"
17+
assert "auth_sandbox" not in pages
18+
19+
20+
async def test_index_lists_debug_pages(debug_client: AsyncClient):
21+
"""Test root index includes the auth sandbox in debug mode."""
22+
response = await debug_client.get("/")
23+
assert response.status_code == 200
24+
data = response.json()
25+
26+
pages = {page["name"]: page["path"] for page in data["pages"]}
27+
assert pages["auth_sandbox"] == "/__dev/auth-sandbox"
28+
29+
630
async def test_health_check(client: AsyncClient):
731
"""Test health check endpoint."""
832
response = await client.get("/health")

0 commit comments

Comments
 (0)