api: improve message serialisation

This commit is contained in:
Johannes Kirschbauer
2024-05-23 09:33:57 +02:00
parent fc8a64ef49
commit 691ae9fb15
9 changed files with 91 additions and 30 deletions

View File

@@ -1,12 +1,14 @@
from collections.abc import Callable
from typing import Any
from typing import Any, TypeVar
T = TypeVar("T")
class _MethodRegistry:
def __init__(self) -> None:
self._registry: dict[str, Callable] = {}
def register(self, fn: Callable) -> Callable:
def register(self, fn: Callable[..., T]) -> Callable[..., T]:
self._registry[fn.__name__] = fn
return fn

View File

@@ -44,6 +44,7 @@ def type_to_dict(t: Any, scope: str = "") -> dict:
elif issubclass(origin, dict):
return {
"type": "object",
"additionalProperties": type_to_dict(t.__args__[1], scope),
}
raise BaseException(f"Error api type not yet supported {t!s}")