Skip to content

LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows

api deployment dto registry to load dto from plugins (#1156)

vishnuszipstacke365e6ca8ad5
diff --git a/backend/api_v2/api_deployment_dto_registry.py b/backend/api_v2/api_deployment_dto_registry.py
new file mode 100644
index 000000000..9c8e73b09
--- /dev/null
+++ b/backend/api_v2/api_deployment_dto_registry.py
@@ -0,0 +1,23 @@
+import logging
+from typing import Any, Optional
+
+from api_v2.postman_collection.dto import PostmanCollection
+from plugins.api.dto import metadata
+
+logger = logging.getLogger(__name__)
+
+
+class ApiDeploymentDTORegistry:
+ _dto_class: Optional[Any] = None # Store the selected DTO class (cached)
+
+ @classmethod
+ def load_dto(cls) -> Optional[Any]:
+ class_name = PostmanCollection.__name__
+ if metadata.get(class_name):
+ return metadata[class_name].class_name
+ return PostmanCollection # Return as soon as we find a valid DTO
+
+ @classmethod
+ def get_dto(cls) -> Optional[type]:
+ """Returns the first available DTO class, or None if unavailable."""
+ return cls.load_dto()
diff --git a/backend/api_v2/api_deployment_views.py b/backend/api_v2/api_deployment_views.py
index 65556020a..95e215a9c 100644
--- a/backend/api_v2/api_deployment_views.py
+++ b/backend/api_v2/api_deployment_views.py
@@ -2,11 +2,11 @@ import json
import logging
from typing import Any, Optional
+from api_v2.api_deployment_dto_registry import ApiDeploymentDTORegistry
from api_v2.constants import ApiExecution
from api_v2.deployment_helper import DeploymentHelper
from api_v2.exceptions import NoActiveAPIKeyError
from api_v2.models import APIDeployment
-from api_v2.postman_collection.dto import PostmanCollection
from api_v2.serializers import (
APIDeploymentListSerializer,
APIDeploymentSerializer,
@@ -156,8 +156,8 @@ class APIDeploymentViewSet(viewsets.ModelViewSet):
if not api_key_inst:
logger.error(f"No active API key set for deployment {instance.pk}")
raise NoActiveAPIKeyError(deployment_name=instance.display_name)
-
- postman_collection = PostmanCollection.create(
+ dto_class = ApiDeploymentDTORegistry.get_dto()
+ postman_collection = dto_class.create(
instance=instance, api_key=api_key_inst.api_key
)
response = HttpResponse(
diff --git a/backend/plugins/api/dto/__init__.py b/backend/plugins/api/dto/__init__.py
new file mode 100644
index 000000000..b84a87d20
--- /dev/null
+++ b/backend/plugins/api/dto/__init__.py
@@ -0,0 +1,12 @@
+from dataclasses import dataclass
+from typing import Any
+
+
+@dataclass
+class MetadataDto:
+ name: str
+ class_name: Any
+ is_active: bool
+
+
+metadata = {}