@@ -51,24 +51,6 @@ class Config:
51
51
allow_population_by_field_name = True
52
52
validate_assignment = True
53
53
54
- # JSON field name that stores the object type
55
- __discriminator_property_name = 'userRole'
56
-
57
- # discriminator mappings
58
- __discriminator_value_class_map = {
59
- 'Admin, Project Manager (v2)' : 'AdminProjectManagerV2' ,
60
- 'Linguist (v2)' : 'LinguistV2'
61
- }
62
-
63
- @classmethod
64
- def get_discriminator_value (cls , obj : dict ) -> str :
65
- """Returns the discriminator value (object type) of the data"""
66
- discriminator_value = obj [cls .__discriminator_property_name ]
67
- if discriminator_value :
68
- return cls .__discriminator_value_class_map .get (discriminator_value )
69
- else :
70
- return None
71
-
72
54
def to_str (self ) -> str :
73
55
"""Returns the string representation of the model using alias"""
74
56
return pprint .pformat (self .dict (by_alias = True ))
@@ -78,7 +60,7 @@ def to_json(self) -> str:
78
60
return json .dumps (self .to_dict ())
79
61
80
62
@classmethod
81
- def from_json (cls , json_str : str ) -> Union ( AdminProjectManagerV2 , LinguistV2 ) : # noqa: F821
63
+ def from_json (cls , json_str : str ) -> AbstractProjectDtoV2 : # noqa: F821
82
64
"""Create an instance of AbstractProjectDtoV2 from a JSON string"""
83
65
return cls .from_dict (json .loads (json_str ))
84
66
@@ -115,15 +97,28 @@ def to_dict(self):
115
97
return _dict
116
98
117
99
@classmethod
118
- def from_dict (cls , obj : dict ) -> Union ( AdminProjectManagerV2 , LinguistV2 ) : # noqa: F821
100
+ def from_dict (cls , obj : dict ) -> AbstractProjectDtoV2 : # noqa: F821
119
101
"""Create an instance of AbstractProjectDtoV2 from a dict"""
120
- # look up the object type based on discriminator mapping
121
- object_type = cls .get_discriminator_value (obj )
122
- if object_type :
123
- klass = getattr (phrasetms_client .models , object_type )
124
- return klass .from_dict (obj )
125
- else :
126
- raise ValueError ("AbstractProjectDtoV2 failed to lookup discriminator value from " +
127
- json .dumps (obj ) + ". Discriminator property name: " + cls .__discriminator_property_name +
128
- ", mapping: " + json .dumps (cls .__discriminator_value_class_map ))
102
+ if obj is None :
103
+ return None
104
+
105
+ if not isinstance (obj , dict ):
106
+ return AbstractProjectDtoV2 .parse_obj (obj )
107
+
108
+ _obj = AbstractProjectDtoV2 .parse_obj ({
109
+ "uid" : obj .get ("uid" ),
110
+ "internal_id" : obj .get ("internalId" ),
111
+ "id" : obj .get ("id" ),
112
+ "name" : obj .get ("name" ),
113
+ "date_created" : obj .get ("dateCreated" ),
114
+ "domain" : DomainReference .from_dict (obj .get ("domain" )) if obj .get ("domain" ) is not None else None ,
115
+ "sub_domain" : SubDomainReference .from_dict (obj .get ("subDomain" )) if obj .get ("subDomain" ) is not None else None ,
116
+ "owner" : UserReference .from_dict (obj .get ("owner" )) if obj .get ("owner" ) is not None else None ,
117
+ "source_lang" : obj .get ("sourceLang" ),
118
+ "target_langs" : obj .get ("targetLangs" ),
119
+ "references" : [ReferenceFileReference .from_dict (_item ) for _item in obj .get ("references" )] if obj .get ("references" ) is not None else None ,
120
+ "mt_settings_per_language_list" : [MTSettingsPerLanguageReference .from_dict (_item ) for _item in obj .get ("mtSettingsPerLanguageList" )] if obj .get ("mtSettingsPerLanguageList" ) is not None else None ,
121
+ "user_role" : obj .get ("userRole" ),
122
+ })
123
+ return _obj
129
124
0 commit comments