Skip to content

Commit 163bb02

Browse files
committed
endpoint_fx docstring as FastAPI description
this commit adds descriptions to each API endpoint in the generated FastAPI. in vetiver_post, the docstring for the new function is dedented to avoid formatting issues.
1 parent d610f25 commit 163bb02

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

vetiver/server.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from fastapi.openapi.utils import get_openapi
1212
from fastapi.responses import HTMLResponse, RedirectResponse
1313
from fastapi.responses import PlainTextResponse
14+
from textwrap import dedent
1415
from warnings import warn
1516

1617
from .utils import _jupyter_nb
@@ -105,10 +106,12 @@ def pin_url():
105106

106107
@app.get("/ping", include_in_schema=True)
107108
async def ping():
109+
"""Ping endpoint for health check"""
108110
return {"ping": "pong"}
109111

110112
@app.get("/metadata")
111113
async def get_metadata():
114+
"""Get metadata from model"""
112115
return self.model.metadata.to_dict()
113116

114117
self.vetiver_post(
@@ -185,11 +188,14 @@ def vetiver_post(self, endpoint_fx: Callable, endpoint_name: str = None, **kw):
185188

186189
if self.check_prototype is True:
187190

188-
@self.app.post(urljoin("/", endpoint_name), name=endpoint_name)
191+
@self.app.post(
192+
urljoin("/", endpoint_name),
193+
name=endpoint_name,
194+
description=dedent(endpoint_fx.__doc__),
195+
)
189196
async def custom_endpoint(input_data: List[self.model.prototype]):
190197
_to_frame = api_data_to_frame(input_data)
191198
predictions = endpoint_fx(_to_frame, **kw)
192-
193199
if isinstance(predictions, List):
194200
return {endpoint_name: predictions}
195201
else:

0 commit comments

Comments
 (0)