chore(api): make version prefix optional

This commit is contained in:
Matthew Farrellee 2025-09-02 08:57:18 -04:00
parent 5c873d53db
commit f991f9ff1c
2 changed files with 6 additions and 1 deletions

View file

@ -60,7 +60,9 @@ def get_all_api_routes(
# The __webmethod__ attribute is dynamically added by the @webmethod decorator # The __webmethod__ attribute is dynamically added by the @webmethod decorator
# mypy doesn't know about this dynamic attribute, so we ignore the attr-defined error # mypy doesn't know about this dynamic attribute, so we ignore the attr-defined error
webmethod = method.__webmethod__ # type: ignore[attr-defined] webmethod = method.__webmethod__ # type: ignore[attr-defined]
path = f"/{LLAMA_STACK_API_VERSION}/{webmethod.route.lstrip('/')}" path = webmethod.route.lstrip("/")
if webmethod.add_version:
path = f"/{LLAMA_STACK_API_VERSION}/{path}"
if webmethod.method == hdrs.METH_GET: if webmethod.method == hdrs.METH_GET:
http_method = hdrs.METH_GET http_method = hdrs.METH_GET
elif webmethod.method == hdrs.METH_DELETE: elif webmethod.method == hdrs.METH_DELETE:

View file

@ -23,6 +23,7 @@ class WebMethod:
descriptive_name: str | None = None descriptive_name: str | None = None
experimental: bool | None = False experimental: bool | None = False
required_scope: str | None = None required_scope: str | None = None
add_version: bool = True
T = TypeVar("T", bound=Callable[..., Any]) T = TypeVar("T", bound=Callable[..., Any])
@ -38,6 +39,7 @@ def webmethod(
descriptive_name: str | None = None, descriptive_name: str | None = None,
experimental: bool | None = False, experimental: bool | None = False,
required_scope: str | None = None, required_scope: str | None = None,
add_version: bool = True,
) -> Callable[[T], T]: ) -> Callable[[T], T]:
""" """
Decorator that supplies additional metadata to an endpoint operation function. Decorator that supplies additional metadata to an endpoint operation function.
@ -61,6 +63,7 @@ def webmethod(
descriptive_name=descriptive_name, descriptive_name=descriptive_name,
experimental=experimental, experimental=experimental,
required_scope=required_scope, required_scope=required_scope,
add_version=add_version,
) )
return func return func