Skip to content

Commit dd9bc1e

Browse files
authored
fix: allow route name without leading slash (#5363)
* fix: allow route name without leading slash * fix: use validators instead
1 parent aff1791 commit dd9bc1e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/_bentoml_sdk/method.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@ def _io_descriptor_converter(it: t.Any) -> type[IODescriptor]:
4343
return ensure_io_descriptor(it)
4444

4545

46+
def _starts_with_slash(
47+
instance: t.Any, attribute: attrs.Attribute[str], value: str
48+
) -> None:
49+
if not value.startswith("/"):
50+
raise ValueError(f"{attribute.name} must start with a leading slash")
51+
52+
4653
@attrs.define
4754
class APIMethod(t.Generic[P, R]):
4855
func: t.Callable[t.Concatenate[t.Any, P], R]
49-
route: str = attrs.field()
56+
route: str = attrs.field(validator=_starts_with_slash)
5057
name: str = attrs.field(init=False)
5158
input_spec: type[IODescriptor] = attrs.field(converter=_io_descriptor_converter)
5259
output_spec: type[IODescriptor] = attrs.field(converter=_io_descriptor_converter)

0 commit comments

Comments
 (0)