diff --git a/generator-templates/api_client.mustache b/generator-templates/api_client.mustache index fc21e11..42bfaae 100755 --- a/generator-templates/api_client.mustache +++ b/generator-templates/api_client.mustache @@ -81,22 +81,7 @@ class ModelSerDe: return {key: self.sanitize_for_serialization(val) for key, val in six.iteritems(obj_dict)} - def deserialize(self, response, response_type): - """Deserializes response into an object. - - :param response: RESTResponse object to be deserialized. - :param response_type: class literal for - deserialized object, or string of class name. - - :return: deserialized object. - """ - try: - data = json.loads(response.data) - except ValueError: - data = response.data - return self.__deserialize(data, response_type) - - def __deserialize(self, data, klass): + def deserialize_raw(self, data, klass): """Deserializes dict, list, str into an object. :param data: dict, list or str. @@ -110,12 +95,12 @@ class ModelSerDe: if type(klass) == str: if klass.startswith('list['): sub_kls = re.match(r'list\[(.*)\]', klass).group(1) - return [self.__deserialize(sub_data, sub_kls) + return [self.deserialize_raw(sub_data, sub_kls) for sub_data in data] if klass.startswith('dict('): sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2) - return {k: self.__deserialize(v, sub_kls) + return {k: self.deserialize_raw(v, sub_kls) for k, v in six.iteritems(data)} # convert str to class @@ -222,14 +207,14 @@ class ModelSerDe: for attr, attr_type in six.iteritems(klass.openapi_types): if klass.attribute_map[attr] in data: value = data[klass.attribute_map[attr]] - kwargs[attr] = self.__deserialize(value, attr_type) + kwargs[attr] = self.deserialize_raw(value, attr_type) instance = klass(**kwargs) if has_discriminator: klass_name = instance.get_real_child_model(data) if klass_name: - instance = self.__deserialize(data, klass_name) + instance = self.deserialize_raw(data, klass_name) return instance @@ -441,6 +426,21 @@ class ApiClient(ModelSerDe, object): response_data.getheaders())) {{/tornado}} + def deserialize(self, response, response_type): + """Deserializes response into an object. + + :param response: RESTResponse object to be deserialized. + :param response_type: class literal for + deserialized object, or string of class name. + + :return: deserialized object. + """ + try: + data = json.loads(response.data) + except ValueError: + data = response.data + return self.deserialize_raw(data, response_type) + def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None, diff --git a/regula/documentreader/webclient/gen/api_client.py b/regula/documentreader/webclient/gen/api_client.py index 9b8fa9b..706c986 100755 --- a/regula/documentreader/webclient/gen/api_client.py +++ b/regula/documentreader/webclient/gen/api_client.py @@ -80,22 +80,7 @@ def sanitize_for_serialization(self, obj): return {key: self.sanitize_for_serialization(val) for key, val in six.iteritems(obj_dict)} - def deserialize(self, response, response_type): - """Deserializes response into an object. - - :param response: RESTResponse object to be deserialized. - :param response_type: class literal for - deserialized object, or string of class name. - - :return: deserialized object. - """ - try: - data = json.loads(response.data) - except ValueError: - data = response.data - return self.__deserialize(data, response_type) - - def __deserialize(self, data, klass): + def deserialize_raw(self, data, klass): """Deserializes dict, list, str into an object. :param data: dict, list or str. @@ -109,12 +94,12 @@ def __deserialize(self, data, klass): if type(klass) == str: if klass.startswith('list['): sub_kls = re.match(r'list\[(.*)\]', klass).group(1) - return [self.__deserialize(sub_data, sub_kls) + return [self.deserialize_raw(sub_data, sub_kls) for sub_data in data] if klass.startswith('dict('): sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2) - return {k: self.__deserialize(v, sub_kls) + return {k: self.deserialize_raw(v, sub_kls) for k, v in six.iteritems(data)} # convert str to class @@ -221,14 +206,14 @@ def __deserialize_model(self, data, klass): for attr, attr_type in six.iteritems(klass.openapi_types): if klass.attribute_map[attr] in data: value = data[klass.attribute_map[attr]] - kwargs[attr] = self.__deserialize(value, attr_type) + kwargs[attr] = self.deserialize_raw(value, attr_type) instance = klass(**kwargs) if has_discriminator: klass_name = instance.get_real_child_model(data) if klass_name: - instance = self.__deserialize(data, klass_name) + instance = self.deserialize_raw(data, klass_name) return instance @@ -411,6 +396,21 @@ def __call_api( return (return_data, response_data.status, response_data.getheaders()) + def deserialize(self, response, response_type): + """Deserializes response into an object. + + :param response: RESTResponse object to be deserialized. + :param response_type: class literal for + deserialized object, or string of class name. + + :return: deserialized object. + """ + try: + data = json.loads(response.data) + except ValueError: + data = response.data + return self.deserialize_raw(data, response_type) + def call_api(self, resource_path, method, path_params=None, query_params=None, header_params=None, body=None, post_params=None, files=None,