Skip to content

Commit

Permalink
Handler type
Browse files Browse the repository at this point in the history
  • Loading branch information
kkedziak-splunk committed Jan 16, 2025
1 parent 849e407 commit 091b39b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_user_defined_rest_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 091b39b

Please sign in to comment.