Skip to content

Commit a3b9883

Browse files
committed
Add schema registration support for PydanticMessage and Message subclasses
1 parent aaadd6c commit a3b9883

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/iop/_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pkg_resources
88
import importlib
99
import json
10+
from iop._message import _Message, _PydanticMessage
1011
from dc_schema import get_schema
1112

1213
class _Utils():
@@ -42,7 +43,12 @@ def register_message_schema(cls):
4243
4344
:param cls: The class to register
4445
"""
45-
schema = get_schema(cls)
46+
if issubclass(cls,_PydanticMessage):
47+
schema = cls.model_json_schema()
48+
elif issubclass(cls,_Message):
49+
schema = get_schema(cls)
50+
else:
51+
raise ValueError("The class must be a subclass of _Message or _PydanticMessage")
4652
schema_name = cls.__module__ + '.' + cls.__name__
4753
schema_str = json.dumps(schema)
4854
categories = schema_name

0 commit comments

Comments
 (0)