Skip to content

Commit 3b628b0

Browse files
committed
WIP: integrate documentation to the jinja theme
1 parent 0fcf8a9 commit 3b628b0

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/server/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
load_dotenv()
2020

2121
# Initialize the FastAPI application with lifespan
22-
app = FastAPI(lifespan=lifespan)
22+
app = FastAPI(lifespan=lifespan, docs_url=None, redoc_url=None)
2323
app.state.limiter = limiter
2424

2525
# Register the custom exception handler for rate limits
@@ -98,6 +98,12 @@ async def llm_txt() -> FileResponse:
9898
return FileResponse("static/llm.txt")
9999

100100

101+
@app.get("/docs", response_class=HTMLResponse)
102+
async def custom_swagger_ui(request: Request) -> HTMLResponse:
103+
"""Render the Swagger UI documentation page inside the Jinja theme."""
104+
return templates.TemplateResponse("swagger_ui.jinja", {"request": request})
105+
106+
101107
# Include routers for modular endpoints
102108
app.include_router(index)
103109
app.include_router(ingest)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{% extends "base.jinja" %}
2+
{% block title %}API Docs{% endblock %}
3+
{% block content %}
4+
<div class="bg-[#fff4da] rounded-xl border-[3px] border-gray-900 p-4 md:p-8 relative z-20">
5+
<h1 class="text-3xl font-bold text-gray-900 mb-4">API Documentation</h1>
6+
<div id="swagger-ui"></div>
7+
</div>
8+
<link rel="stylesheet"
9+
href="https://unpkg.com/swagger-ui-dist@5/swagger-ui.css">
10+
<script src="https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
11+
<script>
12+
window.onload = function() {
13+
SwaggerUIBundle({
14+
url: "/openapi.json",
15+
dom_id: '#swagger-ui',
16+
presets: [
17+
SwaggerUIBundle.presets.apis,
18+
SwaggerUIBundle.SwaggerUIStandalonePreset
19+
],
20+
layout: "BaseLayout",
21+
deepLinking: true,
22+
});
23+
}
24+
</script>
25+
{% endblock %}

0 commit comments

Comments
 (0)