1313
1414if TYPE_CHECKING :
1515 from dataclasses import dataclass
16+
17+ from pyatlan .client .atlan import AtlanClient
1618else :
1719 from pydantic .v1 .dataclasses import dataclass
1820
19- from typing import Any , Dict , Generic , List , Optional , TypeVar
21+ from typing import Any , Dict , Generic , List , Optional , TypeVar , Union
2022
2123from pydantic .v1 .generics import GenericModel
2224
2325from pyatlan .model .constants import DELETED_ , DELETED_SENTINEL
2426from pyatlan .model .enums import AnnouncementType , EntityStatus , SaveSemantic
2527from pyatlan .model .structs import SourceTagAttachment
28+ from pyatlan .model .translators import AtlanTagTranslator
2629
2730
2831class AtlanTagName :
@@ -178,6 +181,38 @@ def from_yaml(cls, yaml_str: str):
178181 return cls (** data )
179182
180183
184+ class AtlanResponse :
185+ def __init__ (self , raw_json : Dict [str , Any ], client : AtlanClient ):
186+ self .raw_json = raw_json
187+ self .client = client
188+ self .translators = [
189+ AtlanTagTranslator (client ),
190+ # Register more translators here
191+ ]
192+ self .translated = self ._deep_translate (self .raw_json )
193+
194+ def _deep_translate (
195+ self , data : Union [Dict [str , Any ], List [Any ], Any ]
196+ ) -> Union [Dict [str , Any ], List [Any ], Any ]:
197+ if isinstance (data , dict ):
198+ # Apply translators to this dict if any apply
199+ for translator in self .translators :
200+ if translator .applies_to (data ):
201+ data = translator .translate (data )
202+
203+ # Recursively apply to each value
204+ return {key : self ._deep_translate (value ) for key , value in data .items ()}
205+
206+ elif isinstance (data , list ):
207+ return [self ._deep_translate (item ) for item in data ]
208+
209+ else :
210+ return data
211+
212+ def to_dict (self ) -> Dict [str , Any ]:
213+ return self .translated
214+
215+
181216class SearchRequest (AtlanObject , ABC ):
182217 attributes : Optional [List [str ]] = Field (
183218 default_factory = list ,
@@ -202,7 +237,7 @@ class AtlanTag(AtlanObject):
202237 class Config :
203238 extra = "forbid"
204239
205- type_name : Optional [AtlanTagName ] = Field (
240+ type_name : Optional [str ] = Field (
206241 default = None ,
207242 description = "Name of the type definition that defines this instance.\n " ,
208243 alias = "typeName" ,
@@ -255,26 +290,26 @@ class Config:
255290 def source_tag_attachements (self ) -> List [SourceTagAttachment ]:
256291 return self ._source_tag_attachements
257292
258- @validator ("type_name" , pre = True )
259- def type_name_is_tag_name (cls , value ):
260- if isinstance (value , AtlanTagName ):
261- return value
262- return AtlanTagName ._convert_to_display_text (value )
263-
264- def __init__ (self , * args , ** kwargs ):
265- from pyatlan .client .atlan import AtlanClient
266-
267- super ().__init__ (* args , ** kwargs )
268- if self .type_name != AtlanTagName .get_deleted_sentinel ():
269- attr_id = AtlanClient .get_current_client ().atlan_tag_cache .get_source_tags_attr_id (
270- self .type_name .id
271- )
272- if self .attributes and attr_id in self .attributes :
273- self ._source_tag_attachements = [
274- SourceTagAttachment (** source_tag ["attributes" ])
275- for source_tag in self .attributes [attr_id ]
276- if isinstance (source_tag , dict ) and source_tag .get ("attributes" )
277- ]
293+ # @validator("type_name", pre=True)
294+ # def type_name_is_tag_name(cls, value):
295+ # if isinstance(value, AtlanTagName):
296+ # return value
297+ # return AtlanTagName._convert_to_display_text(value)
298+
299+ # def __init__(self, *args, **kwargs):
300+ # from pyatlan.client.atlan import AtlanClient
301+
302+ # super().__init__(*args, **kwargs)
303+ # if self.type_name != AtlanTagName.get_deleted_sentinel():
304+ # attr_id = AtlanClient.get_current_client().atlan_tag_cache.get_source_tags_attr_id(
305+ # self.type_name.id
306+ # )
307+ # if self.attributes and attr_id in self.attributes:
308+ # self._source_tag_attachements = [
309+ # SourceTagAttachment(**source_tag["attributes"])
310+ # for source_tag in self.attributes[attr_id]
311+ # if isinstance(source_tag, dict) and source_tag.get("attributes")
312+ # ]
278313
279314 @classmethod
280315 def of (
0 commit comments