11import json
22from http import HTTPStatus
3+ from typing import Union , Dict , Any
34
45from ...abstract_base_client import AbstractBaseClient
56from ...errors .custom_error import CustomError
1415async def register_event_schema (
1516 client : AbstractBaseClient ,
1617 event_type : str ,
17- json_schema : str ,
18+ json_schema : Union [ str , Dict [ str , Any ]] ,
1819) -> None :
1920 try :
2021 validate_type (event_type )
@@ -24,10 +25,22 @@ async def register_event_schema(
2425 ) from validation_error
2526 except Exception as other_error :
2627 raise InternalError (str (other_error )) from other_error
28+
29+ # Handle both string and dictionary schema formats
30+ # If json_schema is a string, parse it to ensure it's valid JSON
31+ # If it's already a dict, use it directly
32+ schema_obj = json_schema
33+ if isinstance (json_schema , str ):
34+ try :
35+ schema_obj = json .loads (json_schema )
36+ except json .JSONDecodeError as json_error :
37+ raise InvalidParameterError (
38+ 'json_schema' , f'Invalid JSON schema: { str (json_error )} '
39+ ) from json_error
2740
2841 request_body = json .dumps ({
2942 'eventType' : event_type ,
30- 'schema' : json_schema ,
43+ 'schema' : schema_obj ,
3144 })
3245
3346 response : Response
0 commit comments