From 091b39b1b6c177320e4d6a0555cf6bbcfd61cd5e Mon Sep 17 00:00:00 2001 From: kkedziak Date: Thu, 16 Jan 2025 09:31:45 +0100 Subject: [PATCH] Handler type --- .../rest_builder/user_defined_rest_handlers.py | 10 ++++++---- tests/unit/test_user_defined_rest_handlers.py | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/splunk_add_on_ucc_framework/commands/rest_builder/user_defined_rest_handlers.py b/splunk_add_on_ucc_framework/commands/rest_builder/user_defined_rest_handlers.py index c7f2faf23..edf9115f1 100644 --- a/splunk_add_on_ucc_framework/commands/rest_builder/user_defined_rest_handlers.py +++ b/splunk_add_on_ucc_framework/commands/rest_builder/user_defined_rest_handlers.py @@ -14,11 +14,10 @@ # limitations under the License. # from dataclasses import dataclass -from typing import Dict, Any, Union, Iterable, Optional, Set, List, Literal +from typing import Dict, Any, Union, Iterable, Optional, Set, List from splunk_add_on_ucc_framework.commands.openapi_generator import oas -HandlerType = Literal["EAI"] _EAI_OUTPUT_MODE = { "name": "output_mode", @@ -68,7 +67,7 @@ def _eai_response_schema(schema: Any) -> oas.MediaTypeObject: class RestHandlerConfig: name: str endpoint: str - handlerType: HandlerType + handlerType: str registerHandler: Optional[Dict[str, Any]] = None requestParameters: Optional[Dict[str, Dict[str, Any]]] = None responseParameters: Optional[Dict[str, Dict[str, Any]]] = None @@ -298,7 +297,10 @@ def _oas_objects_eai(self) -> Dict[str, oas.PathItemObject]: @property def oas_paths(self) -> Dict[str, oas.PathItemObject]: - return self._oas_objects_eai() + if self.handlerType == "EAI": + return self._oas_objects_eai() + else: + raise ValueError(f"Unsupported handler type: {self.handlerType}") class UserDefinedRestHandlers: diff --git a/tests/unit/test_user_defined_rest_handlers.py b/tests/unit/test_user_defined_rest_handlers.py index 0888d7353..6099da064 100644 --- a/tests/unit/test_user_defined_rest_handlers.py +++ b/tests/unit/test_user_defined_rest_handlers.py @@ -23,6 +23,13 @@ def test_rest_handler_config_minimal(cfg_minimal): assert not cfg_minimal.oas_paths +def test_rest_handler_config_unsupported_handler_type(cfg_minimal): + cfg_minimal.handlerType = "unsupported" + + with pytest.raises(ValueError): + print(cfg_minimal.oas_paths) + + def test_rest_handler_config_openapi_only_specified(): cfg = RestHandlerConfig( name="test_name",