Skip to content

Commit 1d85f61

Browse files
committed
unify docstring for endpoints
1 parent 1efd15a commit 1d85f61

File tree

2 files changed

+77
-35
lines changed

2 files changed

+77
-35
lines changed

src/server/main.py

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,59 +61,100 @@ async def health_check() -> dict[str, str]:
6161
async def head_root() -> HTMLResponse:
6262
"""Respond to HTTP HEAD requests for the root URL.
6363
64-
Mirrors the headers and status code of the index page.
64+
**This endpoint mirrors the headers and status code of the index page**
65+
for HTTP HEAD requests, providing a lightweight way to check if the server
66+
is responding without downloading the full page content.
6567
66-
Returns
67-
-------
68-
HTMLResponse
69-
An empty HTML response with appropriate headers.
68+
**Returns**
69+
70+
- **HTMLResponse**: An empty HTML response with appropriate headers
7071
7172
"""
7273
return HTMLResponse(content=None, headers={"content-type": "text/html; charset=utf-8"})
7374

7475

7576
@app.get("/robots.txt", include_in_schema=False)
7677
async def robots() -> FileResponse:
77-
"""Serve the ``robots.txt`` file to guide search engine crawlers.
78+
"""Serve the robots.txt file to guide search engine crawlers.
7879
79-
Returns
80-
-------
81-
FileResponse
82-
The ``robots.txt`` file located in the static directory.
80+
**This endpoint serves the ``robots.txt`` file located in the static directory**
81+
to provide instructions to search engine crawlers about which parts of the site
82+
they should or should not index.
83+
84+
**Returns**
85+
86+
- **FileResponse**: The ``robots.txt`` file located in the static directory
8387
8488
"""
8589
return FileResponse("static/robots.txt")
8690

8791

8892
@app.get("/llm.txt")
8993
async def llm_txt() -> FileResponse:
90-
"""Serve the ``llm.txt`` file to provide information about the site to LLMs.
94+
"""Serve the llm.txt file to provide information about the site to LLMs.
95+
96+
**This endpoint serves the ``llm.txt`` file located in the static directory**
97+
to provide information about the site to Large Language Models (LLMs)
98+
and other AI systems that may be crawling the site.
99+
100+
**Returns**
91101
92-
Returns
93-
-------
94-
FileResponse
95-
The ``llm.txt`` file located in the static directory.
102+
- **FileResponse**: The ``llm.txt`` file located in the static directory
96103
97104
"""
98105
return FileResponse("static/llm.txt")
99106

100107

101108
@app.get("/docs", response_class=HTMLResponse, include_in_schema=False)
102109
async def custom_swagger_ui(request: Request) -> HTMLResponse:
103-
"""Swagger UI documentation."""
110+
"""Serve custom Swagger UI documentation.
111+
112+
**This endpoint serves a custom Swagger UI interface**
113+
for the API documentation, providing an interactive way to explore
114+
and test the available endpoints.
115+
116+
**Parameters**
117+
118+
- **request** (`Request`): The incoming HTTP request
119+
120+
**Returns**
121+
122+
- **HTMLResponse**: Custom Swagger UI documentation page
123+
124+
"""
104125
return templates.TemplateResponse("swagger_ui.jinja", {"request": request})
105126

106127

107128
@app.get("/api", include_in_schema=True)
108129
def openapi_json_get() -> JSONResponse:
109-
"""Return the OpenAPI schema (openapi.json)."""
130+
"""Return the OpenAPI schema.
131+
132+
**This endpoint returns the OpenAPI schema (openapi.json)**
133+
that describes the API structure, endpoints, and data models
134+
for documentation and client generation purposes.
135+
136+
**Returns**
137+
138+
- **JSONResponse**: The OpenAPI schema as JSON
139+
140+
"""
110141
return JSONResponse(app.openapi())
111142

112143

113144
@app.api_route("/api", methods=["POST", "PUT", "DELETE", "OPTIONS", "HEAD"], include_in_schema=False)
114145
@app.api_route("/api/", methods=["GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD"], include_in_schema=False)
115146
def openapi_json() -> JSONResponse:
116-
"""Return the OpenAPI schema (openapi.json)."""
147+
"""Return the OpenAPI schema for various HTTP methods.
148+
149+
**This endpoint returns the OpenAPI schema (openapi.json)**
150+
for multiple HTTP methods, providing API documentation
151+
for clients that may use different request methods.
152+
153+
**Returns**
154+
155+
- **JSONResponse**: The OpenAPI schema as JSON
156+
157+
"""
117158
return JSONResponse(app.openapi())
118159

119160

src/server/routers/ingest.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,24 @@ async def api_ingest_get(
8383

8484
@router.get("/api/download/file/{ingest_id}", response_class=FileResponse)
8585
async def download_ingest(ingest_id: str) -> FileResponse:
86-
"""Return the first ``*.txt`` file produced for ``ingest_id`` as a download.
87-
88-
Parameters
89-
----------
90-
ingest_id : str
91-
Identifier that the ingest step emitted (also the directory name that stores the artefacts).
92-
93-
Returns
94-
-------
95-
FileResponse
96-
Streamed response with media type ``text/plain`` that prompts the browser to download the file.
97-
98-
Raises
99-
------
100-
HTTPException
101-
**404** - digest directory is missing or contains no ``*.txt`` file.
102-
**403** - the process lacks permission to read the directory or file.
86+
"""Download the first text file produced for an ingest ID.
87+
88+
**This endpoint retrieves the first ``*.txt`` file produced during the ingestion process**
89+
and returns it as a downloadable file. The file is streamed with media type ``text/plain``
90+
and prompts the browser to download it.
91+
92+
**Parameters**
93+
94+
- **ingest_id** (`str`): Identifier that the ingest step emitted
95+
96+
**Returns**
97+
98+
- **FileResponse**: Streamed response with media type ``text/plain``
99+
100+
**Raises**
101+
102+
- **HTTPException**: **404** - digest directory is missing or contains no ``*.txt`` file
103+
- **HTTPException**: **403** - the process lacks permission to read the directory or file
103104
104105
"""
105106
directory = TMP_BASE_PATH / ingest_id

0 commit comments

Comments
 (0)