Skip to content

Commit e365e6c

Browse files
api deployment dto registry to load dto from plugins (#1156)
1 parent 68764e0 commit e365e6c

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import logging
2+
from typing import Any, Optional
3+
4+
from api_v2.postman_collection.dto import PostmanCollection
5+
from plugins.api.dto import metadata
6+
7+
logger = logging.getLogger(__name__)
8+
9+
10+
class ApiDeploymentDTORegistry:
11+
_dto_class: Optional[Any] = None # Store the selected DTO class (cached)
12+
13+
@classmethod
14+
def load_dto(cls) -> Optional[Any]:
15+
class_name = PostmanCollection.__name__
16+
if metadata.get(class_name):
17+
return metadata[class_name].class_name
18+
return PostmanCollection # Return as soon as we find a valid DTO
19+
20+
@classmethod
21+
def get_dto(cls) -> Optional[type]:
22+
"""Returns the first available DTO class, or None if unavailable."""
23+
return cls.load_dto()

backend/api_v2/api_deployment_views.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
import logging
33
from typing import Any, Optional
44

5+
from api_v2.api_deployment_dto_registry import ApiDeploymentDTORegistry
56
from api_v2.constants import ApiExecution
67
from api_v2.deployment_helper import DeploymentHelper
78
from api_v2.exceptions import NoActiveAPIKeyError
89
from api_v2.models import APIDeployment
9-
from api_v2.postman_collection.dto import PostmanCollection
1010
from api_v2.serializers import (
1111
APIDeploymentListSerializer,
1212
APIDeploymentSerializer,
@@ -156,8 +156,8 @@ def download_postman_collection(
156156
if not api_key_inst:
157157
logger.error(f"No active API key set for deployment {instance.pk}")
158158
raise NoActiveAPIKeyError(deployment_name=instance.display_name)
159-
160-
postman_collection = PostmanCollection.create(
159+
dto_class = ApiDeploymentDTORegistry.get_dto()
160+
postman_collection = dto_class.create(
161161
instance=instance, api_key=api_key_inst.api_key
162162
)
163163
response = HttpResponse(

backend/plugins/api/dto/__init__.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from dataclasses import dataclass
2+
from typing import Any
3+
4+
5+
@dataclass
6+
class MetadataDto:
7+
name: str
8+
class_name: Any
9+
is_active: bool
10+
11+
12+
metadata = {}

0 commit comments

Comments
 (0)